Class EnumValue<T extends EnumValue<T>>
- java.lang.Object
-
- com.gengoai.EnumValue<T>
-
- Type Parameters:
T
- the type parameter
- All Implemented Interfaces:
Tag
,Serializable
,Cloneable
,Comparable<T>
- Direct Known Subclasses:
HierarchicalEnumValue
public abstract class EnumValue<T extends EnumValue<T>> extends Object implements Tag, Serializable, Cloneable, Comparable<T>
A enum like object that can have elements created at runtime as needed. Elements are singleton objects and can have their equality safely checked using the
==
operator. A python script in the mango tools directory (tools/enumGen.py
) bootstraps the creation of basic EnumValues. Names associated with EnumValues are normalized to be uppercase and have all whitespace replaced by underscores with consecutive whitespace becoming a single underscore. Names must not contain a period (.) or be blank.Examples of common usage patterns for EnumValue types generated using
tools/enumGen.py
are as follows://Enum values can be retrieved or created using the create method. MyEnum red = MyEnum.create("red"); MyEnum blue = MyEnum.create("blue); //Can emulate Java enum using the valueOf method MyEnum green = MyEnum.valueOf("gReEn"); //Can retrieve all instances in an unmodifiable set using the values method Set<MyEnum> allColors = MyEnum.values();
*If your EnumValue stores other information and want to ensure that declared instances are loaded in memory you can use Mango's
Preloader
to load during application startup.- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description String
canonicalName()
Retrieves the canonical name of the enum value, which is the canonical name of the enum class and the specified name of the enum value.protected Object
clone()
int
compareTo(T o)
boolean
equals(Object obj)
int
hashCode()
boolean
isInstance(Tag value)
Determines if this tag is an instance of a given tag.static void
main(String[] args)
The entry point of application.String
name()
The name of the tag.protected Object
readResolve()
protected abstract Registry<T>
registry()
Gets the registry used by this valueString
toString()
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.gengoai.Tag
isInstance, label, parent
-
-
-
-
Constructor Detail
-
EnumValue
protected EnumValue(String name)
Instantiates a new enum value.- Parameters:
name
- the name of the enum value
-
-
Method Detail
-
main
public static void main(String[] args) throws Exception
The entry point of application.- Parameters:
args
- the input arguments- Throws:
Exception
- the exception
-
canonicalName
public final String canonicalName()
Retrieves the canonical name of the enum value, which is the canonical name of the enum class and the specified name of the enum value.
- Returns:
- the canonical name of the enum value
-
clone
protected final Object clone() throws CloneNotSupportedException
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-
compareTo
public int compareTo(T o)
- Specified by:
compareTo
in interfaceComparable<T extends EnumValue<T>>
-
isInstance
public boolean isInstance(Tag value)
Description copied from interface:Tag
Determines if this tag is an instance of a given tag.- Specified by:
isInstance
in interfaceTag
- Parameters:
value
- The given tag to check if this one is an instance of- Returns:
- True if this tag is an instance of the given tag
-
readResolve
protected Object readResolve() throws ObjectStreamException
- Throws:
ObjectStreamException
-
registry
protected abstract Registry<T> registry()
Gets the registry used by this value- Returns:
- the registry
-
-