E - the type of enum instances this class will manage. It must extend CoreDynamicEnum.
Example usage:
EnumCache<YesNo> c =
EnumCache.of(
YesNo.class);
YesNo maybe =
c.valueOf("Maybe");
public class DynamicEnumClass<E extends CoreDynamicEnum<E>> extends EnumCache<E>
EnumCache.
The class is capable of dynamically creating and managing instances which resemble enumerations
(enums) in behavior. Unlike traditional enums, which have a fixed set of instances,
DynamicEnumClass can create new instances on-the-fly.
This class is thread-safe and ensures that each unique name maps to a single instance.
Instances of DynamicEnumClass have properties similar to traditional enums,
like name and ordinal. The name is the string identifier of an enum instance,
while the ordinal represents the position of the enum instance in the declaration order.
| Modifier and Type | Field and Description |
|---|---|
static CoreDynamicEnum<?>[] |
CORE_DYNAMIC_ENUMS |
| Modifier and Type | Method and Description |
|---|---|
E[] |
asArray()
Returns all enum instances in creation order.
|
<T> Map<E,T> |
createMap()
Creates a map keyed by enum values.
|
Set<E> |
createSet()
Creates a set for storing enum values.
|
E |
forIndex(int index)
Returns an array containing the enum instances managed by this class in
the order they were created.
|
E |
get(String name)
Returns the enum instance with the specified name.
|
void |
reset()
Resets the internal state by discarding any dynamic instances.
|
int |
size()
Returns the number of enum instances currently managed by this class.
|
E |
valueOf(String name)
Returns the enum instance with the specified name.
|
public static final CoreDynamicEnum<?>[] CORE_DYNAMIC_ENUMS
@Nullable public E get(String name)
null
if the instance does not exist.get in class EnumCache<E extends CoreDynamicEnum<E>>name - the name of the enum instance to be retrieved.null if not present.public E valueOf(String name)
valueOf in class EnumCache<E extends CoreDynamicEnum<E>>name - the name of the enum instance to be retrieved or created.null; unknown names are created on demand.public int size()
size in class EnumCache<E extends CoreDynamicEnum<E>>public E forIndex(int index)
forIndex in class EnumCache<E extends CoreDynamicEnum<E>>index - the ordinal index of the enum instance to retrieve.public E[] asArray()
asArray in class EnumCache<E extends CoreDynamicEnum<E>>public <T> Map<E,T> createMap()
createMap in class EnumCache<E extends CoreDynamicEnum<E>>T - map value typepublic Set<E> createSet()
createSet in class EnumCache<E extends CoreDynamicEnum<E>>@TestOnly public void reset()
Copyright © 2026 Chronicle Software Ltd. All rights reserved.