本文整理了Java中java.lang.Class.getEnumConstants()
方法的一些代码示例,展示了Class.getEnumConstants()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.getEnumConstants()
方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:getEnumConstants
[英]Returns the enum constants associated with this Class. Returns null if this Class does not represent an enum type.
[中]返回与此类关联的枚举常量。如果此类不表示枚举类型,则返回null。
代码示例来源:origin: spring-projects/spring-framework
@Override
public T convert(Integer source) {
return this.enumType.getEnumConstants()[source];
}
}
代码示例来源:origin: libgdx/libgdx
/** Returns the elements of this enum class or null if this Class object does not represent an enum type. */
static public Object[] getEnumConstants (Class c) {
return c.getEnumConstants();
}
代码示例来源:origin: libgdx/libgdx
/** Returns the elements of this enum class or null if this Class object does not represent an enum type. */
static public Object[] getEnumConstants (Class c) {
return c.getEnumConstants();
}
代码示例来源:origin: prestodb/presto
private EnumValues(Class<Enum<?>> enumClass, SerializableString[] textual)
{
_enumClass = enumClass;
_values = enumClass.getEnumConstants();
_textual = textual;
}
代码示例来源:origin: jenkinsci/jenkins
public Enum[] getEnumConstants() {
return (Enum[])clazz.getEnumConstants();
}
代码示例来源:origin: google/guava
/** Creates an empty {@code EnumMultiset}. */
private EnumMultiset(Class<E> type) {
this.type = type;
checkArgument(type.isEnum());
this.enumConstants = type.getEnumConstants();
this.counts = new int[enumConstants.length];
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* <p>Gets the {@code List} of enums.</p>
*
* <p>This method is useful when you need a list of enums rather than an array.</p>
*
* @param <E> the type of the enumeration
* @param enumClass the class of the enum to query, not null
* @return the modifiable list of enums, never null
*/
public static <E extends Enum<E>> List<E> getEnumList(final Class<E> enumClass) {
return new ArrayList<>(Arrays.asList(enumClass.getEnumConstants()));
}
代码示例来源:origin: google/guava
private EnumHashBiMap(Class<K> keyType) {
super(
WellBehavedMap.wrap(new EnumMap<K, V>(keyType)),
Maps.<V, K>newHashMapWithExpectedSize(keyType.getEnumConstants().length));
this.keyType = keyType;
}
代码示例来源:origin: google/guava
/**
* Returns the ClassValue-using validator, or falls back to the "weak Set" implementation if
* unable to do so.
*/
static GetCheckedTypeValidator getBestValidator() {
try {
Class<?> theClass = Class.forName(CLASS_VALUE_VALIDATOR_NAME);
return (GetCheckedTypeValidator) theClass.getEnumConstants()[0];
} catch (Throwable t) { // ensure we really catch *everything*
return weakSetValidator();
}
}
}
代码示例来源:origin: google/guava
/**
* Returns the Unsafe-using Comparator, or falls back to the pure-Java implementation if unable
* to do so.
*/
static Comparator<byte[]> getBestComparator() {
try {
Class<?> theClass = Class.forName(UNSAFE_COMPARATOR_NAME);
// yes, UnsafeComparator does implement Comparator<byte[]>
@SuppressWarnings("unchecked")
Comparator<byte[]> comparator = (Comparator<byte[]>) theClass.getEnumConstants()[0];
return comparator;
} catch (Throwable t) { // ensure we really catch *everything*
return lexicographicalComparatorJavaImpl();
}
}
}
代码示例来源:origin: eclipse-vertx/vert.x
/**
* Sets the list of values accepted by this option from the option's type.
*/
private void setChoicesFromEnumType() {
Object[] constants = type.getEnumConstants();
for (Object c : constants) {
addChoice(c.toString());
}
}
代码示例来源:origin: prestodb/presto
/** Creates an empty {@code EnumMultiset}. */
private EnumMultiset(Class<E> type) {
this.type = type;
checkArgument(type.isEnum());
this.enumConstants = type.getEnumConstants();
this.counts = new int[enumConstants.length];
}
代码示例来源:origin: google/guava
/**
* @serialData the {@code Class<E>} for the enum type, the number of distinct elements, the first
* element, its count, the second element, its count, and so on
*/
@GwtIncompatible // java.io.ObjectInputStream
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
@SuppressWarnings("unchecked") // reading data stored by writeObject
Class<E> localType = (Class<E>) stream.readObject();
type = localType;
enumConstants = type.getEnumConstants();
counts = new int[enumConstants.length];
Serialization.populateMultiset(this, stream);
}
代码示例来源:origin: google/guava
@SuppressWarnings("unchecked") // reading field populated by writeObject
@GwtIncompatible // java.io.ObjectInputStream
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
keyType = (Class<K>) stream.readObject();
setDelegates(
WellBehavedMap.wrap(new EnumMap<K, V>(keyType)),
new HashMap<V, K>(keyType.getEnumConstants().length * 3 / 2));
Serialization.populateMap(this, stream);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Render the inner '{@code option}' tags using the {@link #optionSource}.
* @see #doRenderFromCollection(java.util.Collection, TagWriter)
*/
private void renderFromEnum(TagWriter tagWriter) throws JspException {
doRenderFromCollection(CollectionUtils.arrayToList(((Class<?>) this.optionSource).getEnumConstants()), tagWriter);
}
代码示例来源:origin: prestodb/presto
private EnumHashBiMap(Class<K> keyType) {
super(
WellBehavedMap.wrap(new EnumMap<K, V>(keyType)),
Maps.<V, K>newHashMapWithExpectedSize(keyType.getEnumConstants().length));
this.keyType = keyType;
}
代码示例来源:origin: prestodb/presto
@SuppressWarnings("unchecked") // reading field populated by writeObject
@GwtIncompatible // java.io.ObjectInputStream
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
keyType = (Class<K>) stream.readObject();
setDelegates(
WellBehavedMap.wrap(new EnumMap<K, V>(keyType)),
new HashMap<V, K>(keyType.getEnumConstants().length * 3 / 2));
Serialization.populateMap(this, stream);
}
代码示例来源:origin: spring-projects/spring-framework
public T convert(String source) {
for (T value : enumType.getEnumConstants()) {
if (value.getBaseCode().equals(source)) {
return value;
}
}
return null;
}
}
代码示例来源:origin: spring-projects/spring-framework
public T convert(String source) {
for (T value : enumType.getEnumConstants()) {
if (value.getCode().equals(source)) {
return value;
}
}
return null;
}
}
代码示例来源:origin: google/guava
@GwtIncompatible // weak references
private WeakReference<?> doTestClassUnloading() throws Exception {
URLClassLoader shadowLoader = new URLClassLoader(getClassPathUrls(), null);
@SuppressWarnings("unchecked")
Class<TestEnum> shadowTestEnum =
(Class<TestEnum>) Class.forName(TestEnum.class.getName(), false, shadowLoader);
assertNotSame(shadowTestEnum, TestEnum.class);
// We can't write Set<TestEnum> because that is a Set of the TestEnum from the original
// ClassLoader.
Set<Object> shadowConstants = new HashSet<>();
for (TestEnum constant : TestEnum.values()) {
Optional<TestEnum> result = Enums.getIfPresent(shadowTestEnum, constant.name());
assertThat(result).isPresent();
shadowConstants.add(result.get());
}
assertEquals(ImmutableSet.<Object>copyOf(shadowTestEnum.getEnumConstants()), shadowConstants);
Optional<TestEnum> result = Enums.getIfPresent(shadowTestEnum, "blibby");
assertThat(result).isAbsent();
return new WeakReference<>(shadowLoader);
}
内容来源于网络,如有侵权,请联系作者删除!