-
- Type Parameters:
T
- The type managed by theHeader
.
- All Superinterfaces:
org.refcodes.mixin.Clearable
,Collection<Column<? extends T>>
,ColumnRow<T,Column<? extends T>>
,HeaderRow<T,Column<? extends T>>
,Iterable<Column<? extends T>>
,org.refcodes.struct.Keys<String,Column<? extends T>>
,org.refcodes.struct.Keys.MutableKeys<String,Column<? extends T>>
,List<Column<? extends T>>
- All Known Implementing Classes:
HeaderImpl
,StringHeader
public interface Header<T> extends HeaderRow<T,Column<? extends T>>
A list ofColumn
instances, for example describing the elements of a CSV file (visually speaking the of the CSV file's header line), is represented by theHeader
. TheHeader
preserves an order for a list ofColumn
instances. AHeader
provides the semantics for relatedRow
instances.The
Keys.keySet()
method must provide a predictable order as ensured by theLinkedHashSet
class as of the ordered nature of theHeader
.
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default T
get(Row<T> aRow, String aKey)
default boolean
isEqualWith(Record<?> aRecord)
default boolean
isEqualWith(Row<?> aRow)
default boolean
isSubsetOf(Record<?> aRecord)
default boolean
isSubsetOf(Row<?> aRow)
default boolean
isSupersetOf(Record<?> aRecord)
default boolean
isSupersetOf(Row<?> aRow)
default <REC> Record<REC>
toIntersection(Record<REC> aRecord)
default String[]
toKeys()
Returns the keys of theHeader
in the intended order.default <REC> Record<REC>
toSubset(Record<REC> aRecord)
default Class<T>
toType()
default T[]
toValues(Record<T> aRecord)
Returns an array of the values stored by theRecord
in the order as defined by the header.-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface org.refcodes.tabular.ColumnRow
containsValue, withColumns
-
Methods inherited from interface org.refcodes.tabular.HeaderRow
fromStorageString, fromStorageString, fromStorageStringRecord, fromStorageStringRow, fromStorageStrings, fromStorageStrings, fromStorageStringsRecord, fromStorageStringsRow, indexOf, toPrintable, toPrintable, toPrintableRecord, toPrintableRow, toRecord, toRecord, toRecordIgnoreType, toRow, toRowIgnoreType, toStorageString, toStorageString, toStorageStringRecord, toStorageStringRow, toStorageStrings, toStorageStrings, toStorageStringsRecord, toStorageStringsRow
-
Methods inherited from interface org.refcodes.struct.Keys
containsKey, get, getOr, keySet, use, values
-
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray
-
-
-
-
Method Detail
-
get
default T get(Row<T> aRow, String aKey) throws HeaderMismatchException, ColumnMismatchException
This method retrieves a value from theRow
by taking the index of the according column of thisHeader
of the given key (the one with the given key) and returns that value. This is possible as the values in the row and in the header have an order. This method is a convenience delegate toRow.get(Header, String)
.- Parameters:
aRow
- TheRow
containing the value of the given key.aKey
- The key for which to retrieve the value.- Returns:
- The value in the row representing the key in the header.
- Throws:
HeaderMismatchException
- Thrown in case there is a mismatch between the givenHeaderMismatchException
and theRow
, i.e. the index for the given key in the header may be out of index of the given row or the given key does not exist in theHeader
.ColumnMismatchException
- in case the type defined in the column for that key does not match the type in the row identified by the given key.
-
toKeys
default String[] toKeys()
Returns the keys of theHeader
in the intended order.- Returns:
- The keys of the
Header
in correct order.
-
toValues
default T[] toValues(Record<T> aRecord)
Returns an array of the values stored by theRecord
in the order as defined by the header.- Parameters:
aRecord
- TheRecord
to be converted to an array of values.- Returns:
- The array of values.
-
isSubsetOf
default boolean isSubsetOf(Record<?> aRecord)
Tests whether the given potential subset ofHeader
elements is matching theRecord
's elements in terms of matching the same relevant attributes of theColumn
instances with the elements in theRecord
. I.e. allColumn
instances in the subset must match the elements, even if this has more elements. The test also fails (returns false) in case the types of the instances in theRecord
do not match the according key's type in theHeader
Column
instance or vice versa.- Parameters:
aRecord
- TheRecord
to be used for testing.- Returns:
- true in case all columns in the subset match this' elements or the argument passed was null.
-
isEqualWith
default boolean isEqualWith(Record<?> aRecord)
Tests whether the given potential equal set ofHeader
is matching theRecord
's elements in terms of matching the same relevant attributes of the columns with the elements in theRecord
. I.e. allHeader
in the subset must match the elements, and the number ofHeader
must be the same as the number of elements in theRecord
. The test also fails (returns false) in case the types of the instances in theRecord
do not match the according key's type in theHeader
Column
instance or vice versa.- Parameters:
aRecord
- TheRecord
to be used for testing.- Returns:
- True in case all columns in the subset match this' elements and the number of elements matches the number of columns or the argument passed was null.
-
isSupersetOf
default boolean isSupersetOf(Record<?> aRecord)
Tests whether theRecord
's elements is matching the given potential superset ofHeader
elements in terms of matching the same relevant attributes of the columns with the elements in theRecord
. I.e. all elements in theRecord
must match theHeader
in the superset, even if the superset has more elements. The test also fails (returns false) in case the types of the instances in theRecord
do not match the according key's type in theHeader
Column
instance or vice versa.- Parameters:
aRecord
- TheRecord
to be used for testing.- Returns:
- True in case all elements in this instance match the columns in the superset or the argument passed was null.
-
isSubsetOf
default boolean isSubsetOf(Row<?> aRow)
Tests whether thisHeader
is a subset of theRow
's elements in terms of matching the same relevant attributes of theHeader
with the elements in theRow
. I.e. allColumn
instances in the subset must match the elements, even if this has more elements. The test also fails (returns false) in case the types of the instances in theRow
do not match the according key's type in theHeader
Column
instance or vice versa.- Parameters:
aRow
- TheRow
to be used for testing.- Returns:
- true in case all columns in the subset match this' elements or the argument passed was null.
-
isEqualWith
default boolean isEqualWith(Row<?> aRow)
Tests whether the given potentialHeader
equal set is matching theRow
's elements in terms of matching the same relevant attributes of theHeader
with the elements in theRow
. I.e. allColumn
instances in the subset must match the elements, and the number of columns must be the same as the number of elements in theRow
. The test also fails (returns false) in case the types of the instances in theRow
do not match the according key's type in theHeader
Column
instance or vice versa.- Parameters:
aRow
- TheRow
to be used for testing.- Returns:
- True in case all columns in the subset match this' elements and the number of elements matches the number of columns or the argument passed was null.
-
isSupersetOf
default boolean isSupersetOf(Row<?> aRow)
Tests whether theRow
's elements is matching the given potentialHeader
superset in terms of matching the same relevant attributes of theHeader
with the elements in theRow
. I.e. all elements in theRow
must match theColumn
instances in the superset, even if the superset has more elements. The test also fails (returns false) in case the types of the instances in theRow
do not match the according key's type in theHeader
Column
instance or vice versa.- Parameters:
aRow
- TheRow
to be used for testing.- Returns:
- True in case all elements in this instance match the columns in the superset or the argument passed was null.
-
toIntersection
default <REC> Record<REC> toIntersection(Record<REC> aRecord) throws ColumnMismatchException
-
toSubset
default <REC> Record<REC> toSubset(Record<REC> aRecord) throws ColumnMismatchException
-
-