Class Enumeration<T>

java.lang.Object
org.moeaframework.analysis.parameter.AbstractParameter<T>
org.moeaframework.analysis.parameter.Enumeration<T>
Type Parameters:
T - the type of each value
All Implemented Interfaces:
EnumeratedParameter<T>, Parameter<T>, SampledParameter<T>, Named

public class Enumeration<T> extends AbstractParameter<T> implements EnumeratedParameter<T>, SampledParameter<T>
An enumeration of a fixed set of possible values. This parameter can either be used to enumerate all possible values or sample according to a sequence.
  • Constructor Details

    • Enumeration

      @SafeVarargs public Enumeration(String name, T... values)
      Constructs an enumeration with a fixed set of possible values.
      Parameters:
      name - the parameter name
      values - the values
    • Enumeration

      public Enumeration(String name, List<T> values)
      Constructs an enumeration with a fixed set of possible values.
      Parameters:
      name - the parameter name
      values - the values
  • Method Details

    • size

      public int size()
      Returns the number of values defined by this enumeration.
      Returns:
      the number of values
    • values

      public List<T> values()
      Description copied from interface: EnumeratedParameter
      Returns all possible values produced by this enumeration.
      Specified by:
      values in interface EnumeratedParameter<T>
      Returns:
      the values
    • parse

      public T parse(String str)
      Description copied from interface: Parameter
      Parses this parameter value from the given string.
      Specified by:
      parse in interface Parameter<T>
      Parameters:
      str - the string
      Returns:
      the parameter value
    • enumerate

      public List<Sample> enumerate(List<Sample> samples)
      Description copied from interface: EnumeratedParameter
      Enumerates the parameters by creating a "cross join" with the existing samples. If given N samples as input, the result will contain N * values().size() samples.
      Specified by:
      enumerate in interface EnumeratedParameter<T>
      Parameters:
      samples - the input samples
      Returns:
      the enumerated samples including this parameter
    • sample

      public void sample(Sample sample, double scale)
      Description copied from interface: SampledParameter
      Samples this parameter and assigns the value to the sample. The scale is a value between 0.0 and 1.0, typically supplied by a Sequence, used to generate the sampled value.

      When converting the scale to the parameter value, implementations are expected to provide equal weighting to each possible value, so that a value does not appear more or less often than any other value.

      Specified by:
      sample in interface SampledParameter<T>
      Parameters:
      sample - the sample
      scale - value between 0.0 and 1.0 used to generate the sample
    • encode

      public String encode(Tokenizer tokenizer)
      Description copied from interface: Parameter
      Encodes this parameter definition in a format suitable for storing in a file.
      Specified by:
      encode in interface Parameter<T>
      Parameters:
      tokenizer - the tokenizer
      Returns:
      the string representation
    • decode

      public static Enumeration<String> decode(Tokenizer tokenizer, String line)
      Decodes the string representation of this parameter.
      Parameters:
      tokenizer - the tokenizer
      line - the string representation
      Returns:
      the decoded parameter
      Throws:
      InvalidParameterException - if the string representation is not a valid parameter