java.lang.Enum.getDeclaringClass()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(187)

本文整理了Java中java.lang.Enum.getDeclaringClass()方法的一些代码示例,展示了Enum.getDeclaringClass()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Enum.getDeclaringClass()方法的具体详情如下:
包路径:java.lang.Enum
类名称:Enum
方法名:getDeclaringClass

Enum.getDeclaringClass介绍

[英]Returns the enum constant's declaring class.
[中]返回枚举常量的声明类。

代码示例

代码示例来源:origin: google/guava

/**
 * For the given Enum value {@code rank}, returns the value's {@code "EnumClass.name"}, which is
 * used in exception and warning output.
 */
private static String getLockName(Enum<?> rank) {
 return rank.getDeclaringClass().getSimpleName() + "." + rank.name();
}

代码示例来源:origin: google/guava

private static <V extends Enum<V>> Class<V> inferValueType(Map<?, V> map) {
 if (map instanceof EnumBiMap) {
  return ((EnumBiMap<?, V>) map).valueType;
 }
 checkArgument(!map.isEmpty());
 return map.values().iterator().next().getDeclaringClass();
}

代码示例来源:origin: google/guava

protected static String formatFeatureSet(Set<? extends Feature<?>> features) {
  List<String> temp = new ArrayList<>();
  for (Feature<?> feature : features) {
   Object featureAsObject = feature; // to work around bogus JDK warning
   if (featureAsObject instanceof Enum) {
    Enum<?> f = (Enum<?>) featureAsObject;
    temp.add(f.getDeclaringClass().getSimpleName() + "." + feature);
   } else {
    temp.add(feature.toString());
   }
  }
  return temp.toString();
 }
}

代码示例来源:origin: prestodb/presto

/**
 * For the given Enum value {@code rank}, returns the value's {@code "EnumClass.name"}, which is
 * used in exception and warning output.
 */
private static String getLockName(Enum<?> rank) {
 return rank.getDeclaringClass().getSimpleName() + "." + rank.name();
}

代码示例来源:origin: redisson/redisson

/**
   * {@inheritDoc}
   */
  @SuppressWarnings("unchecked")
  public <T extends Enum<T>> T load(Class<T> type) {
    return value.getDeclaringClass() == type
        ? (T) value
        : Enum.valueOf(type, value.name());
  }
}

代码示例来源:origin: google/guava

void put(K key, V value) {
 if (map == null) {
  map = new EnumMap<>(key.getDeclaringClass());
 }
 map.merge(key, value, mergeFunction);
}

代码示例来源:origin: neo4j/neo4j

<C extends Enum<C> & Status> Code( Classification classification, C categoryAndTitle, String description )
{
  this.classification = classification;
  this.category = categoryAndTitle.getDeclaringClass().getSimpleName();
  this.title = categoryAndTitle.name();
  this.description = description;
}

代码示例来源:origin: google/j2objc

/**
 * For the given Enum value {@code rank}, returns the value's {@code "EnumClass.name"}, which is
 * used in exception and warning output.
 */
private static String getLockName(Enum<?> rank) {
 return rank.getDeclaringClass().getSimpleName() + "." + rank.name();
}

代码示例来源:origin: google/guava

/**
 * Creates a new {@code EnumMultiset} containing the specified elements.
 *
 * <p>This implementation is highly efficient when {@code elements} is itself a {@link Multiset}.
 *
 * @param elements the elements that the multiset should contain
 * @throws IllegalArgumentException if {@code elements} is empty
 */
public static <E extends Enum<E>> EnumMultiset<E> create(Iterable<E> elements) {
 Iterator<E> iterator = elements.iterator();
 checkArgument(iterator.hasNext(), "EnumMultiset constructor passed empty Iterable");
 EnumMultiset<E> multiset = new EnumMultiset<>(iterator.next().getDeclaringClass());
 Iterables.addAll(multiset, elements);
 return multiset;
}

代码示例来源:origin: google/guava

static <K extends Enum<K>> Class<K> inferKeyType(Map<K, ?> map) {
 if (map instanceof EnumBiMap) {
  return ((EnumBiMap<K, ?>) map).keyType();
 }
 if (map instanceof EnumHashBiMap) {
  return ((EnumHashBiMap<K, ?>) map).keyType();
 }
 checkArgument(!map.isEmpty());
 return map.keySet().iterator().next().getDeclaringClass();
}

代码示例来源:origin: google/guava

/**
 * Returns the {@link Field} in which {@code enumValue} is defined. For example, to get the {@code
 * Description} annotation on the {@code GOLF} constant of enum {@code Sport}, use {@code
 * Enums.getField(Sport.GOLF).getAnnotation(Description.class)}.
 *
 * @since 12.0
 */
@GwtIncompatible // reflection
public static Field getField(Enum<?> enumValue) {
 Class<?> clazz = enumValue.getDeclaringClass();
 try {
  return clazz.getDeclaredField(enumValue.name());
 } catch (NoSuchFieldException impossible) {
  throw new AssertionError(impossible);
 }
}

代码示例来源:origin: google/j2objc

private static <V extends Enum<V>> Class<V> inferValueType(Map<?, V> map) {
 if (map instanceof EnumBiMap) {
  return ((EnumBiMap<?, V>) map).valueType;
 }
 checkArgument(!map.isEmpty());
 return map.values().iterator().next().getDeclaringClass();
}

代码示例来源:origin: prestodb/presto

void put(K key, V value) {
 if (map == null) {
  map = new EnumMap<>(key.getDeclaringClass());
 }
 map.merge(key, value, mergeFunction);
}

代码示例来源:origin: prestodb/presto

private static <V extends Enum<V>> Class<V> inferValueType(Map<?, V> map) {
 if (map instanceof EnumBiMap) {
  return ((EnumBiMap<?, V>) map).valueType;
 }
 checkArgument(!map.isEmpty());
 return map.values().iterator().next().getDeclaringClass();
}

代码示例来源:origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public TypeDescription getEnumerationType() {
  return TypeDescription.ForLoadedType.of(value.getDeclaringClass());
}

代码示例来源:origin: apache/flink

/**
 * Return value matching this enumerated type.
 * Note that the returned value is trimmed by this method.
 * @param name Property name
 * @param defaultValue Value returned if no mapping exists
 * @throws IllegalArgumentException If mapping is illegal for the type
 * provided
 */
public <T extends Enum<T>> T getEnum(String name, T defaultValue) {
 final String val = getTrimmed(name);
 return null == val
  ? defaultValue
  : Enum.valueOf(defaultValue.getDeclaringClass(), val);
}

代码示例来源:origin: google/guava

/**
 * Creates an {@code EnumSet} consisting of all enum values that are not in the specified
 * collection. If the collection is an {@link EnumSet}, this method has the same behavior as
 * {@link EnumSet#complementOf}. Otherwise, the specified collection must contain at least one
 * element, in order to determine the element type. If the collection could be empty, use {@link
 * #complementOf(Collection, Class)} instead of this method.
 *
 * @param collection the collection whose complement should be stored in the enum set
 * @return a new, modifiable {@code EnumSet} containing all values of the enum that aren't present
 *     in the given collection
 * @throws IllegalArgumentException if {@code collection} is not an {@code EnumSet} instance and
 *     contains no elements
 */
public static <E extends Enum<E>> EnumSet<E> complementOf(Collection<E> collection) {
 if (collection instanceof EnumSet) {
  return EnumSet.complementOf((EnumSet<E>) collection);
 }
 checkArgument(
   !collection.isEmpty(), "collection is empty; use the other version of this method");
 Class<E> type = collection.iterator().next().getDeclaringClass();
 return makeComplementByHand(collection, type);
}

代码示例来源:origin: google/j2objc

static <K extends Enum<K>> Class<K> inferKeyType(Map<K, ?> map) {
 if (map instanceof EnumBiMap) {
  return ((EnumBiMap<K, ?>) map).keyType();
 }
 if (map instanceof EnumHashBiMap) {
  return ((EnumHashBiMap<K, ?>) map).keyType();
 }
 checkArgument(!map.isEmpty());
 return map.keySet().iterator().next().getDeclaringClass();
}

代码示例来源:origin: prestodb/presto

static <K extends Enum<K>> Class<K> inferKeyType(Map<K, ?> map) {
 if (map instanceof EnumBiMap) {
  return ((EnumBiMap<K, ?>) map).keyType();
 }
 if (map instanceof EnumHashBiMap) {
  return ((EnumHashBiMap<K, ?>) map).keyType();
 }
 checkArgument(!map.isEmpty());
 return map.keySet().iterator().next().getDeclaringClass();
}

代码示例来源:origin: prestodb/presto

/**
 * Creates a new {@code EnumMultiset} containing the specified elements.
 *
 * <p>This implementation is highly efficient when {@code elements} is itself a {@link Multiset}.
 *
 * @param elements the elements that the multiset should contain
 * @throws IllegalArgumentException if {@code elements} is empty
 */
public static <E extends Enum<E>> EnumMultiset<E> create(Iterable<E> elements) {
 Iterator<E> iterator = elements.iterator();
 checkArgument(iterator.hasNext(), "EnumMultiset constructor passed empty Iterable");
 EnumMultiset<E> multiset = new EnumMultiset<>(iterator.next().getDeclaringClass());
 Iterables.addAll(multiset, elements);
 return multiset;
}

相关文章