Package table

Class ColType

java.lang.Object
table.ColType
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
NominalType, OrdinalType, StringType

public abstract class ColType extends Object implements Cloneable, Serializable
Class for (column) types for data tables.

The values of a type can be represented by objects of two different types: one for unified external access and one for internal storage. The reason is that it is wasteful to use real Java objects to represent values of the basic types (like int, double etc), but that it is sometimes necessary to convert them to the corresponding object types (for example, for displaying data in a JTable). These two classes can be retrieved by getValueClass() and getStorageClass.

Since:
2006.09.11
See Also:
  • Field Details

    • CURRENT

      public static final Object CURRENT
      indicates that the internal current value should be used
  • Constructor Details

    • ColType

      public ColType()
      Create a column type.
      Since:
      2023.07.26 (Christian Borgelt)
  • Method Details

    • addType

      public static boolean addType(String name, Class<?> cls)
      Add a type, that is, register it.
      Parameters:
      name - the name of the type
      cls - the class of the type
      Returns:
      whether the type was registered
      Since:
      2007.02.13 (Christian Borgelt)
    • getTypeCount

      public static int getTypeCount()
      Get the number of types.
      Returns:
      the number of registered types
      Since:
      2007.02.13 (Christian Borgelt)
    • getTypeId

      public static int getTypeId(String name)
      Get identifier for a type name.
      Parameters:
      name - the name of the type
      Returns:
      the identifier of the type
      Since:
      2007.06.07 (Christian Borgelt)
    • getTypeId

      public static int getTypeId(ColType type)
      Get identifier for a type.
      Parameters:
      type - the type
      Returns:
      the identifier of the type
      Since:
      2007.06.07 (Christian Borgelt)
    • getTypeClass

      public static Class<?> getTypeClass(String name)
      Get type class for a name.
      Parameters:
      name - the name of the type
      Returns:
      the class of the type
      Since:
      2007.02.13 (Christian Borgelt)
    • getTypeClass

      public static Class<?> getTypeClass(int id)
      Get type class for a type identifier.
      Parameters:
      id - the identifier of the type
      Returns:
      the class of the type
      Since:
      2007.02.13 (Christian Borgelt)
    • getTypeName

      public static String getTypeName(int id)
      Get type name for a type identifier.
      Parameters:
      id - the identifier of the type
      Returns:
      the name of the type
      Since:
      2007.02.13 (Christian Borgelt)
    • getAllTypeNames

      public static String[] getAllTypeNames()
      Get all type names.
      Returns:
      an array of type names
      Since:
      2007.06.07 (Christian Borgelt)
    • getAllTypeNames

      public static String[] getAllTypeNames(int cnt)
      Get all type names.
      Parameters:
      cnt - the maximum number of names
      Returns:
      an array of type names
      Since:
      2007.06.07 (Christian Borgelt)
    • clone

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

      public String getName()
      Get the name of the type.
      Returns:
      the name of the type
      Since:
      2007.07.13 (Christian Borgelt)
    • getValueClass

      public abstract Class<?> getValueClass()
      Get the class used to access values of this type.

      This is the class of objects returned by getValueAt() and may differ from the class used for the internal storage (as used by setValueAt()).

      Returns:
      the class used for accessing values of this type
      Since:
      2006.10.04 (Christian Borgelt)
      See Also:
    • getStorageClass

      public abstract Class<?> getStorageClass()
      Get the class used to store values of this type.

      This is the class used for the internal storage (that is, the class converted to by setValueAt()) and may differ from the class of objects returned by getValueAt().

      Returns:
      the class used for storing values of this type
      Since:
      2006.10.04 (Christian Borgelt)
      See Also:
    • fits

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

      This function is generic and yields the correct result for all subclasses. Nevertheless it may be useful to overload it with a more efficient specific version.

      Parameters:
      array - the array to check
      Returns:
      whether the array has the storage type
      Since:
      2007.02.02 (Christian Borgelt)
    • getValueCount

      public int getValueCount()
      Get the number of values.

      This function should be overriden by types having (only) a finite number of values.

      Returns:
      always -1
      Since:
      2007.07.13 (Christian Borgelt)
    • addValue

      public Object addValue(Object value)
      Add a value, that is, adapt the range of values.

      By default this function simply returns its argument, since not all types need to keep track of the range of values. However, if they do, the result may be the argument, a different object (for example, of the storage class of this type), the specific object ColType.CURRENT that can be used efficiently with the function setValueAt() (and which refers to an internal value buffer), or null if the object cannot be converted to a value of the type.

      Parameters:
      value - the value to add
      Returns:
      the argument, possibly in a different form
      Since:
      2006.09.16 (Christian Borgelt)
    • addValue

      public Object addValue(Object value, Object info)
      Add a value, that is, adapt the range of values.

      The additional information is ignored. This function should be overridden by types that can store additional information for values or properties.

      Parameters:
      value - the value to add
      info - the additional information to store with the value
      Returns:
      the argument, possibly in a different form
      Since:
      2007.07.13 (Christian Borgelt)
      See Also:
    • findValue

      public int findValue(Object value)
      Get the identifier of a value.
      Parameters:
      value - the value as an object
      Returns:
      always -1
      Since:
      2007.07.13 (Christian Borgelt)
    • getValueId

      public int getValueId(Object value)
      Get the identifier of a value.
      Parameters:
      value - the value as an object
      Returns:
      always -1
      Since:
      2007.07.13 (Christian Borgelt)
      See Also:
    • getValue

      public Object getValue(int id)
      Get the value associated with an identifier.

      This function should be overriden by types having (only) a finite number of values.

      Parameters:
      id - the value identifier
      Returns:
      always null
      Since:
      2007.07.13 (Christian Borgelt)
    • clear

      public abstract void clear()
      Clear the range of values.
      Since:
      2007.07.19 (Christian Borgelt)
    • clearInfo

      public void clearInfo()
      Clear all additional information.

      This function should be overriden by types supporting additional information for values or properties.

      Since:
      2013.12.26 (Christian Borgelt)
    • getInfoCount

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

      This function should be overriden by types supporting additional information for values or properties.

      Returns:
      always 0
      Since:
      2007.06.11 (Christian Borgelt)
    • getInfo

      public Object getInfo(Object value)
      Get the information for a value or a property.

      This function should be overridden by types that can store additional information for values or properties.

      Parameters:
      value - the value for which to get additional information
      Returns:
      always null
      Since:
      2007.07.13 (Christian Borgelt)
    • setInfo

      public void setInfo(Object value, Object info)
      Set the additional information for a value.

      The additional information is ignored. This function should be overridden by types that can store additional information for values or properties.

      Parameters:
      value - the value to modify
      info - the additional information to store
      Since:
      2007.07.13 (Christian Borgelt)
    • getInfo

      public Object getInfo(int id)
      Get the additional information for a value given its identifier.

      This function should be overridden by types that can store additional information for values or properties.

      Parameters:
      id - the identifier of the value
      Returns:
      always null
      Since:
      2007.07.13 (Christian Borgelt)
    • setInfo

      public void setInfo(int id, Object info)
      Set the additional information for a value given its identifier.

      The additional information is ignored. This function should be overridden by types that can store information with values.

      Parameters:
      id - the identifier of the value
      info - the additional information to store
      Since:
      2007.07.13 (Christian Borgelt)
    • getValueAt

      public Object getValueAt(Object array, int index)
      Get an array element as an object.
      Parameters:
      array - an array of values (the entries of which are instances of the class returned by getStorageClass())
      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 an object.
      Parameters:
      array - an array of values (the entries of which are instances of the class returned by getStorageClass())
      index - the index of the array element to set
      value - the value to set
      Since:
      2006.10.04 (Christian Borgelt)
    • getStringAt

      public String getStringAt(Object array, int index)
      Get an array element as a string.
      Parameters:
      array - an array of values (of the storage class)
      index - the index of the array element to access
      Returns:
      the created string description
      Since:
      2007.02.01 (Christian Borgelt)
      See Also:
    • getNumberAt

      public double getNumberAt(Object array, int index)
      Get an array element as a number.

      This function should be overridden by numeric types.

      Parameters:
      array - the array to retrieve an element from
      index - the array index from which to retrieve
      Returns:
      always 0
      Since:
      2007.07.13 (Christian Borgelt)
    • isNull

      public boolean isNull(Object array, int index)
      Check whether an array element is null.
      Parameters:
      array - an array of values (of the storage class)
      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.
      Parameters:
      array - an array of values
      index - the index of the array element to set
      Since:
      2007.01.31 (Christian Borgelt)
      See Also:
    • setNull

      public void setNull(Object array, int beg, int end)
      Set a range of array elements to a null value.
      Parameters:
      array - an array of values
      beg - the index of the first array element (inclusive)
      end - the index of the last array element (exclusive)
      Since:
      2007.07.13 (Christian Borgelt)
      See Also:
    • parseValue

      public abstract Object parseValue(String desc)
      Parse a value from a string.
      Parameters:
      desc - the string description to parse
      Returns:
      the parsed object or null if parsing failed
      Since:
      2007.02.01 (Christian Borgelt)
      See Also:
    • toString

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

      public static ColType parseType(util.Scanner scan) throws IOException
      Parse a type description.

      This function must be overloaded in all subclasses.

      Parameters:
      scan - the scanner to read from
      Returns:
      the type of the column description parsed
      Throws:
      IOException - if a read error occurs
      Since:
      2007.02.16 (Christian Borgelt)