Package table

Class NominalType

java.lang.Object
table.ColType
table.NominalType
All Implemented Interfaces:
Serializable, Cloneable

public class NominalType extends ColType
Class for nominal types for data tables.
Since:
2006.09.11
See Also:
  • Field Details

    • NULL

      public static final int NULL
      a null value (of the storage class)
      See Also:
  • Constructor Details

    • NominalType

      public NominalType()
      Create for a nominal type.
      Since:
      2006.09.11 (Christian Borgelt)
    • NominalType

      public NominalType(Object[] values)
      Create for a nominal type.
      Parameters:
      values - the list of values as objects
      Since:
      2006.09.11 (Christian Borgelt)
    • NominalType

      public NominalType(NominalType type)
      Create a clone of a nominal type.
      Parameters:
      type - the nominal type to clone
      Since:
      2006.10.06 (Christian Borgelt)
  • Method Details

    • clone

      public Object clone()
      Clone this type.
      Specified by:
      clone in class ColType
      Returns:
      a clone of this type
      Since:
      2006.10.06 (Christian Borgelt)
    • getName

      public String getName()
      Get the name of the type.
      Overrides:
      getName in class ColType
      Returns:
      the name of the type
      Since:
      2007.02.13 (Christian Borgelt)
    • getValueClass

      public Class<?> getValueClass()
      Get the class used to access values of this type, that is, Object.class.
      Specified by:
      getValueClass in class ColType
      Returns:
      Object.class
      Since:
      2006.10.04 (Christian Borgelt)
      See Also:
    • getStorageClass

      public Class<?> getStorageClass()
      Get the class used to store values of this type, that is, int.class.
      Specified by:
      getStorageClass in class ColType
      Returns:
      int.class
      Since:
      2006.10.04 (Christian Borgelt)
      See Also:
    • fits

      public boolean fits(Object array)
      Check whether an array fits this type.

      This function need not really be here, since the generic version in ColType.java yields the same result. However, this version is more efficient.

      Overrides:
      fits in class ColType
      Parameters:
      array - the array to check
      Returns:
      whether the array has the correct type
      Since:
      2007.02.02 (Christian Borgelt)
    • getValueCount

      public int getValueCount()
      Get the number of values.
      Overrides:
      getValueCount in class ColType
      Returns:
      the number of values
      Since:
      2006.09.16 (Christian Borgelt)
    • addValue

      public Object addValue(Object value)
      Add a value, that is, adapt the range of values.
      Overrides:
      addValue in class ColType
      Parameters:
      value - the value to add
      Returns:
      a value that can be used efficiently with setValueAt()
      Since:
      2006.09.11 (Christian Borgelt)
    • addValue

      public Object addValue(Object value, Object info)
      Add a value, that is, adapt the range of values.
      Overrides:
      addValue in class ColType
      Parameters:
      value - the value to add
      info - the additional information to store with the value
      Returns:
      a value that can be used efficiently with setValueAt()
      Since:
      2006.09.11 (Christian Borgelt)
      See Also:
    • findValue

      public int findValue(Object value)
      Get the identifier of a value.
      Overrides:
      findValue in class ColType
      Parameters:
      value - the value as an object
      Returns:
      the identifier that is assigned to the value or -1 if the value is not in the type
      Since:
      2006.10.04 (Christian Borgelt)
      See Also:
    • getValueId

      public int getValueId(Object value)
      Get the identifier of a value.
      Overrides:
      getValueId in class ColType
      Parameters:
      value - the value as an object
      Returns:
      the identifier that is assigned to the value or -1 if the value is not in the type
      Since:
      2006.09.11 (Christian Borgelt)
      See Also:
    • getValue

      public Object getValue(int id)
      Get a value given its identifier.
      Overrides:
      getValue in class ColType
      Parameters:
      id - the identifier of the value
      Returns:
      the object that is associated with the identifier
      Throws:
      ArrayIndexOutOfBoundsException - if the identifier is outside the allowed range of 0 to getValueCount()-1
      Since:
      2006.09.11 (Christian Borgelt)
    • clear

      public void clear()
      Clear the range of values.
      Specified by:
      clear in class ColType
      Since:
      2007.07.19 (Christian Borgelt)
    • replaceValue

      public int replaceValue(int id, Object value)
      Replace a value by another.
      Parameters:
      id - the identifier of the value to replace
      value - the new value
      Returns:
      the identifier of the type, that is, id or -1 if replacing would create a duplicate
      Since:
      2007.07.19 (Christian Borgelt)
    • removeValue

      public void removeValue(int id)
      Remove a value.
      Parameters:
      id - the identifier of the value to remove
      Since:
      2007.07.19 (Christian Borgelt)
    • removeValue

      public void removeValue(Object value)
      Remove a value.
      Parameters:
      value - the value to remove
      Since:
      2007.07.19 (Christian Borgelt)
    • moveValue

      public void moveValue(int src, int dst)
      Move a value, that is, change its identifier.
      Parameters:
      src - the old identifier of the value
      dst - the new identifier of the value
      Since:
      2007.07.19 (Christian Borgelt)
    • reorderValues

      public void reorderValues(int[] map)
      Reorder the values.

      The desired reordering has to be stated as a permutation of the integer numbers 0 to getValueCount()-1, with each entry stating the new index for the value that is identified by the array index (forward map).

      If the reordering map is not such a permutation, the type will get into an inconsistent state that may lead to serious errors.

      Parameters:
      map - an integer array containing a permutation of the integer numbers 0 to getColumnCount()-1
      Since:
      2007.01.31 (Christian Borgelt)
    • sort

      public int[] sort()
      Sort the values by their string representation.
      Returns:
      a map from the old indices (array indices) to the new indices (contents of array elements)
      Since:
      2007.07.25 (Christian Borgelt)
    • sort

      public int[] sort(Comparator<Object> cmp)
      Sort the values.
      Parameters:
      cmp - the comparator for the values
      Returns:
      a map from the old indices (array indices) to the new indices (contents of array elements)
      Since:
      2007.07.25 (Christian Borgelt)
    • clearInfo

      public void clearInfo()
      Clear all additional information.
      Overrides:
      clearInfo in class ColType
      Since:
      2013.12.26 (Christian Borgelt)
    • getInfoCount

      public int getInfoCount()
      Get the number of values with additional information.

      Each value can be associated with additional information.

      Overrides:
      getInfoCount in class ColType
      Returns:
      the number of values
      Since:
      2007.07.13 (Christian Borgelt)
    • getInfo

      public Object getInfo(Object value)
      Get the additional information for a value.
      Overrides:
      getInfo in class ColType
      Parameters:
      value - the value for which to get the additional information
      Returns:
      the additional information associated with the identifier
      Since:
      2007.02.18 (Christian Borgelt)
    • setInfo

      public void setInfo(Object value, Object info)
      Set the additional information for a value.
      Overrides:
      setInfo in class ColType
      Parameters:
      value - the value to modify
      info - the additional information to store
      Since:
      2007.02.18 (Christian Borgelt)
    • getInfo

      public Object getInfo(int id)
      Get the additional information for a value given its identifier.
      Overrides:
      getInfo in class ColType
      Parameters:
      id - the identifier of the value
      Returns:
      the additional information associated with the identifier
      Since:
      2007.02.18 (Christian Borgelt)
    • setInfo

      public void setInfo(int id, Object info)
      Set the additional information for a value given its identifier.
      Overrides:
      setInfo in class ColType
      Parameters:
      id - the identifier of the value
      info - the additional information to store
      Since:
      2007.02.18 (Christian Borgelt)
    • getValueAt

      public Object getValueAt(Object array, int index)
      Get an array element as an object.
      Overrides:
      getValueAt in class ColType
      Parameters:
      array - an array of identifiers, i.e. int[]
      index - the index of the array element to access
      Returns:
      the value as an object
      Since:
      2006.09.26 (Christian Borgelt)
    • setValueAt

      public void setValueAt(Object array, int index, Object value)
      Set an array element from a string.
      Overrides:
      setValueAt in class ColType
      Parameters:
      array - an array of identifiers, i.e. int[]
      index - the index of the array element to set
      value - the value to set
      Since:
      2006.09.26 (Christian Borgelt)
    • getStringAt

      public String getStringAt(Object array, int index)
      Get an array element as a string.
      Overrides:
      getStringAt in class ColType
      Parameters:
      array - an array of identifiers, i.e. int[]
      index - the index of the array element to get
      Returns:
      the created string description
      Since:
      2007.02.01 (Christian Borgelt)
      See Also:
    • isNull

      public boolean isNull(Object array, int index)
      Check whether an array element is null.
      Overrides:
      isNull in class ColType
      Parameters:
      array - an array of identifiers, i.e. int[]
      index - the index of the array element to check
      Returns:
      whether the array element is null
      Since:
      2007.01.31 (Christian Borgelt)
      See Also:
    • setNull

      public void setNull(Object array, int index)
      Set an array element to a null value.
      Overrides:
      setNull in class ColType
      Parameters:
      array - an array of identifiers, i.e. int[]
      index - the index of the array element to set
      Since:
      2007.01.31 (Christian Borgelt)
      See Also:
    • parseValue

      public Object parseValue(String desc)
      Parse an instance from a string.
      Specified by:
      parseValue in class ColType
      Parameters:
      desc - the string description to parse
      Returns:
      the parsed nominal value (identical to the argument)
      Since:
      2007.02.01 (Christian Borgelt)
      See Also:
    • toString

      public String toString()
      Create a string description.
      Overrides:
      toString in class ColType
      Returns:
      a string description of the type
      Since:
      2007.02.02 (Christian Borgelt)
    • parseType

      public static ColType parseType(util.Scanner scan) throws IOException
      Parse a type description.
      Parameters:
      scan - the scanner to read from
      Returns:
      the described type
      Throws:
      IOException - if a read error occurs
      Since:
      2007.02.16 (Christian Borgelt)