Package com.gengoai

Class EnumValue<T extends 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
    • 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
      • equals

        public final boolean equals​(Object obj)
        Overrides:
        equals in class Object
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class Object
      • 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 interface Tag
        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
      • name

        public String name()
        Description copied from interface: Tag
        The name of the tag.
        Specified by:
        name in interface Tag
        Returns:
        The name of the tag
      • registry

        protected abstract Registry<T> registry()
        Gets the registry used by this value
        Returns:
        the registry