E
- the type of element stored in this kind of columnpublic abstract class AbstractColumn<E> extends java.lang.Object implements ColumnSpecification
A column specification that transforms each cell individually,
expecting each cell to follow a common format
and declaring a column invalid if any cell does not satisfy this requirement.
This abstraction can be applied to any homogeneous column:
if you can say "this column holds widgets,"
then you can use an AbstractColumn<Widget>
.
Constructor and Description |
---|
AbstractColumn(java.lang.String name)
Create a new column with the given name.
|
Modifier and Type | Method and Description |
---|---|
E |
extract(Column column,
int index)
Convert the given cell in the column
to a structured format.
|
java.util.List<E> |
extractAll(Column column)
Like calling
extract(Column, int) on each cell in a column. |
java.util.List<E> |
extractAllFrom(java.util.Map<? extends ColumnSpecification,? extends Column> columnMap)
Get all the data associated with this column in the given map.
|
java.lang.String |
getName()
Get a human-readable name of this column.
|
boolean |
isValid(Column column)
Determine whether the given column
represents a valid instance of this column specification.
|
protected abstract java.util.Optional<E> |
parse(java.lang.String s)
Attempt to parse the given string
into the format expected by this kind of column,
returning
Optional.empty() on failure. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getTypeName
public AbstractColumn(java.lang.String name)
name
- the name of this column, like "Pizza consumption"
public java.lang.String getName()
ColumnSpecification
"Radius"
,
not the abstract type, like "Numeric column"
.
(Use ColumnSpecification.getTypeName()
for that.)getName
in interface ColumnSpecification
protected abstract java.util.Optional<E> parse(java.lang.String s)
Optional.empty()
on failure.s
- a string representing an entry in a column,
which may or may not be validOptional.empty()
if the given string is not valid;
this must not be null
public boolean isValid(Column column) throws java.lang.NullPointerException
ColumnSpecification
isValid
in interface ColumnSpecification
column
- the column to checktrue
if the given column is valid,
or false if it is not
java.lang.NullPointerException
- if column == null
public E extract(Column column, int index) throws java.lang.IndexOutOfBoundsException
ColumnSpecification
Convert the given cell in the column
to a structured format.
The format depends on the implementation of the column specification;
implementations are encouraged to covariantly narrow the return type.
(For example, a numeric column specification
might override this method to return a Number
.)
If this is called on a column
that would not validate under ColumnSpecification.isValid(Column)
,
then the results are undefined.
extract
in interface ColumnSpecification
column
- the column containing the cell to extractindex
- the index into column
of the cell to extractjava.lang.IndexOutOfBoundsException
- if index
is out of the range of column
public java.util.List<E> extractAll(Column column)
Like calling extract(Column, int)
on each cell in a column.
Convert all the cells in the column to a structured format.
The format depends on the implementation of the column specification;
implementations are encouraged to covariantly narrow the return type.
(For example, a numeric column specification
might override this method to return a List<Number>
.)
If this is called on a column
that would not validate under isValid(Column)
,
then the results are undefined.
column
- the column containing the cell to extractextract(Column, int)
)public java.util.List<E> extractAllFrom(java.util.Map<? extends ColumnSpecification,? extends Column> columnMap)
Get all the data associated with this column in the given map.
The map probably comes from someSeries.data()
,
and you want to actually get the data associated with this column.
This method will do that.
More precisely:
given a map of column specifications to columns
that includes this column specification as a key,
get the column associated with this column
and call extractAll(Column)
on it.
If the column would not validate under isValid(Column)
,
then the results are undefined.
columnMap
- the map of column specifications to columns
that maps this column specification to some column of dataextract(Column, int)
)java.lang.IllegalArgumentException
- if this
is not a key in columnMap
,
or if the column on the other side is null