/** * 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(); }
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(); }
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(); } }
/** * 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(); }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") public <T extends Enum<T>> T load(Class<T> type) { return value.getDeclaringClass() == type ? (T) value : Enum.valueOf(type, value.name()); } }
void put(K key, V value) { if (map == null) { map = new EnumMap<>(key.getDeclaringClass()); } map.merge(key, value, mergeFunction); }
<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; }
/** * 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(); }
/** * 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; }
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(); }
/** * 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); } }
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(); }
void put(K key, V value) { if (map == null) { map = new EnumMap<>(key.getDeclaringClass()); } map.merge(key, value, mergeFunction); }
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(); }
/** * {@inheritDoc} */ public TypeDescription getEnumerationType() { return TypeDescription.ForLoadedType.of(value.getDeclaringClass()); }
/** * 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); }
/** * 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); }
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(); }
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(); }
/** * 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; }