Package table

Class Column

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

public class Column extends Object implements Cloneable, Serializable
Class for columns of a data table.
Since:
2007.01.31
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Object
    the data of the column (array of row values)
    protected int
    the direction of the column
    static final int
    direction: (unique) identifier
    static final int
    direction: input column
    static final int
    direction: do not use column
    static final int
    direction: output column
    static final int
    direction: weight column (tuple occurrences)
    protected int
    the marker of the column
    protected String
    the name of the column
    protected ColType
    the type of the column
    protected double
    the weight of the column
  • Constructor Summary

    Constructors
    Constructor
    Description
    Column(String name, ColType type)
    Create a column of a data table.
    Column(String name, ColType type, int rowcnt)
    Create a column of a data table.
    Column(String name, ColType type, Object data)
    Create a column of a data table.
  • Method Summary

    Modifier and Type
    Method
    Description
    Add a value, that is, adapt the range of values.
    void
    Automatically determine the type of a nominal or string column.
    void
    Clear all additional information.
    Clone this column.
    Clone a column as a type/domain description.
    void
    Clone the value array of the column.
    void
    Clone the type of the column.
    void
    cloneType(boolean update)
    Clone the type of the column.
    static String[]
    Get all direction names.
    static String[]
    getAllDirNames(int cnt)
    Get the name for a direction identifier.
    Get the value array of the column.
    int
    Get the direction of the column.
    static int
    Get the identifier for a direction name.
    static String
    getDirName(int id)
    Get the name for a direction identifier.
    getInfo(int id)
    Get the information associated with a value.
    getInfo(Object value)
    Get the information associated with a value.
    int
    Get the number of values for which there is information.
    int
    Get the marker value of the column.
    Get the name of the column.
    double
    getNumberAt(int row)
    Get the value of a column row as a number.
    int
    Get the number of rows of the column.
    getStringAt(int row)
    Get the value of a column row as a string.
    Get the type of the column.
    getValue(int id)
    Get the value associated with an identifier.
    getValueAt(int row)
    Get the value of a column row as an object.
    int
    Get the number of values.
    double
    Get the weight of the column.
    boolean
    Check whether a column contains null values.
    boolean
    isNull(int row)
    Check whether a column row is null.
    static Column
    parse(util.Scanner scan)
    Parse a column description.
    void
    resize(int newcnt)
    Resize the value array of the column.
    void
    resize(int newcnt, boolean init)
    Resize the value array of the column.
    void
    Set the value array of the column.
    void
    setDir(int dir)
    Set the direction of the column.
    void
    setInfo(int id, Object info)
    Set the information associated with a value or property.
    void
    setInfo(Object value, Object info)
    Set the information associated with a value.
    void
    setMark(int mark)
    Set the marker value of the column.
    void
    setNull(int row)
    Set a column row to a null value.
    void
    setNull(int beg, int end)
    Set a range of column rows to a null value.
    void
    Set the type of the column, that is, convert its type.
    void
    setValueAt(Object value, int row)
    Set the value of a column row from an object.
    void
    setWeight(double weight)
    Set the weight of the column.
    void
    Sort the values of the column type by their string description.
    void
    Sort the values of the column type.
    Create a string description of the column type.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • DIR_NONE

      public static final int DIR_NONE
      direction: do not use column
      See Also:
    • DIR_IN

      public static final int DIR_IN
      direction: input column
      See Also:
    • DIR_OUT

      public static final int DIR_OUT
      direction: output column
      See Also:
    • DIR_ID

      public static final int DIR_ID
      direction: (unique) identifier
      See Also:
    • DIR_WGT

      public static final int DIR_WGT
      direction: weight column (tuple occurrences)
      See Also:
    • name

      protected String name
      the name of the column
    • type

      protected ColType type
      the type of the column
    • data

      protected transient Object data
      the data of the column (array of row values)
    • dir

      protected int dir
      the direction of the column
    • mark

      protected int mark
      the marker of the column
    • weight

      protected double weight
      the weight of the column
  • Constructor Details

    • Column

      public Column(String name, ColType type, Object data)
      Create a column of a data table.

      The direction of the column is set to DIR_IN and its marker is initialized to 0.

      Parameters:
      name - the name of the column
      type - the type of the column
      data - the data of the column (array of row values)
      Since:
      2007.01.31 (Christian Borgelt)
    • Column

      public Column(String name, ColType type)
      Create a column of a data table.
      Parameters:
      name - the name of the column
      type - the type of the column
      Since:
      2007.02.16 (Christian Borgelt)
    • Column

      public Column(String name, ColType type, int rowcnt)
      Create a column of a data table.
      Parameters:
      name - the name of the column
      type - the type of the column
      rowcnt - the number of rows of the column
      Since:
      2007.01.31 (Christian Borgelt)
  • Method Details

    • getDirId

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

      public static String getDirName(int id)
      Get the name for a direction identifier.
      Parameters:
      id - the identifier of the direction
      Returns:
      the name of the direction
      Since:
      2007.06.07 (Christian Borgelt)
    • getAllDirNames

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

      public static String[] getAllDirNames(int cnt)
      Get the name for a direction identifier.
      Parameters:
      cnt - the maximum number of names
      Returns:
      an array of direction names
      Since:
      2007.06.07 (Christian Borgelt)
    • clone

      public Object clone()
      Clone this column.

      The clone is a shallow copy: it keeps the type and the value array of the original column. If a deep copy is desired, the functions cloneType() and cloneData() must be called afterwards.

      Overrides:
      clone in class Object
      Returns:
      a clone of this column
      Since:
      2007.01.31 (Christian Borgelt)
    • cloneAsType

      public Column cloneAsType()
      Clone a column as a type/domain description.

      The column as well as its type are cloned, while the data is omitted (the new column has a size of 0).

      Returns:
      a clone of the column as a type/domain description
      Since:
      2007.04.13 (Christian Borgelt)
    • cloneType

      public void cloneType()
      Clone the type of the column.
      Since:
      2007.01.31 (Christian Borgelt)
    • cloneType

      public void cloneType(boolean update)
      Clone the type of the column.

      Note that if update == true this function may also clone the value array if an update of the range of values requires recoding the values (e.g. for a nominal type).

      Parameters:
      update - whether to update the range of values
      Since:
      2007.02.02 (Christian Borgelt)
      See Also:
    • cloneData

      public void cloneData()
      Clone the value array of the column.

      Note, however, that this does not clone the row values itself if they are object instances (rather than basic types). Only the array containing them is cloned.

      Since:
      2007.01.31 (Christian Borgelt)
      See Also:
    • getName

      public String getName()
      Get the name of the column.

      Note that there is no corresponding setName() function, because when a column is part of a table, it may not be renamed directly, since the column access structure of the table needs to be updated.

      Returns:
      the name of the column
      Since:
      2007.01.31 (Christian Borgelt)
    • getType

      public ColType getType()
      Get the type of the column.
      Returns:
      the type of the column
      Since:
      2007.01.31 (Christian Borgelt)
    • setType

      public void setType(ColType type)
      Set the type of the column, that is, convert its type.

      Note that the type to convert to may coincide with the current type of the column. In this case the value array is cloned, maybe recoded, and the new range of values is determined.

      Parameters:
      type - the new type of the column
      Since:
      2007.01.31 (Christian Borgelt)
    • autoType

      public void autoType()
      Automatically determine the type of a nominal or string column.
      Since:
      2007.02.07 (Christian Borgelt)
    • sortType

      public void sortType()
      Sort the values of the column type by their string description.
      Since:
      2007.07.26 (Christian Borgelt)
    • sortType

      public void sortType(Comparator<Object> cmp)
      Sort the values of the column type.
      Parameters:
      cmp - the comparator for the values
      Since:
      2007.07.26 (Christian Borgelt)
    • getValueCount

      public int getValueCount()
      Get the number of values.
      Returns:
      the number of values
      Since:
      2007.07.13 (Christian Borgelt)
      See Also:
    • addValue

      public Object addValue(Object value)
      Add a value, that is, adapt the range of values.
      Parameters:
      value - the value to add
      Returns:
      the argument, possibly in a different form
      Since:
      2007.02.01 (Christian Borgelt)
      See Also:
    • getValue

      public Object getValue(int id)
      Get the value associated with an identifier.
      Parameters:
      id - the value identifier
      Returns:
      the value with the given identifier
      Since:
      2007.07.13 (Christian Borgelt)
      See Also:
    • clearInfo

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

      public int getInfoCount()
      Get the number of values for which there is information.
      Returns:
      the number of values for which there is information
      Since:
      2007.06.11 (Christian Borgelt)
      See Also:
    • getInfo

      public Object getInfo(Object value)
      Get the information associated with a value.
      Parameters:
      value - the value for which to get the information
      Returns:
      the additional information stored with the value
      Since:
      2007.02.18 (Christian Borgelt)
      See Also:
    • setInfo

      public void setInfo(Object value, Object info)
      Set the information associated with a value.
      Parameters:
      value - the value for which to set the information
      info - the information to set
      Since:
      2007.02.18 (Christian Borgelt)
      See Also:
    • getInfo

      public Object getInfo(int id)
      Get the information associated with a value.
      Parameters:
      id - the identifier of the value or property
      Returns:
      the information associated with the value
      Since:
      2007.02.20 (Christian Borgelt)
      See Also:
    • setInfo

      public void setInfo(int id, Object info)
      Set the information associated with a value or property.
      Parameters:
      id - the identifier of the value or property
      info - the information to set
      Since:
      2007.02.20 (Christian Borgelt)
      See Also:
    • getData

      public Object getData()
      Get the value array of the column.
      Returns:
      the value array of the column
      Since:
      2007.01.31 (Christian Borgelt)
    • setData

      public void setData(Object data)
      Set the value array of the column.

      Note that this function does not update the range of values of the column type. This may be achieved afterwards (except for nominal columns) by calling the function cloneType(true).

      Parameters:
      data - the value array of the column
      Since:
      2007.01.31 (Christian Borgelt)
      See Also:
    • getRowCount

      public int getRowCount()
      Get the number of rows of the column.
      Returns:
      the number of rows of the column
      Since:
      2007.02.01 (Christian Borgelt)
    • getDir

      public int getDir()
      Get the direction of the column.
      Returns:
      the direction of the column
      Since:
      2007.02.02 (Christian Borgelt)
    • setDir

      public void setDir(int dir)
      Set the direction of the column.
      Parameters:
      dir - the direction of the column
      Since:
      2007.02.02 (Christian Borgelt)
    • getWeight

      public double getWeight()
      Get the weight of the column.
      Returns:
      the weight of the column
      Since:
      2007.02.17 (Christian Borgelt)
    • setWeight

      public void setWeight(double weight)
      Set the weight of the column.
      Parameters:
      weight - the weight of the column
      Since:
      2007.02.17 (Christian Borgelt)
    • getMark

      public int getMark()
      Get the marker value of the column.
      Returns:
      the marker value of the column
      Since:
      2007.02.02 (Christian Borgelt)
    • setMark

      public void setMark(int mark)
      Set the marker value of the column.
      Parameters:
      mark - the marker value of the column
      Since:
      2007.02.02 (Christian Borgelt)
    • getValueAt

      public Object getValueAt(int row)
      Get the value of a column row as an object.
      Parameters:
      row - the row to access
      Returns:
      an object representing the value in the specified row
      Since:
      2007.02.01 (Christian Borgelt)
    • setValueAt

      public void setValueAt(Object value, int row)
      Set the value of a column row from an object.
      Parameters:
      value - the value to set in the specified cell
      row - the row to set
      Since:
      2007.02.01 (Christian Borgelt)
    • getStringAt

      public String getStringAt(int row)
      Get the value of a column row as a string.
      Parameters:
      row - the row to access
      Returns:
      the created string description
      Since:
      2007.02.02 (Christian Borgelt)
    • getNumberAt

      public double getNumberAt(int row)
      Get the value of a column row as a number.
      Parameters:
      row - the row to get
      Returns:
      the row entry as a number
      Since:
      2007.02.09 (Christian Borgelt)
    • isNull

      public boolean isNull(int row)
      Check whether a column row is null.
      Parameters:
      row - the row to check
      Returns:
      whether the column row is null
      Since:
      2007.02.02 (Christian Borgelt)
    • setNull

      public void setNull(int row)
      Set a column row to a null value.
      Parameters:
      row - the row to set
      Since:
      2007.02.02 (Christian Borgelt)
    • setNull

      public void setNull(int beg, int end)
      Set a range of column rows to a null value.
      Parameters:
      beg - the index of the first row (inclusive)
      end - the index of the last row (exclusive)
      Since:
      2007.03.15 (Christian Borgelt)
    • hasNulls

      public boolean hasNulls()
      Check whether a column contains null values.
      Returns:
      whether the column contains null values
      Since:
      2007.02.09 (Christian Borgelt)
    • resize

      public void resize(int newcnt)
      Resize the value array of the column.

      If the new number of rows is greater than the old, the additional fields are initialized with null values.

      Note that a new value array is allocated regardless of whether the new number of rows coincides with the old number or not. Hence calling this function with the old number of rows effectively clones the value array of the column.

      Parameters:
      newcnt - the new number of rows
      Since:
      2007.02.01 (Christian Borgelt)
      See Also:
    • resize

      public void resize(int newcnt, boolean init)
      Resize the value array of the column.

      Note that a new value array is allocated regardless of whether the new number of rows coincides with the old number or not. Hence calling this function with the old number of columns effectively clones the value array of the column.

      Parameters:
      newcnt - the new number of rows
      init - whether new fields should be initialized with null values
      Since:
      2007.02.01 (Christian Borgelt)
      See Also:
    • toString

      public String toString()
      Create a string description of the column type.
      Overrides:
      toString in class Object
      Returns:
      a string description of the column type
      Since:
      2007.02.09 (Christian Borgelt)
    • parse

      public static Column parse(util.Scanner scan) throws IOException
      Parse a column description.
      Parameters:
      scan - the scanner to read from
      Returns:
      the parsed description as a Column object
      Throws:
      IOException - if a read error occurs
      Since:
      2007.02.16 (Christian Borgelt)