Package table
Class NominalType
java.lang.Object
table.ColType
table.NominalType
- All Implemented Interfaces:
Serializable
,Cloneable
Class for nominal types for data tables.
- Since:
- 2006.09.11
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreate for a nominal type.NominalType
(Object[] values) Create for a nominal type.NominalType
(NominalType type) Create a clone of a nominal type. -
Method Summary
Modifier and TypeMethodDescriptionAdd a value, that is, adapt the range of values.Add a value, that is, adapt the range of values.void
clear()
Clear the range of values.void
Clear all additional information.clone()
Clone this type.int
Get the identifier of a value.boolean
Check whether an array fits this type.getInfo
(int id) Get the additional information for a value given its identifier.Get the additional information for a value.int
Get the number of values with additional information.getName()
Get the name of the type.Class<?>
Get the class used to store values of this type, that is,int.class
.getStringAt
(Object array, int index) Get an array element as a string.getValue
(int id) Get a value given its identifier.getValueAt
(Object array, int index) Get an array element as an object.Class<?>
Get the class used to access values of this type, that is,Object.class
.int
Get the number of values.int
getValueId
(Object value) Get the identifier of a value.boolean
Check whether an array element is null.void
moveValue
(int src, int dst) Move a value, that is, change its identifier.static ColType
parseType
(util.Scanner scan) Parse a type description.parseValue
(String desc) Parse an instance from a string.void
removeValue
(int id) Remove a value.void
removeValue
(Object value) Remove a value.void
reorderValues
(int[] map) Reorder the values.int
replaceValue
(int id, Object value) Replace a value by another.void
Set the additional information for a value given its identifier.void
Set the additional information for a value.void
Set an array element to a null value.void
setValueAt
(Object array, int index, Object value) Set an array element from a string.int[]
sort()
Sort the values by their string representation.int[]
sort
(Comparator<Object> cmp) Sort the values.toString()
Create a string description.Methods inherited from class table.ColType
addType, getAllTypeNames, getAllTypeNames, getNumberAt, getTypeClass, getTypeClass, getTypeCount, getTypeId, getTypeId, getTypeName, setNull
-
Field Details
-
NULL
public static final int NULLa 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
Create for a nominal type.- Parameters:
values
- the list of values as objects- Since:
- 2006.09.11 (Christian Borgelt)
-
NominalType
Create a clone of a nominal type.- Parameters:
type
- the nominal type to clone- Since:
- 2006.10.06 (Christian Borgelt)
-
-
Method Details
-
clone
Clone this type. -
getName
Get the name of the type. -
getValueClass
Get the class used to access values of this type, that is,Object.class
.- Specified by:
getValueClass
in classColType
- Returns:
Object.class
- Since:
- 2006.10.04 (Christian Borgelt)
- See Also:
-
getStorageClass
Get the class used to store values of this type, that is,int.class
.- Specified by:
getStorageClass
in classColType
- Returns:
int.class
- Since:
- 2006.10.04 (Christian Borgelt)
- See Also:
-
fits
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.
-
getValueCount
public int getValueCount()Get the number of values.- Overrides:
getValueCount
in classColType
- Returns:
- the number of values
- Since:
- 2006.09.16 (Christian Borgelt)
-
addValue
Add a value, that is, adapt the range of values. -
addValue
Add a value, that is, adapt the range of values. -
findValue
Get the identifier of a value. -
getValueId
Get the identifier of a value.- Overrides:
getValueId
in classColType
- 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
Get a value given its identifier.- Overrides:
getValue
in classColType
- 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 togetValueCount()-1
- Since:
- 2006.09.11 (Christian Borgelt)
-
clear
public void clear()Clear the range of values. -
replaceValue
Replace a value by another.- Parameters:
id
- the identifier of the value to replacevalue
- 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
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 valuedst
- 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 togetColumnCount()-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
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. -
getInfoCount
public int getInfoCount()Get the number of values with additional information.Each value can be associated with additional information.
- Overrides:
getInfoCount
in classColType
- Returns:
- the number of values
- Since:
- 2007.07.13 (Christian Borgelt)
-
getInfo
Get the additional information for a value. -
setInfo
Set the additional information for a value. -
getInfo
Get the additional information for a value given its identifier. -
setInfo
Set the additional information for a value given its identifier. -
getValueAt
Get an array element as an object.- Overrides:
getValueAt
in classColType
- 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
Set an array element from a string.- Overrides:
setValueAt
in classColType
- Parameters:
array
- an array of identifiers, i.e.int[]
index
- the index of the array element to setvalue
- the value to set- Since:
- 2006.09.26 (Christian Borgelt)
-
getStringAt
Get an array element as a string.- Overrides:
getStringAt
in classColType
- 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
Check whether an array element is null. -
setNull
Set an array element to a null value. -
parseValue
Parse an instance from a string.- Specified by:
parseValue
in classColType
- 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
Create a string description. -
parseType
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)
-