Class 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)
      Tests whether the given potential equal set of Header is matching the Record's elements in terms of matching the same relevant attributes of the columns with the elements in the Record.
      static boolean isEqualWith​(Row<?> aRow, Header<?> aEquivalsWith)
      Tests whether the given potential Header equal set is matching the Row's elements in terms of matching the same relevant attributes of the Header with the elements in the Row.
      static boolean isSubsetOf​(Record<?> aRecord, Header<?> aSupersetOf)
      Tests whether the given potential subset of Header is matching the Record's elements in terms of matching the same relevant attributes of the Column instances with the elements in the Record.
      static boolean isSubsetOf​(Row<?> aRow, Header<?> aSupersetOf)
      Tests whether the given potential Header subset is matching the Row's elements in terms of matching the same relevant attributes of the Header with the elements in the Row.
      static boolean isSupersetOf​(Record<?> aRecord, Header<?> aSubsetOf)
      Tests whether the Record's elements is matching the given potential superset of Header in terms of matching the same relevant attributes of the columns with the elements in the Record.
      static boolean isSupersetOf​(Row<?> aRow, Header<?> aSubsetOf)
      Tests whether the Row's elements is matching the given potential Header superset in terms of matching the same relevant attributes of the Header with the elements in the Row.
      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)
      Returns a Record just containing the keys as defined in the Header and found in the provided Record. ------------------------------------------------------------------------- TODO: Think about moving this method to the Header.
      static Record<?> toPurged​(Record<?> aRecord)
      The given Record is taken and only all non null values are taken for the returned Record.
      static java.lang.String toSeparatedValues​(Record<?> aRecord)
      Returns a separated values representation of the implementing collection by separating each item with the default separator Delimiter.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)
      Returns a Record just containing the keys as defined in the Header; keys not found in the provided Record are ignored. ------------------------------------------------------------------------- TODO: Think about moving this method to the Header.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 be Object.
        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 as Date. If null is passed then just ObjectColumn 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 be Object.
        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 as Date. If null is passed then just ObjectColumn instances for type Object are created.
        Returns:
        A header constructed from the given column names.
      • toPurged

        public static Record<?> toPurged​(Record<?> aRecord)
        The given Record is taken and only all non null values are taken for the returned Record. In case of string objects, only String instances with a length greater than zero are taken into account for the returned Record.
        Parameters:
        aRecord - The Record as input.
        Returns:
        The output Record without any keys which's values were null or in case of strings which's length was zero.
      • isSubsetOf

        public static boolean isSubsetOf​(Record<?> aRecord,
                                         Header<?> aSupersetOf)
        Tests whether the given potential subset of Header is matching the Record's elements in terms of matching the same relevant attributes of the Column instances with the elements in the Record. I.e. all Column 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 the Record do not match the according key's type in the Header Column instance or vice versa. ------------------------------------------------------------------------- TODO: Think about moving this method to the Header. -------------------------------------------------------------------------
        Parameters:
        aRecord - The Record 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 of Header is matching the Record's elements in terms of matching the same relevant attributes of the columns with the elements in the Record. I.e. all Header in the subset must match the elements, and the number of Header must be the same as the number of elements in the Record. The test also fails (returns false) in case the types of the instances in the Record do not match the according key's type in the Header Column instance or vice versa. ------------------------------------------------------------------------- TODO: Think about moving this method to the Header. -------------------------------------------------------------------------
        Parameters:
        aRecord - The Record 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 the Record's elements is matching the given potential superset of Header in terms of matching the same relevant attributes of the columns with the elements in the Record. I.e. all elements in the Record must match the Header in the superset, even if the superset has more elements. The test also fails (returns false) in case the types of the instances in the Record do not match the according key's type in the Header Column instance or vice versa. ------------------------------------------------------------------------- TODO: Think about moving this method to the Header. -------------------------------------------------------------------------
        Parameters:
        aRecord - The Record 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 potential Header subset is matching the Row's elements in terms of matching the same relevant attributes of the Header with the elements in the Row. I.e. all Column instances in the subset must match the elements, even if this has more elements. ------------------------------------------------------------------------- TODO: Think about moving this method to the Header. ------------------------------------------------------------------------- The test also fails (returns false) in case the types of the instances in the Row do not match the according key's type in the Header Column instance or vice versa.
        Parameters:
        aRow - The Row 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 potential Header equal set is matching the Row's elements in terms of matching the same relevant attributes of the Header with the elements in the Row. I.e. all Column instances in the subset must match the elements, and the number of columns must be the same as the number of elements in the Row. The test also fails (returns false) in case the types of the instances in the Row do not match the according key's type in the Header Column instance or vice versa. ------------------------------------------------------------------------- TODO: Think about moving this method to the Header. -------------------------------------------------------------------------
        Parameters:
        aRow - The Row 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 the Row's elements is matching the given potential Header superset in terms of matching the same relevant attributes of the Header with the elements in the Row. I.e. all elements in the Row must match the Column 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 the Row do not match the according key's type in the Header Column instance or vice versa. ------------------------------------------------------------------------- TODO: Think about moving this method to the Header. -------------------------------------------------------------------------
        Parameters:
        aRow - The Row 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 a Record just containing the keys as defined in the Header and found in the provided Record. ------------------------------------------------------------------------- TODO: Think about moving this method to the Header. -------------------------------------------------------------------------
        Type Parameters:
        T - the generic type
        Parameters:
        aRecord - The Record to use.
        aHeader - The Header being the reference for the expected result.
        Returns:
        The Record being a subset of the given Header.
        Throws:
        ColumnMismatchException - in case the type of a key defined in a Column does not match the type of the according value in the Record.
      • toSubset

        public static <T> Record<T> toSubset​(Record<T> aRecord,
                                             Header<?> aHeader)
                                      throws ColumnMismatchException
        Returns a Record just containing the keys as defined in the Header; keys not found in the provided Record are ignored. ------------------------------------------------------------------------- TODO: Think about moving this method to the Header. -------------------------------------------------------------------------
        Type Parameters:
        T - the generic type
        Parameters:
        aRecord - The Record to use.
        aHeader - The Header being the reference for the expected result.
        Returns:
        The Record being a subset of the given Header.
        Throws:
        ColumnMismatchException - in case the type of a key defined in a Column does not match the type of the according value in the Record.
      • 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 separator Delimiter.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.