Interface Header<T>

Type Parameters:
T - The type managed by the Header.
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 of Column instances, for example describing the elements of a CSV file (visually speaking the of the CSV file's header line), is represented by the Header. The Header preserves an order for a list of Column instances. A Header provides the semantics for related Row instances.

The Keys.keySet() method must provide a predictable order as ensured by the LinkedHashSet class as of the ordered nature of the Header.

  • Method Details

    • get

      default T get(Row<T> aRow, String aKey) throws HeaderMismatchException, ColumnMismatchException
      This method retrieves a value from the Row by taking the index of the according column of this Header 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 to Row.get(Header, String).
      Parameters:
      aRow - The Row 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 given HeaderMismatchException and the Row, 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 the Header.
      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 the Header 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 the Record in the order as defined by the header.
      Parameters:
      aRecord - The Record to be converted to an array of values.
      Returns:
      The array of values.
    • toType

      default Class<T> toType()
      Determines the least common denominator type by evaluating the Column instances contained within this Header.
      Returns:
      Determines the lest common denominator type or null (in case there are no Column instances in the Header).
    • isSubsetOf

      default boolean isSubsetOf(Record<?> aRecord)
      Tests whether the given potential subset of Header elements 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.
      Parameters:
      aRecord - The Record 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 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.
      Parameters:
      aRecord - The Record 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 the Record's elements is matching the given potential superset of Header elements 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.
      Parameters:
      aRecord - The Record 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 this Header is a subset of 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. 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.
      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 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.
      Parameters:
      aRow - The Row 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 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.
      Parameters:
      aRow - The Row 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
      Returns a Record just containing the keys as defined in the Header and found in the provided Record.
      Type Parameters:
      REC - the generic type
      Parameters:
      aRecord - The Record to use.
      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

      default <REC> Record<REC> toSubset(Record<REC> aRecord) throws ColumnMismatchException
      Returns a Record just containing the keys as defined in the Header; keys not found in the provided Record are ignored.
      Type Parameters:
      REC - the generic type
      Parameters:
      aRecord - The Record to use.
      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.