Package org.refcodes.tabular
Class TabularUtility
- java.lang.Object
-
- org.refcodes.tabular.TabularUtility
-
public final class TabularUtility extends java.lang.ObjectUtility for listing specific functionality.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisEqualWith(Record<?> aRecord, Header<?> aEquivalsWith)static booleanisEqualWith(Row<?> aRow, Header<?> aEquivalsWith)static booleanisSubsetOf(Record<?> aRecord, Header<?> aSupersetOf)static booleanisSubsetOf(Row<?> aRow, Header<?> aSupersetOf)static booleanisSupersetOf(Record<?> aRecord, Header<?> aSubsetOf)static booleanisSupersetOf(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.StringtoSeparatedValues(Record<?> aRecord)Returns a separated values representation of the implementing collection by separating each item with the default separatorDelimiter.CSV.static java.lang.StringtoSeparatedValues(Record<?> aRecord, char aDelimiter)Returns a separated values representation of the implementing collection by separating each item with the given separator.static java.lang.StringtoString(Record<?> aRecord)Creates the string representation from from the given record.static java.lang.StringtoString(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 justColumnImplinstances 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 justColumnImplinstances for typeObjectare 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 ofHeaderis matching theRecord's elements in terms of matching the same relevant attributes of theColumninstances with the elements in theRecord. I.e. allColumninstances 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 theRecorddo not match the according key's type in theHeaderColumninstance or vice versa. ------------------------------------------------------------------------- TODO: Think about moving this method to theHeader. -------------------------------------------------------------------------- Parameters:
aRecord- TheRecordto 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 ofHeaderis matching theRecord's elements in terms of matching the same relevant attributes of the columns with the elements in theRecord. I.e. allHeaderin the subset must match the elements, and the number ofHeadermust be the same as the number of elements in theRecord. The test also fails (returns false) in case the types of the instances in theRecorddo not match the according key's type in theHeaderColumninstance or vice versa. ------------------------------------------------------------------------- TODO: Think about moving this method to theHeader. -------------------------------------------------------------------------- Parameters:
aRecord- TheRecordto 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 ofHeaderin terms of matching the same relevant attributes of the columns with the elements in theRecord. I.e. all elements in theRecordmust match theHeaderin the superset, even if the superset has more elements. The test also fails (returns false) in case the types of the instances in theRecorddo not match the according key's type in theHeaderColumninstance or vice versa. ------------------------------------------------------------------------- TODO: Think about moving this method to theHeader. -------------------------------------------------------------------------- Parameters:
aRecord- TheRecordto 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 potentialHeadersubset is matching theRow's elements in terms of matching the same relevant attributes of theHeaderwith the elements in theRow. I.e. allColumninstances 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 theRowdo not match the according key's type in theHeaderColumninstance or vice versa.- Parameters:
aRow- TheRowto 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 potentialHeaderequal set is matching theRow's elements in terms of matching the same relevant attributes of theHeaderwith the elements in theRow. I.e. allColumninstances 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 theRowdo not match the according key's type in theHeaderColumninstance or vice versa. ------------------------------------------------------------------------- TODO: Think about moving this method to theHeader. -------------------------------------------------------------------------- Parameters:
aRow- TheRowto 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 potentialHeadersuperset in terms of matching the same relevant attributes of theHeaderwith the elements in theRow. I.e. all elements in theRowmust match theColumninstances in the superset, even if the superset has more elements. The test also fails (returns false) in case the types of the instances in theRowdo not match the according key's type in theHeaderColumninstance or vice versa. ------------------------------------------------------------------------- TODO: Think about moving this method to theHeader. -------------------------------------------------------------------------- Parameters:
aRow- TheRowto 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 aRecordjust containing the keys as defined in theHeaderand found in the providedRecord. ------------------------------------------------------------------------- TODO: Think about moving this method to theHeader. -------------------------------------------------------------------------- Type Parameters:
T- the generic type- Parameters:
aRecord- TheRecordto use.aHeader- TheHeaderbeing the reference for the expected result.- Returns:
- The
Recordbeing a subset of the givenHeader. - Throws:
ColumnMismatchException- in case the type of a key defined in aColumndoes 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 aRecordjust containing the keys as defined in theHeader; keys not found in the providedRecordare ignored. ------------------------------------------------------------------------- TODO: Think about moving this method to theHeader. -------------------------------------------------------------------------- Type Parameters:
T- the generic type- Parameters:
aRecord- TheRecordto use.aHeader- TheHeaderbeing the reference for the expected result.- Returns:
- The
Recordbeing a subset of the givenHeader. - Throws:
ColumnMismatchException- in case the type of a key defined in aColumndoes 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.
-
-