E - the type of enum instances this cache will manage.
Example usage:
EnumCache<MyEnum> myEnumCache = EnumCache.of(MyEnum.class);
MyEnum someValue = myEnumCache.valueOf("SOME_VALUE");
public abstract class EnumCache<E> extends Object
Usage of this class provides efficient access to enum instances via name or index, and also provides convenience methods for creating maps and sets that use enum instances as keys or elements.
| Modifier | Constructor and Description |
|---|---|
protected |
EnumCache(Class<E> type)
Constructs an EnumCache for the specified enum type.
|
| Modifier and Type | Method and Description |
|---|---|
abstract E[] |
asArray()
Returns an array containing all the enum instances managed by this cache.
|
abstract <T> Map<E,T> |
createMap()
Creates a map where the keys are enum instances.
|
abstract Set<E> |
createSet()
Creates a set for holding enum instances.
|
abstract E |
forIndex(int index)
Retrieves the enum instance at the given ordinal index.
|
E |
get(String name)
Returns the enum instance with the specified name.
|
static <E> EnumCache<E> |
of(Class<E> eClass)
Retrieves an EnumCache instance for the specified enum class.
|
abstract int |
size()
Returns the total number of enum instances managed by this cache.
|
Class<?> |
type()
Returns the class of the enum type this cache is managing.
|
abstract E |
valueOf(String name)
Returns the enum instance with the specified name.
|
public static <E> EnumCache<E> of(Class<E> eClass)
E - the type of the enum.eClass - the class of the enum.public E get(String name)
name - the name of the enum instance to be returned.public abstract E valueOf(String name)
name - the name of the enum instance to be returned.public abstract int size()
public Class<?> type()
public abstract E forIndex(int index)
index - the ordinal index of the enum instance to retrieve.public abstract E[] asArray()
public abstract <T> Map<E,T> createMap()
T - the type of the map values.Copyright © 2024. All rights reserved.