Class EnumParameter<E extends java.lang.Enum<E>>

  • Type Parameters:
    E - Enum type
    All Implemented Interfaces:
    Parameter<E>

    public class EnumParameter<E extends java.lang.Enum<E>>
    extends AbstractParameter<EnumParameter<E>,​E>
    Parameter class for a parameter specifying an enum type.

    Usage:

     // Enum declaration.
     enum MyEnum { VALUE1, VALUE2 };
     // Parameter value holder.
     MyEnum myEnumParameter;
     
     // ...
     
     // Parameterization.
     EnumParameter<MyEnum> param = new
     EnumParameter<MyEnum>(ENUM_PROPERTY_ID, MyEnum.class);
     // OR
     EnumParameter<MyEnum> param = new
     EnumParameter<MyEnum>(ENUM_PROPERTY_ID, MyEnum.class, MyEnum.VALUE1);
     // OR
     EnumParameter<MyEnum> param = new
     EnumParameter<MyEnum>(ENUM_PROPERTY_ID, MyEnum.class, true);
     
     if(config.grab(param)) {
       myEnumParameter = param.getValue();
     }
     
    Since:
    0.4.0
    Author:
    Florian Nuecke
    • Field Detail

      • enumClass

        protected java.lang.Class<E extends java.lang.Enum<E>> enumClass
        Reference to the actual enum type, for T.valueOf().
    • Constructor Detail

      • EnumParameter

        public EnumParameter​(OptionID optionID,
                             java.lang.Class<E> enumClass,
                             E defaultValue)
        Constructs an enum parameter with the given optionID, constraints and default value.
        Parameters:
        optionID - the unique id of the parameter
        defaultValue - the default value of the parameter
      • EnumParameter

        public EnumParameter​(OptionID optionID,
                             java.lang.Class<E> enumClass)
        Constructs an enum parameter with the given optionID, constraints and default value.
        Parameters:
        optionID - the unique id of the parameter
    • Method Detail

      • getSyntax

        public java.lang.String getSyntax()
        Description copied from interface: Parameter
        Returns a string representation of the parameter's type (e.g., an IntParameter should return <int>).
        Returns:
        a string representation of the parameter's type
      • getValueAsString

        public java.lang.String getValueAsString()
        Description copied from interface: Parameter
        Get the value as string. May return null
        Returns:
        Value as string
      • describeValues

        public java.lang.StringBuilder describeValues​(java.lang.StringBuilder buf)
        Description copied from interface: Parameter
        Describe the valid values.
        Specified by:
        describeValues in interface Parameter<E extends java.lang.Enum<E>>
        Overrides:
        describeValues in class AbstractParameter<EnumParameter<E extends java.lang.Enum<E>>,​E extends java.lang.Enum<E>>
        Parameters:
        buf - Buffer to append to
        Returns:
        Buffer
      • getPossibleValues

        public java.util.Collection<java.lang.String> getPossibleValues()
        Get a list of possible values for this enum parameter.
        Returns:
        list of strings representing possible enum values.
      • joinEnumNames

        private java.lang.String joinEnumNames​(java.lang.String separator)
        Utility method for merging possible values into a string for informational messages.
        Parameters:
        separator - char sequence to use as a separator for enum values.
        Returns:
        {VAL1}{separator}{VAL2}{separator}...
      • grab

        public boolean grab​(Parameterization config,
                            java.util.function.Consumer<E> consumer)
        Get the parameter.
        Parameters:
        config - Parameterization
        consumer - Output consumer
        Returns:
        true if valid