T
- The type managed by the column.public abstract class AbstractColumn<T> extends Object implements Column<T>, Cloneable
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_DELIMITER
character as we use the
Delimiter.CSV_DELIMITER
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_DELIMITER
character as we use the
Delimiter.CSV_DELIMITER
when parsing a String
in a CSV
list (file).
SeparatedValuesUtility#toSeparatedValues(java.util.Collection, char)
,
SeparatedValuesUtility#fromSeparatedValues(String, char)
Constructor and Description |
---|
AbstractColumn(String aKey,
Class<T> aType)
Constructs a column.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone() |
boolean |
contains(Record<?> aRecord)
|
T |
fromStorageString(String aStringValue)
A
Column implementation can provide its own text exchange format
for the given objects. |
T |
get(Record<?> aRecord)
|
String |
getKey() |
Class<T> |
getType() |
T |
remove(Record<?> aRecord)
|
String |
toPrintable(T aValue)
A
Column 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). |
String |
toStorageString(T aValue)
A
Column implementation can provide its own text exchange format
for the given objects. |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
fromStorageStrings, toStorageStrings
public String toStorageString(T aValue)
Column
implementation can provide its own text exchange format
for the given objects. This method enables the Column
to convert
a value of the given type to a String
and via
Column.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 storage String
representation of the elements in that
array are represented by a single returned String
.
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 method Column.toStorageStrings(Object)
may be used instead.
ATTENTION: This implementation calls Column.toStorageStrings(Object)
:
It 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_DELIMITER
character as we use the Delimiter.CSV_DELIMITER
when
embedding the returned String
in a CSV list (file).
This means that for array types special characters as quotation marks or
the Delimiter.ARRAY_DELIMITER
character are escaped as of
SeparatedValuesUtility#toSeparatedValues(java.util.Collection, char)
even in case there is just one element in the array.
In case T is not an array type then we expect exactly one element in the
String
array to be returned by Column.toStorageStrings(Object)
which then is returned untouched (not escaped); in case the returned
array contains more than one element an IllegalArgumentException
is thrown.toStorageString
in interface Column<T>
aValue
- the element to be converted to a String
.String
representation of the value.IllegalArgumentException
- Thrown in case the type T is not an
array type and the method Column.toStorageStrings(Object)
returns an array with more than one elements.SeparatedValuesUtility#toSeparatedValues(java.util.Collection, char)
public T fromStorageString(String aStringValue) throws ParseException
Column
implementation can provide its own text exchange format
for the given objects. This method enables the Column
to convert
a String
value to a value of the given type and via
Column.toStorageString(Object)
back to the String
(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 storage String
representation of the elements in that
array are represented by the single passed String
.
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 method Column.fromStorageStrings(String[])
may be used instead.
ATTENTION: This implementation calls
Column.fromStorageStrings(String[])
:
It 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_DELIMITER
character as we use the Delimiter.CSV_DELIMITER
when
parsing a String
in a CSV list (file).
This means that for array types special characters as quotation marks or
the Delimiter.ARRAY_DELIMITER
character are unescaped as of
SeparatedValuesUtility#fromSeparatedValues(String, char)
even in
case there is just one element in the array.
In case T is not an array type then we leave the String
value
untouched (not unescaped) and call Column.fromStorageStrings(String[])
with a String
array just containing that String
value as
its only element.fromStorageString
in interface Column<T>
aStringValue
- The value to be converted to a type instance.ParseException
- in case parsing the String
was not
possibleSeparatedValuesUtility#fromSeparatedValues(String, char)
public String toPrintable(T aValue)
Column
Column
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 the Column
to convert a value of the
given type to a human readable text. The human readable text, in
comparison to the method #toString()
(or
#toStorageFormat(Object)
) is not intended to be converted back to
the actual value (not bijective).
This method may be used a Header
instance's method
HeaderTemplate.toPrintable(Record)
.toPrintable
in interface Column<T>
aValue
- the element to be converted to a human readable text.public boolean contains(Record<?> aRecord)
Column
Record
contains a value identified by the
Column
instance's key and where the value's type is assignable to
the Column
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 the Column
instance's type.contains
in interface Column<T>
aRecord
- The Record
which to test if there is a value
associated to the Column
instance's key and if it can be
casted to the Column
instance's type.Record
contains a value identified by
the Column
instance's key and where the value's type is
assignable to the Column
instance's type.public T get(Record<?> aRecord) throws ColumnMismatchException
Column
Record
identified by the
Column
instance's key. In case the type of the Column
instance does not match the value's type associated with the
Column
instance's key, then a ColumnMismatchException
is
thrown.get
in interface Column<T>
aRecord
- The Record
from which to retrieve the value
associated to the Column
instances key.Record
associated to the
Column
instances key.ColumnMismatchException
- in case the value in the Record
associated with the Column
instance's key does not fit
the Column
instance's type.public T remove(Record<?> aRecord) throws ColumnMismatchException
Column
Record
matching the key and the type of the Column
.remove
in interface Column<T>
aRecord
- The Record
from which to remove the related entry.Column
instance's key or
null if there was none such value found.ColumnMismatchException
- in case the value in the Record
associated with the Column
instance's key does not fit
the Column
instance's type.public Class<T> getType()
getType
in interface org.refcodes.mixin.TypeAccessor
public String getKey()
getKey
in interface org.refcodes.mixin.KeyAccessor<String>
public Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
Copyright © 2017. All rights reserved.