Class AbstractVariable

java.lang.Object
org.moeaframework.core.variable.AbstractVariable
All Implemented Interfaces:
Serializable, Copyable<Variable>, Defined, Named, Variable
Direct Known Subclasses:
BinaryVariable, Grammar, Permutation, Program, RealVariable, Subset

public abstract class AbstractVariable extends Object implements Variable
Abstract class for implementing variables.

Variables can be assigned a name, but if unset will derive its name from its current index by calling Variable.getNameOrDefault(Variable, int). Such variables are also called "anonymous".

See Also:
  • Field Details

    • name

      protected final String name
      The variable name, or null if anonymous.
  • Constructor Details

    • AbstractVariable

      public AbstractVariable()
      Constructs a new, anonymous variable.
    • AbstractVariable

      public AbstractVariable(String name)
      Constructs a new variable with the given name.
      Parameters:
      name - the variable name, or null to create an anonymous variable
  • Method Details

    • getName

      public String getName()
      Description copied from interface: Named
      Returns the name of this object. The format for the name depends on the specific implementation, but in general we recommend:
      1. Prefer using alphanumeric characters including '_' and '-'.
      2. Avoid whitespace and other control characters.
      3. null can be returned, if allowed by the implementation, to indicate the object is anonymous or has no assigned name.
      Specified by:
      getName in interface Named
      Returns:
      the name
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object