Package org.refcodes.tabular
Class TabularUtility
- java.lang.Object
-
- org.refcodes.tabular.TabularUtility
-
public final class TabularUtility extends java.lang.Object
Utility for listing specific functionality.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isEqualWith(Record<?> aRecord, Header<?> aEquivalsWith)
static boolean
isEqualWith(Row<?> aRow, Header<?> aEquivalsWith)
static boolean
isSubsetOf(Record<?> aRecord, Header<?> aSupersetOf)
static boolean
isSubsetOf(Row<?> aRow, Header<?> aSupersetOf)
static boolean
isSupersetOf(Record<?> aRecord, Header<?> aSubsetOf)
static boolean
isSupersetOf(Row<?> aRow, Header<?> aSubsetOf)
static <T> Header<T>
toHeader(java.lang.String[] aColumnKeys, ColumnFactory<T> aColumnFactory)
Creates a header for a given string array with the column names to be used for the header.static <T> Header<T>
toHeader(java.util.Collection<java.lang.String> aColumnKeys, ColumnFactory<T> aColumnFactory)
Creates a header for a given list of strings containing the column names to be used for the header.static <T> Record<T>
toIntersection(Record<T> aRecord, Header<?> aHeader)
static Record<?>
toPurged(Record<?> aRecord)
static java.lang.String
toSeparatedValues(Record<?> aRecord)
Returns a separated values representation of the implementing collection by separating each item with the default separatorDelimiter.CSV
.static java.lang.String
toSeparatedValues(Record<?> aRecord, char aDelimiter)
Returns a separated values representation of the implementing collection by separating each item with the given separator.static java.lang.String
toString(Record<?> aRecord)
Creates the string representation from from the given record.static java.lang.String
toString(Record<?> aRecord, char aSeparator, java.time.format.DateTimeFormatter[] aDateFormats)
Creates the string representation from from the given record.static <T> Record<T>
toSubset(Record<T> aRecord, Header<?> aHeader)
-
-
-
Method Detail
-
toHeader
public static <T> Header<T> toHeader(java.lang.String[] aColumnKeys, ColumnFactory<T> aColumnFactory)
Creates a header for a given string array with the column names to be used for the header. The data type of the header columns will beObject
.- Type Parameters:
T
- the generic type- Parameters:
aColumnKeys
- The column names to be use for the header.aColumnFactory
- creates column instances depending on the key passed. This is useful when special header keys are to have a dedicated type such asDate
. If null is passed then justObjectColumn
instances for type Object.class are created.- Returns:
- A header constructed from the given column names.
-
toHeader
public static <T> Header<T> toHeader(java.util.Collection<java.lang.String> aColumnKeys, ColumnFactory<T> aColumnFactory)
Creates a header for a given list of strings containing the column names to be used for the header. The data type of the header columns will beObject
.- Type Parameters:
T
- the generic type- Parameters:
aColumnKeys
- The column names to be use for the header.aColumnFactory
- creates column instances depending on the key passed. This is useful when special header keys are to have a dedicated type such asDate
. If null is passed then justObjectColumn
instances for typeObject
are created.- Returns:
- A header constructed from the given column names.
-
isSubsetOf
public static boolean isSubsetOf(Record<?> aRecord, Header<?> aSupersetOf)
Tests whether the given potential subset ofHeader
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. ------------------------------------------------------------------------- TODO: Think about moving this method to theHeader
. -------------------------------------------------------------------------- Parameters:
aRecord
- TheRecord
to be used for testing.aSupersetOf
- the superset of- Returns:
- true in case all columns in the subset match this' elements or the argument passed was null.
-
isEqualWith
public static boolean isEqualWith(Record<?> aRecord, Header<?> aEquivalsWith)
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. ------------------------------------------------------------------------- TODO: Think about moving this method to theHeader
. -------------------------------------------------------------------------- Parameters:
aRecord
- TheRecord
to be used for testing.aEquivalsWith
- The columns which all must be matched with elements of this instance.- 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
public static boolean isSupersetOf(Record<?> aRecord, Header<?> aSubsetOf)
Tests whether theRecord
's elements is matching the given potential superset ofHeader
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. ------------------------------------------------------------------------- TODO: Think about moving this method to theHeader
. -------------------------------------------------------------------------- Parameters:
aRecord
- TheRecord
to be used for testing.aSubsetOf
- the subset of- Returns:
- True in case all elements in this instance match the columns in the superset or the argument passed was null.
-
isSubsetOf
public static boolean isSubsetOf(Row<?> aRow, Header<?> aSupersetOf)
Tests whether the given potentialHeader
subset 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, even if this has more elements. ------------------------------------------------------------------------- TODO: Think about moving this method to theHeader
. ------------------------------------------------------------------------- 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.aSupersetOf
- the superset of- Returns:
- true in case all columns in the subset match this' elements or the argument passed was null.
-
isEqualWith
public static boolean isEqualWith(Row<?> aRow, Header<?> aEquivalsWith)
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. ------------------------------------------------------------------------- TODO: Think about moving this method to theHeader
. -------------------------------------------------------------------------- Parameters:
aRow
- TheRow
to be used for testing.aEquivalsWith
- The columns which all must be matched with elements of this instance.- 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
public static boolean isSupersetOf(Row<?> aRow, Header<?> aSubsetOf)
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. ------------------------------------------------------------------------- TODO: Think about moving this method to theHeader
. -------------------------------------------------------------------------- Parameters:
aRow
- TheRow
to be used for testing.aSubsetOf
- the subset of- Returns:
- True in case all elements in this instance match the columns in the superset or the argument passed was null.
-
toIntersection
public static <T> Record<T> toIntersection(Record<T> aRecord, Header<?> aHeader) throws ColumnMismatchException
Returns aRecord
just containing the keys as defined in theHeader
and found in the providedRecord
. ------------------------------------------------------------------------- TODO: Think about moving this method to theHeader
. -------------------------------------------------------------------------- Type Parameters:
T
- the generic type- Parameters:
aRecord
- TheRecord
to use.aHeader
- TheHeader
being the reference for the expected result.- Returns:
- The
Record
being a subset of the givenHeader
. - Throws:
ColumnMismatchException
- in case the type of a key defined in aColumn
does not match the type of the according value in theRecord
.
-
toSubset
public static <T> Record<T> toSubset(Record<T> aRecord, Header<?> aHeader) throws ColumnMismatchException
Returns aRecord
just containing the keys as defined in theHeader
; keys not found in the providedRecord
are ignored. ------------------------------------------------------------------------- TODO: Think about moving this method to theHeader
. -------------------------------------------------------------------------- Type Parameters:
T
- the generic type- Parameters:
aRecord
- TheRecord
to use.aHeader
- TheHeader
being the reference for the expected result.- Returns:
- The
Record
being a subset of the givenHeader
. - Throws:
ColumnMismatchException
- in case the type of a key defined in aColumn
does not match the type of the according value in theRecord
.
-
toString
public static java.lang.String toString(Record<?> aRecord)
Creates the string representation from from the given record. The key / value pairs of each item in the record are separated from each other with the assignment operator "=" and the items are separated from each other by the default CSV separator character and date objects are formatted with the default date format.- Parameters:
aRecord
- The record for which to create a string.- Returns:
- A string representation of the given record.
-
toString
public static java.lang.String toString(Record<?> aRecord, char aSeparator, java.time.format.DateTimeFormatter[] aDateFormats)
Creates the string representation from from the given record. The key / value pairs of each item in the record are separated from each other with the assignment operator "=" and the items are separated from each other by the given separator character.- Parameters:
aRecord
- The record for which to create a string.aSeparator
- The separator to separate the items (key/value-pairs) of the record from each other.aDateFormats
- The date formats to use when formatting date objects.- Returns:
- A string representation of the given record.
-
toSeparatedValues
public static java.lang.String toSeparatedValues(Record<?> aRecord)
Returns a separated values representation of the implementing collection by separating each item with the default separatorDelimiter.CSV
. The common CSV conventions are to be obeyed (although there is none CSV standard). In case a value's string representation contains the delimiter char, then this char must be escaped (i.e. by using the backslash '\').- Parameters:
aRecord
- The record from which to generate separated values.- Returns:
- The aDelimiter separated string.
-
toSeparatedValues
public static java.lang.String toSeparatedValues(Record<?> aRecord, char aDelimiter)
Returns a separated values representation of the implementing collection by separating each item with the given separator. The common CSV conventions are to be obeyed (although there is none CSV standard). In case a value's string representation contains the delimiter char, then this char must be escaped (i.e. by using the backslash '\').- Parameters:
aRecord
- The record from which to generate separated values.aDelimiter
- The delimiter to use when separating the values.- Returns:
- The aDelimiter separated string.
-
-