Class AbstractColumn<T>
java.lang.Object
org.refcodes.tabular.AbstractColumn<T>
- Type Parameters:
T- The type managed by the column.
- All Implemented Interfaces:
Cloneable, KeyAccessor<String>, TypeAccessor<T>, Column<T>
- Direct Known Subclasses:
BooleanColumn, DateColumn, DoubleColumn, EnumColumn, ExceptionColumn, FloatColumn, IntColumn, LongColumn, ObjectColumn, StringColumn, StringsColumn
The
AbstractColumn is the default implementation for the
Column interface. It implements amongst others the
toStorageString(Object) and fromStorageString(String)
methods leaving the developer to implement in sub-classes only the two
methods Column.toStorageStrings(Object) as well as
Column.fromStorageStrings(String[]) which are to do the actual conversions.
Special care is taken when the type T is an array type:
The method toStorageString(Object) returns a String with
separated values (in terms of CSV) in case the type T is an array type. The
delimiter of the values in this String then is the
Delimiter.ARRAY character as we use the Delimiter.CSV when
embedding the returned String in a CSV list (file).
The method fromStorageString(String) interprets the passed
String as separated values (in terms of CSV) in case the type T is an
array type. It creates a String array from the String value;
the delimiter of the values in the String used is the
Delimiter.ARRAY character as we use the Delimiter.CSV when
parsing a String in a CSV list (file).
-
Nested Class Summary
Nested classes/interfaces inherited from interface KeyAccessor
KeyAccessor.KeyBuilder<K,B>, KeyAccessor.KeyMutator<K>, KeyAccessor.KeyProperty<K> Nested classes/interfaces inherited from interface TypeAccessor
TypeAccessor.TypeBuilder<T,B>, TypeAccessor.TypeMutator<T>, TypeAccessor.TypeProperty<T> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()booleanfromStorageString(String aStringValue) AColumnimplementation can provide its own text exchange format for the given objects.getKey()getType()toPrintable(T aValue) AColumnimplementation can provide its own printable format of the given objects; for example a human readable text representation of the value (or in very https://www.metacodes.proized cases even enriched with ANSI escape codes).toStorageString(T aValue) AColumnimplementation can provide its own text exchange format for the given objects.Methods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Column
fromStorageStrings, getValue, toStorageString_, toStorageStrings
-
Constructor Details
-
AbstractColumn
-
-
Method Details
-
toStorageString
AColumnimplementation can provide its own text exchange format for the given objects. This method enables theColumnto convert a value of the given type to aStringand viaColumn.fromStorageString(String)back to the value (bijective). This method supports data sinks (such as relational databases) which allow only a single value in a row's entry: In case T is an array type, then the storageStringrepresentation of the elements in that array are represented by a single returnedString. Question: Why does the detour through the methodColumn.toStorageString(Object)not function?!? Having this snippet in the code seems to be fine for the compiler ... tryingColumn.toStorageString_(Object)instead :-( In case a data sink (such as Amazon's SimpleDb) is to be addressed which provides dedicated support for multiple values in one row's entry, then the methodColumn.toStorageStrings(Object)may be used instead.- Specified by:
toStorageStringin interfaceColumn<T>- Parameters:
aValue- the element to be converted to aString.- Returns:
- The
Stringrepresentation of the value.
-
fromStorageString
AColumnimplementation can provide its own text exchange format for the given objects. This method enables theColumnto convert aStringvalue to a value of the given type and viaColumn.toStorageString(Object)back to theString(bijective). This method supports data sinks (such as relational databases) which allow only a single value in a row's entry: In case T is an array type, then the storageStringrepresentation of the elements in that array are represented by the single passedString. In case a data sink (such as Amazon's SimpleDb) is to be addressed which provides dedicated support for multiple values in one row's entry, then the methodColumn.fromStorageStrings(String[])may be used instead.- Specified by:
fromStorageStringin interfaceColumn<T>- Parameters:
aStringValue- The value to be converted to a type instance.- Returns:
- The type representation of the value.
- Throws:
ParseException- in case parsing theStringwas not possible
-
toPrintable
AColumnimplementation can provide its own printable format of the given objects; for example a human readable text representation of the value (or in very https://www.metacodes.proized cases even enriched with ANSI escape codes). This method enables theColumnto convert a value of the given type to a human readable text. The human readable text, in comparison to the methodObject.toString()(orColumn.toStorageString(Object)) is not intended to be converted back to the actual value (not bijective). This method may be used aHeaderinstance's methodHeaderRow.toPrintable(Record).- Specified by:
toPrintablein interfaceColumn<T>- Parameters:
aValue- the element to be converted to a human readable text.- Returns:
- The human readable representation of the value.
-
contains
Tests whether theRecordcontains a value identified by theColumninstance's key and where the value's type is assignable to theColumninstance's type. Only if them both criteria match, then true is returned. False is returned if there is no such value or the value is not assignable to theColumninstance's type.- Specified by:
containsin interfaceColumn<T>- Parameters:
aRecord- TheRecordwhich to test if there is a value associated to theColumninstance's key and if it can be casted to theColumninstance's type.- Returns:
- True in case the
Recordcontains a value identified by theColumninstance's key and where the value's type is assignable to theColumninstance's type.
-
get
Retrieves a type correct value from theRecordidentified by theColumninstance's key. In case the type of theColumninstance does not match the value's type associated with theColumninstance's key, then aColumnMismatchExceptionis thrown.- Specified by:
getin interfaceColumn<T>- Parameters:
aRecord- TheRecordfrom which to retrieve the value associated to theColumninstances key.- Returns:
- The value from the
Recordassociated to theColumninstances key. - Throws:
ColumnMismatchException- in case the value in theRecordassociated with theColumninstance's key does not fit theColumninstance's type.
-
remove
Removes an entry (key and value pair) from the providedRecordmatching the key and the type of theColumn.- Specified by:
removein interfaceColumn<T>- Parameters:
aRecord- TheRecordfrom which to remove the related entry.- Returns:
- The value related to the given
Columninstance's key or null if there was none such value found. - Throws:
ColumnMismatchException- in case the value in theRecordassociated with theColumninstance's key does not fit theColumninstance's type.
-
getType
- Specified by:
getTypein interfaceTypeAccessor<T>
-
getKey
- Specified by:
getKeyin interfaceKeyAccessor<T>
-
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-