Class Enums
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsSingleEnumElements(Collection<?> elems) Checks whether the given collection is known to contain only elements of a single enum type.static <K,V> Map <K, V> enumAwareCopyOf(Map<K, V> map) Returns a copy of the current entries of a map, optimizing for enum keys.valueMap(E... items) Creates a map of the given enumeration values indexed by their name.Creates a map of all values of the given enumeration class indexed by their name.
-
Method Details
-
valueMap
Creates a map of all values of the given enumeration class indexed by their name.- Type Parameters:
E- the enumeration type- Parameters:
cls- an enumeration class- Returns:
- a complete map of names to values
-
valueMap
Creates a map of the given enumeration values indexed by their name.- Type Parameters:
E- the enumeration type- Parameters:
items- an array of enumeration values- Returns:
- a map of names to the given values
-
containsSingleEnumElements
Checks whether the given collection is known to contain only elements of a single enum type.Passing the given collection to
EnumSet.copyOf(java.util.EnumSet<E>)(with a raw type) will succeed if and only if this method returnstrue. -
enumAwareCopyOf
Returns a copy of the current entries of a map, optimizing for enum keys.A backing implementation as an
EnumMapis chosen preferentially, if an enum type can be inferred from the keys. Otherwise, the resulting map will be backed by some implementation that may or may not tolerate null keys, but makes no further assumptions about the keys. All respective specifications apply.The resulting map may or may not be modifiable, and should be treated as a read-only data structure. The returned reference is guaranteed to be the only one. Hence, to explicitly enforce read-only access, use the wrapper operation
Collections.unmodifiableMap(java.util.Map<? extends K, ? extends V>)before passing it on.The entries of the resulting copy reflect the entries of the given map at the time this method is invoked. Later changes to the given map, after this method has returned, are not reflected in the copy. Behavior is unspecified if the given map is modified concurrently.
- Type Parameters:
K- the type of map keysV- the type of map values- Parameters:
map- the map to copy- Returns:
- a map that contains the current entries of
map, and is of typeEnumMapif feasible - Throws:
NullPointerException- ifmapis null- Since:
- 1.4
-