Package xal.tools.data
Class GenericRecord
java.lang.Object
xal.tools.data.GenericRecord
- All Implemented Interfaces:
DataListener
,KeyedRecord
GenericRecord is the default record class for DataTable. This class can be
used directly for the records or a subclass of GenericRecord may be used for
convenience. GenericRecord stores its data as key/value pairs. Note that
GenericRecord is not thread safe. This is due to the fact that DataTable is
not thread safe.
- Author:
- tap
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A runtime exception thrown while attempting to parse values stored as strings into an object of the appropriate type. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
booleanValueForKey
(String key) Convenience method to get the value as a boolean associated with the specified key.dataLabel() provides the name used to identify the class in an external data source.double
doubleValueForKey
(String key) Convenience method to get the value as a double associated with the specified key.boolean
hasAttributeForKey
(String key) Determine whether this record has the specified attributeint
intValueForKey
(String key) Convenience method to get the value as an int associated with the specified key.keys()
Get the keys used in this record.long
longValueForKey
(String key) Convenience method to get the value as a long associated with the specified key.numberForKey
(String key) Convenience method to get the value cast as a number associated with the specified key.void
setValueForKey
(boolean value, String key) Set the boolean value to associate with the specified key.void
setValueForKey
(double value, String key) Set the double value to associate with the specified key.void
setValueForKey
(int value, String key) Set the int value to associate with the specified key.void
setValueForKey
(long value, String key) Set the long value to associate with the specified key.void
setValueForKey
(Object value, String key) Set the value to associate with the specified key.stringValueForKey
(String key) Convenience method to get the value as a String associated with the specified key.toString()
Overrides toString() to show key/value pairs.void
update
(DataAdaptor adaptor) Update the data based on the information provided by the data provider.valueForKey
(String key) Get the value associated with the specified key.values()
Get the collection of values held in this record.void
write
(DataAdaptor adaptor) Write data to the data adaptor for storage.
-
Field Details
-
dataTable
data table to which this record belongs -
attributeTable
table of attributes by attribute ID
-
-
Constructor Details
-
GenericRecord
Creates new GenericRecord
-
-
Method Details
-
keys
Get the keys used in this record.- Returns:
- The keys used in this record.
-
values
Get the collection of values held in this record.- Returns:
- The collection of values held in this record.
-
hasAttributeForKey
Determine whether this record has the specified attribute -
valueForKey
Get the value associated with the specified key.- Specified by:
valueForKey
in interfaceKeyedRecord
- Parameters:
key
- The key for which to get the associated value.- Returns:
- The value as an Object.
-
setValueForKey
Set the value to associate with the specified key. If the value associated with a primary key is changed we must be careful to force the table to re-index the record.- Parameters:
value
- The new value to associate with the specified key.key
- The key for which to associated the new value.
-
numberForKey
Convenience method to get the value cast as a number associated with the specified key.- Parameters:
key
- The key for which to get the associated value.- Returns:
- The value as an Number.
- Throws:
ClassCastException
- if the value cannot be cast as a Number.
-
booleanValueForKey
Convenience method to get the value as a boolean associated with the specified key.- Parameters:
key
- The key for which to get the associated value.- Returns:
- The value as an boolean.
- Throws:
ClassCastException
- if the value cannot be cast as a Boolean.
-
setValueForKey
Set the boolean value to associate with the specified key.- Parameters:
value
- The new boolean value to associate with the specified key.key
- The key for which to associated the new value.
-
intValueForKey
Convenience method to get the value as an int associated with the specified key.- Parameters:
key
- The key for which to get the associated value.- Returns:
- The value as an int.
- Throws:
ClassCastException
- if the value cannot be cast as a Number.
-
setValueForKey
Set the int value to associate with the specified key.- Parameters:
value
- The new int value to associate with the specified key.key
- The key for which to associated the new value.
-
longValueForKey
Convenience method to get the value as a long associated with the specified key.- Parameters:
key
- The key for which to get the associated value.- Returns:
- The value as a long.
- Throws:
ClassCastException
- if the value cannot be cast as a Number.
-
setValueForKey
Set the long value to associate with the specified key.- Parameters:
value
- The new long value to associate with the specified key.key
- The key for which to associated the new value.
-
doubleValueForKey
Convenience method to get the value as a double associated with the specified key.- Parameters:
key
- The key for which to get the associated value.- Returns:
- The value as a double.
- Throws:
ClassCastException
- if the value cannot be cast as a Number.
-
setValueForKey
Set the double value to associate with the specified key.- Parameters:
value
- The new double value to associate with the specified key.key
- The key for which to associated the new value.
-
stringValueForKey
Convenience method to get the value as a String associated with the specified key.- Parameters:
key
- The key for which to get the associated value.- Returns:
- The value as an String.
- Throws:
ClassCastException
- if the value cannot be cast as a String.
-
toString
Overrides toString() to show key/value pairs. -
dataLabel
dataLabel() provides the name used to identify the class in an external data source.- Specified by:
dataLabel
in interfaceDataListener
- Returns:
- a tag that identifies the receiver's type
-
update
Update the data based on the information provided by the data provider.- Specified by:
update
in interfaceDataListener
- Parameters:
adaptor
- The adaptor from which to update the data- Throws:
GenericRecord.ParseException
-
write
Write data to the data adaptor for storage.- Specified by:
write
in interfaceDataListener
- Parameters:
adaptor
- The adaptor to which the receiver's data is written
-