Package org.refcodes.tabular
Class AbstractColumn<T>
- java.lang.Object
-
- org.refcodes.tabular.AbstractColumn<T>
-
- Type Parameters:
T
- The type managed by the column.
- All Implemented Interfaces:
java.lang.Cloneable
,org.refcodes.mixin.KeyAccessor<T>
,org.refcodes.mixin.TypeAccessor<T>
,Column<T>
- Direct Known Subclasses:
DateColumnImpl
,ExceptionColumnImpl
,IntegerColumn
,ObjectColumn
,StringColumn
,StringsColumn
public abstract class AbstractColumn<T> extends java.lang.Object implements Column<T>, java.lang.Cloneable
TheAbstractColumn
is the default implementation for theColumn
interface. It implements amongst others thetoStorageString(Object)
andfromStorageString(String)
methods leaving the developer to implement in sub-classes only the two methodsColumn.toStorageStrings(Object)
as well asColumn.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 aString
with separated values (in terms of CSV) in case the type T is an array type. The delimiter of the values in thisString
then is theDelimiter.ARRAY
character as we use theDelimiter.CSV
when embedding the returnedString
in a CSV list (file).The method
fromStorageString(String)
interprets the passedString
as separated values (in terms of CSV) in case the type T is an array type. It creates aString
array from theString
value; the delimiter of the values in theString
used is theDelimiter.ARRAY
character as we use theDelimiter.CSV
when parsing aString
in a CSV list (file).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.KeyAccessor
org.refcodes.mixin.KeyAccessor.KeyBuilder<K extends java.lang.Object,B extends org.refcodes.mixin.KeyAccessor.KeyBuilder<K,B>>, org.refcodes.mixin.KeyAccessor.KeyMutator<K extends java.lang.Object>, org.refcodes.mixin.KeyAccessor.KeyProperty<K extends java.lang.Object>
-
-
Constructor Summary
Constructors Constructor Description AbstractColumn(java.lang.String aKey, java.lang.Class<T> aType)
Constructs a column.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
boolean
contains(Record<?> aRecord)
T
fromStorageString(java.lang.String aStringValue)
AColumn
implementation can provide its own text exchange format for the given objects.T
get(Record<?> aRecord)
java.lang.String
getKey()
java.lang.Class<T>
getType()
T
remove(Record<?> aRecord)
java.lang.String
toPrintable(T aValue)
AColumn
implementation can provide its own printable format of the given objects; for example a human readable text representation of the value (or in very specialized cases even enriched with ANSI escape codes).java.lang.String
toStorageString(T aValue)
AColumn
implementation can provide its own text exchange format for the given objects.-
Methods inherited from interface org.refcodes.tabular.Column
fromStorageStrings, getValue, getValue_, toStorageString_, toStorageStrings
-
-
-
-
Constructor Detail
-
AbstractColumn
public AbstractColumn(java.lang.String aKey, java.lang.Class<T> aType)
Constructs a column.- Parameters:
aKey
- The key describing the column.aType
- The type describing the column.
-
-
Method Detail
-
toStorageString
public java.lang.String toStorageString(T aValue)
AColumn
implementation can provide its own text exchange format for the given objects. This method enables theColumn
to convert a value of the given type to aString
and 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 storageString
representation of the elements in that array are represented by a single returnedString
. TODO: 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:
toStorageString
in interfaceColumn<T>
- Parameters:
aValue
- the element to be converted to aString
.- Returns:
- The
String
representation of the value.
-
fromStorageString
public T fromStorageString(java.lang.String aStringValue) throws java.text.ParseException
AColumn
implementation can provide its own text exchange format for the given objects. This method enables theColumn
to convert aString
value 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 storageString
representation 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:
fromStorageString
in interfaceColumn<T>
- Parameters:
aStringValue
- The value to be converted to a type instance.- Returns:
- The type representation of the value.
- Throws:
java.text.ParseException
- in case parsing theString
was not possible
-
toPrintable
public java.lang.String toPrintable(T aValue)
AColumn
implementation can provide its own printable format of the given objects; for example a human readable text representation of the value (or in very specialized cases even enriched with ANSI escape codes). This method enables theColumn
to 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 aHeader
instance's methodHeaderRow.toPrintable(Record)
.- Specified by:
toPrintable
in interfaceColumn<T>
- Parameters:
aValue
- the element to be converted to a human readable text.- Returns:
- The human readable representation of the value.
-
contains
public boolean contains(Record<?> aRecord)
Tests whether theRecord
contains a value identified by theColumn
instance's key and where the value's type is assignable to theColumn
instance'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 theColumn
instance's type.- Specified by:
contains
in interfaceColumn<T>
- Parameters:
aRecord
- TheRecord
which to test if there is a value associated to theColumn
instance's key and if it can be casted to theColumn
instance's type.- Returns:
- True in case the
Record
contains a value identified by theColumn
instance's key and where the value's type is assignable to theColumn
instance's type.
-
get
public T get(Record<?> aRecord) throws ColumnMismatchException
Description copied from interface:Column
Retrieves a type correct value from theRecord
identified by theColumn
instance's key. In case the type of theColumn
instance does not match the value's type associated with theColumn
instance's key, then aColumnMismatchException
is thrown.- Specified by:
get
in interfaceColumn<T>
- Parameters:
aRecord
- TheRecord
from which to retrieve the value associated to theColumn
instances key.- Returns:
- The value from the
Record
associated to theColumn
instances key. - Throws:
ColumnMismatchException
- in case the value in theRecord
associated with theColumn
instance's key does not fit theColumn
instance's type.
-
remove
public T remove(Record<?> aRecord) throws ColumnMismatchException
Description copied from interface:Column
Removes an entry (key and value pair) from the providedRecord
matching the key and the type of theColumn
.- Specified by:
remove
in interfaceColumn<T>
- Parameters:
aRecord
- TheRecord
from which to remove the related entry.- Returns:
- The value related to the given
Column
instance's key or null if there was none such value found. - Throws:
ColumnMismatchException
- in case the value in theRecord
associated with theColumn
instance's key does not fit theColumn
instance's type.
-
getType
public java.lang.Class<T> getType()
- Specified by:
getType
in interfaceorg.refcodes.mixin.TypeAccessor<T>
-
getKey
public java.lang.String getKey()
- Specified by:
getKey
in interfaceorg.refcodes.mixin.KeyAccessor<T>
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
- Overrides:
clone
in classjava.lang.Object
- Throws:
java.lang.CloneNotSupportedException
-
-