@Override public T convert(Integer source) { return this.enumType.getEnumConstants()[source]; } }
/** 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(); }
/** 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(); }
private EnumValues(Class<Enum<?>> enumClass, SerializableString[] textual) { _enumClass = enumClass; _values = enumClass.getEnumConstants(); _textual = textual; }
public Enum[] getEnumConstants() { return (Enum[])clazz.getEnumConstants(); }
/** 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]; }
/** * <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())); }
private EnumHashBiMap(Class<K> keyType) { super( WellBehavedMap.wrap(new EnumMap<K, V>(keyType)), Maps.<V, K>newHashMapWithExpectedSize(keyType.getEnumConstants().length)); this.keyType = keyType; }
/** * 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(); } } }
/** * 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(); } } }
/** * 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()); } }
/** 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]; }
/** * @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); }
@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); }
/** * 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); }
private EnumHashBiMap(Class<K> keyType) { super( WellBehavedMap.wrap(new EnumMap<K, V>(keyType)), Maps.<V, K>newHashMapWithExpectedSize(keyType.getEnumConstants().length)); this.keyType = keyType; }
@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); }
public T convert(String source) { for (T value : enumType.getEnumConstants()) { if (value.getBaseCode().equals(source)) { return value; } } return null; } }
public T convert(String source) { for (T value : enumType.getEnumConstants()) { if (value.getCode().equals(source)) { return value; } } return null; } }
@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); }