Class NominalAttribute


  • public class NominalAttribute
    extends Attribute
    Stores information for a nominal attribute. A nominal attribute has has a name and a domain.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.ArrayList<java.lang.String> domain
      a list of strings for the domain of nominal attributes
    • Constructor Summary

      Constructors 
      Constructor Description
      NominalAttribute()
      Default constructor.
      NominalAttribute​(java.lang.String name)
      Explicit constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addValue​(java.lang.String value)
      Adds a new nominal value to the domain of this nominal attribute.
      int getIndex​(java.lang.String value)
      Returns the index of the specified value index for this nominal attribute.
      java.lang.String getValue​(int index)
      Returns the value of this nominal attribute at the specified index.
      static void main​(java.lang.String[] args)  
      int size()
      Gets the size of this nominal attribute's domain.
      java.lang.String toString()
      Returns a string representation of this NominalAttribute.
      boolean validValue​(java.lang.String value)
      Returns whether the value is valid for a nominal attribute
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • domain

        protected java.util.ArrayList<java.lang.String> domain
        a list of strings for the domain of nominal attributes
    • Constructor Detail

      • NominalAttribute

        public NominalAttribute()
        Default constructor.
      • NominalAttribute

        public NominalAttribute​(java.lang.String name)
        Explicit constructor. Creates a nominal attribute with the specified name.
        Parameters:
        name - the name of this data set
    • Method Detail

      • addValue

        public void addValue​(java.lang.String value)
        Adds a new nominal value to the domain of this nominal attribute.
        Parameters:
        value - the attribute's new domain value
      • size

        public int size()
        Gets the size of this nominal attribute's domain.
        Specified by:
        size in class Attribute
        Returns:
        an int storing the size of the domain
      • getValue

        public java.lang.String getValue​(int index)
        Returns the value of this nominal attribute at the specified index.
        Parameters:
        index - the attribute value's index
        Returns:
        the attribute value at the specified index
      • getIndex

        public int getIndex​(java.lang.String value)
                     throws java.lang.Exception
        Returns the index of the specified value index for this nominal attribute.
        Parameters:
        value - the attribute's value
        Returns:
        the index of the specified value
        Throws:
        java.lang.Exception - if the value is not in the domain
      • toString

        public java.lang.String toString()
        Returns a string representation of this NominalAttribute.
        Overrides:
        toString in class Attribute
        Returns:
        a string representation of this NominalAttribute
      • validValue

        public boolean validValue​(java.lang.String value)
        Returns whether the value is valid for a nominal attribute
        Parameters:
        value - the value for testing
        Returns:
        true if the value is valid; false otherwise
      • main

        public static void main​(java.lang.String[] args)