- java.lang.Object
-
- org.refcodes.tabular.AbstractColumn<T>
-
- Type Parameters:
T- The type managed by the column.
- All Implemented Interfaces:
Cloneable,org.refcodes.mixin.KeyAccessor<String>,org.refcodes.mixin.TypeAccessor<T>,Column<T>
- Direct Known Subclasses:
BooleanColumn,DateColumn,DoubleColumn,EnumColumn,ExceptionColumn,FloatColumn,IntColumn,LongColumn,ObjectColumn,StringColumn,StringsColumn
public abstract class AbstractColumn<T> extends Object implements Column<T>, Cloneable
TheAbstractColumnis the default implementation for theColumninterface. 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 aStringwith separated values (in terms of CSV) in case the type T is an array type. The delimiter of the values in thisStringthen is theDelimiter.ARRAYcharacter as we use theDelimiter.CSVwhen embedding the returnedStringin a CSV list (file).The method
fromStorageString(String)interprets the passedStringas separated values (in terms of CSV) in case the type T is an array type. It creates aStringarray from theStringvalue; the delimiter of the values in theStringused is theDelimiter.ARRAYcharacter as we use theDelimiter.CSVwhen parsing aStringin a CSV list (file).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.KeyAccessor
org.refcodes.mixin.KeyAccessor.KeyBuilder<K extends Object,B extends org.refcodes.mixin.KeyAccessor.KeyBuilder<K,B>>, org.refcodes.mixin.KeyAccessor.KeyMutator<K extends Object>, org.refcodes.mixin.KeyAccessor.KeyProperty<K extends Object>
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.TypeAccessor
org.refcodes.mixin.TypeAccessor.TypeBuilder<T extends Object,B extends org.refcodes.mixin.TypeAccessor.TypeBuilder<T,B>>, org.refcodes.mixin.TypeAccessor.TypeMutator<T extends Object>, org.refcodes.mixin.TypeAccessor.TypeProperty<T extends Object>
-
-
Constructor Summary
Constructors Constructor Description AbstractColumn(String aKey, Class<T> aType)Constructs a column.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectclone()booleancontains(Record<?> aRecord)TfromStorageString(String aStringValue)AColumnimplementation can provide its own text exchange format for the given objects.Tget(Record<?> aRecord)StringgetKey()Class<T>getType()Tremove(Record<?> aRecord)StringtoPrintable(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 specialized cases even enriched with ANSI escape codes).StringtoStorageString(T aValue)AColumnimplementation can provide its own text exchange format for the given objects.-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.refcodes.tabular.Column
fromStorageStrings, getValue, toStorageString_, toStorageStrings
-
-
-
-
Method Detail
-
toStorageString
public String toStorageString(T aValue)
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
public T fromStorageString(String aStringValue) throws ParseException
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
public String 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 specialized 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
public boolean contains(Record<?> aRecord)
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
public T get(Record<?> aRecord) throws ColumnMismatchException
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
public T remove(Record<?> aRecord) throws ColumnMismatchException
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
public Class<T> getType()
- Specified by:
getTypein interfaceorg.refcodes.mixin.TypeAccessor<T>
-
clone
public Object clone() throws CloneNotSupportedException
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
-