Class NominalAttribute<T>

java.lang.Object
com.groiss.ml.ds.Attribute<T>
com.groiss.ml.ds.NominalAttribute<T>
Direct Known Subclasses:
BooleanAttribute

public class NominalAttribute<T> extends Attribute<T>
Attribute which value can be one of a given set of values.
  • Constructor Details

    • NominalAttribute

      public NominalAttribute(String name, Class<T> clazz, List<S> values)
      Creates a new NominalAttribute.
      Parameters:
      name - the name of this attribute
      clazz - the class of the values represented by this attribute
      values - the possible values for objects represented by this attribute
    • NominalAttribute

      @SafeVarargs public NominalAttribute(String name, Class<T> clazz, S... values)
      Creates a new NominalAttribute.
      Parameters:
      name - the name of this attribute
      clazz - the class of the values represented by this attribute
      values - the possible values for objects represented by this attribute
  • Method Details

    • getARFFValues

      public String getARFFValues()
      Description copied from class: Attribute
      Returns the values supported by this attribute as ARFF string
      Specified by:
      getARFFValues in class Attribute<T>
      Returns:
      the supported values as ARFF string
    • getValueAt

      public T getValueAt(int index)
      Returns the value at the given index within the values of this attribute.
      Parameters:
      index - the index of the wanted value
      Returns:
      value of this attribute at given index
    • hasValue

      public boolean hasValue(Object value)
      Returns true if the passed value is supported by this attribute (i.e. if it is part of the values defined by the constructor)
      Parameters:
      value - the requested value
      Returns:
      true if this nominal attribute can represent the given value, false otherwise
      Throws:
      ClassCastException - if the type of the specified element is incompatible with this attribute
    • getIndexOf

      public int getIndexOf(Object value)
      Returns the index of the passed value within the values represented by this class.
      Parameters:
      value - the requested value
      Returns:
      index at which the given object is stored, or -1 if there is no such index
      Throws:
      ClassCastException - if the type of the specified element is incompatible with this attribute
    • checkTypeCompatibility

      protected void checkTypeCompatibility(Object value)
    • getIndexOfValueAsString

      public int getIndexOfValueAsString(String value)
      Returns the index of the value within the values represented by this class where the string representation of those values equals the given string
      Parameters:
      value - the string representation of the requested value
      Returns:
      index of value where the String representation equals the given String, or -1 if there is no such index
    • getValues

      public List<T> getValues()
      Returns a list of the values supported by this attribute
      Returns:
      values a field in the column of this nominal attribute can become