Class ColType
- All Implemented Interfaces:
Serializable
,Cloneable
- Direct Known Subclasses:
NominalType
,OrdinalType
,StringType
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Add a type, that is, register it.Add a value, that is, adapt the range of values.Add a value, that is, adapt the range of values.abstract void
clear()
Clear the range of values.void
Clear all additional information.abstract Object
clone()
Clone this type.int
Get the identifier of a value.boolean
Check whether an array fits this type.static String[]
Get all type names.static String[]
getAllTypeNames
(int cnt) Get all type names.getInfo
(int id) Get the additional information for a value given its identifier.Get the information for a value or a property.int
Get the number of values with additional information.getName()
Get the name of the type.double
getNumberAt
(Object array, int index) Get an array element as a number.abstract Class<?>
Get the class used to store values of this type.getStringAt
(Object array, int index) Get an array element as a string.static Class<?>
getTypeClass
(int id) Get type class for a type identifier.static Class<?>
getTypeClass
(String name) Get type class for a name.static int
Get the number of types.static int
Get identifier for a type name.static int
Get identifier for a type.static String
getTypeName
(int id) Get type name for a type identifier.getValue
(int id) Get the value associated with an identifier.getValueAt
(Object array, int index) Get an array element as an object.abstract Class<?>
Get the class used to access values of this type.int
Get the number of values.int
getValueId
(Object value) Get the identifier of a value.boolean
Check whether an array element is null.static ColType
parseType
(util.Scanner scan) Parse a type description.abstract Object
parseValue
(String desc) Parse a value from a string.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
Set a range of array elements to a null value.void
setValueAt
(Object array, int index, Object value) Set an array element from an object.toString()
Create a string description.
-
Field Details
-
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
Add a type, that is, register it.- Parameters:
name
- the name of the typecls
- 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
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
Get identifier for a type.- Parameters:
type
- the type- Returns:
- the identifier of the type
- Since:
- 2007.06.07 (Christian Borgelt)
-
getTypeClass
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
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
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
Get all type names.- Returns:
- an array of type names
- Since:
- 2007.06.07 (Christian Borgelt)
-
getAllTypeNames
Get all type names.- Parameters:
cnt
- the maximum number of names- Returns:
- an array of type names
- Since:
- 2007.06.07 (Christian Borgelt)
-
clone
Clone this type. -
getName
Get the name of the type.- Returns:
- the name of the type
- Since:
- 2007.07.13 (Christian Borgelt)
-
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 bysetValueAt()
).- Returns:
- the class used for accessing values of this type
- Since:
- 2006.10.04 (Christian Borgelt)
- See Also:
-
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 bygetValueAt()
.- Returns:
- the class used for storing values of this type
- Since:
- 2006.10.04 (Christian Borgelt)
- See Also:
-
fits
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
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 functionsetValueAt()
(and which refers to an internal value buffer), ornull
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
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 addinfo
- 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
Get the identifier of a value.- Parameters:
value
- the value as an object- Returns:
- always
-1
- Since:
- 2007.07.13 (Christian Borgelt)
-
getValueId
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
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
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
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 modifyinfo
- the additional information to store- Since:
- 2007.07.13 (Christian Borgelt)
-
getInfo
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
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 valueinfo
- the additional information to store- Since:
- 2007.07.13 (Christian Borgelt)
-
getValueAt
Get an array element as an object.- Parameters:
array
- an array of values (the entries of which are instances of the class returned bygetStorageClass()
)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 an object.- Parameters:
array
- an array of values (the entries of which are instances of the class returned bygetStorageClass()
)index
- the index of the array element to setvalue
- the value to set- Since:
- 2006.10.04 (Christian Borgelt)
-
getStringAt
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
Get an array element as a number.This function should be overridden by numeric types.
- Parameters:
array
- the array to retrieve an element fromindex
- the array index from which to retrieve- Returns:
- always
0
- Since:
- 2007.07.13 (Christian Borgelt)
-
isNull
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
Set an array element to a null value.- Parameters:
array
- an array of valuesindex
- the index of the array element to set- Since:
- 2007.01.31 (Christian Borgelt)
- See Also:
-
setNull
Set a range of array elements to a null value.- Parameters:
array
- an array of valuesbeg
- 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
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
Create a string description. -
parseType
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)
-