Interface Tuple

All Superinterfaces:
Iterable<Object>
All Known Subinterfaces:
SqlRow

public interface Tuple extends Iterable<Object>
Tuple represents an arbitrary set of columns whose values are accessible by column name. Column name arguments passed to the tuple methods must use SQL-parser style notation; e.g., "myColumn" - column named "MYCOLUMN", "\"MyColumn\"" - "MyColumn", etc.

Note: "\"MYCOLUMN\"" is equivalent to a normalized name "MYCOLUMN".

Provides a specialized method for some value-types to avoid boxing/unboxing.

  • Method Details

    • create

      static Tuple create()
      Creates a tuple.
      Returns:
      A new tuple.
    • create

      static Tuple create(int capacity)
      Creates a tuple with a specified initial capacity.
      Parameters:
      capacity - Initial capacity.
      Returns:
      A new tuple.
    • create

      static Tuple create(Map<String,Object> map)
      Creates a tuple from a given mapping.
      Parameters:
      map - Column values.
      Returns:
      A new tuple.
    • copy

      static Tuple copy(Tuple tuple)
      Creates a tuple copy.
      Parameters:
      tuple - Tuple to copy.
      Returns:
      A new tuple.
    • hashCode

      static int hashCode(Tuple tuple)
      Returns a hash code value for the tuple.

      The hash code of a tuple is the sum of the hash codes of each pair of column name and column value. Therefore, m1.equals(m2) implies that m1.hashCode()==m2.hashCode() for any tuples m1 and m2, as required by the general contract of Object.hashCode().

      The hash code of a pair of column name and column value i is:

      (columnName(i).hashCode()) ^ (value(i)==null ? 0 : value(i).hashCode())
      Parameters:
      tuple - Tuple.
      Returns:
      The hash code value for the tuple.
    • hashCode

      int hashCode()
      Returns a hash code value for the tuple.
      Overrides:
      hashCode in class Object
      Returns:
      The hash code value for the tuple.
      See Also:
    • equals

      static boolean equals(Tuple firstTuple, Tuple secondTuple)
      Compares tuples for equality.

      Returns true if both tuples represent the same column name-to-value mapping.

      This implementation first checks if both tuples is of same size. If not, it returns false. If yes, it iterates over columns of the first tuple and checks that the second tuple contains each mapping that the first one contains. If the second tuple fails to contain such a mapping, false is returned. If the iteration completes, true is returned.

      Parameters:
      firstTuple - First tuple to compare.
      secondTuple - Second tuple to compare.
      Returns:
      true if the first tuple is equal to the second tuple.
    • equals

      boolean equals(Object obj)
      Indicates whether another object is "equal to" the specified one.
      Overrides:
      equals in class Object
      Returns:
      true if this object is the same as the specified one; false otherwise.
      See Also:
    • columnCount

      int columnCount()
      Gets a number of columns in the tuple.
      Returns:
      Number of columns.
    • columnName

      String columnName(int columnIndex)
      Gets a name of the column with the specified index.
      Parameters:
      columnIndex - Column index.
      Returns:
      Normalized column name in SQL-parser style notation; e.g.,
      "\"MyColumn\"" - quoted value for a name of the column with respect to case sensitivity, "MYCOLUMN" - column name in uppercase, otherwise.
      Throws:
      IndexOutOfBoundsException - If a value for a column with the given index doesn't exists.
    • columnIndex

      int columnIndex(String columnName)
      Gets an index of the column with the specified name.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column index, or -1 if the column with the given name is not present.
    • valueOrDefault

      @Nullable <T> T valueOrDefault(String columnName, @Nullable T defaultValue)
      Gets a column value if the column with the specified name is present in the tuple; returns a default value otherwise.
      Type Parameters:
      T - Default value type.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      defaultValue - Default value.
      Returns:
      Column value if the tuple contains a column with the specified name. Otherwise, defaultValue.
    • set

      Tuple set(String columnName, @Nullable @Nullable Object value)
      Sets a column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      value - Value to set.
      Returns:
      this for chaining.
    • value

      @Nullable <T> T value(String columnName) throws IllegalArgumentException
      Gets a column value for the given column name.
      Type Parameters:
      T - Value type.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with the given name exists.
    • value

      @Nullable <T> T value(int columnIndex)
      Gets a column value for the given column index.
      Type Parameters:
      T - Value type.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the given index exists.
    • booleanValue

      boolean booleanValue(String columnName)
      Gets a boolean column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with given name exists.
    • booleanValue

      boolean booleanValue(int columnIndex)
      Gets boolean column value.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the given index exists.
    • byteValue

      byte byteValue(String columnName)
      Gets a byte column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with given name exists.
    • byteValue

      byte byteValue(int columnIndex)
      Gets byte column value.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the given index exists.
    • shortValue

      short shortValue(String columnName)
      Gets a short column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with the given name exists.
    • shortValue

      short shortValue(int columnIndex)
      Gets a short column value.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the given index exists.
    • intValue

      int intValue(String columnName)
      Gets a int column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with the given name exists.
    • intValue

      int intValue(int columnIndex)
      Gets a int column value.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the given index exists.
    • longValue

      long longValue(String columnName)
      Gets a long column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with the given name exists.
    • longValue

      long longValue(int columnIndex)
      Gets a long column value.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the given index exists.
    • floatValue

      float floatValue(String columnName)
      Gets a float column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with the given name exists.
    • floatValue

      float floatValue(int columnIndex)
      Gets a float column value.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the given index exists.
    • doubleValue

      double doubleValue(String columnName)
      Gets a double column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with the given name exists.
    • doubleValue

      double doubleValue(int columnIndex)
      Gets a double column value.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the given index exists.
    • decimalValue

      BigDecimal decimalValue(String columnName)
      Gets a BigDecimal column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with the given name exists.
    • decimalValue

      BigDecimal decimalValue(int columnIndex)
      Gets a BigDecimal column value.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the given index exists.
    • stringValue

      String stringValue(String columnName)
      Gets a String column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with the given name exists.
    • stringValue

      String stringValue(int columnIndex)
      Gets a String column value.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the given index exists.
    • bytesValue

      byte[] bytesValue(String columnName)
      Gets a byte[] column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with the given name exists.
    • bytesValue

      byte[] bytesValue(int columnIndex)
      Gets a byte[] column value.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the given index exists.
    • uuidValue

      UUID uuidValue(String columnName)
      Gets a UUID column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with the given name exists.
    • uuidValue

      UUID uuidValue(int columnIndex)
      Gets a UUID column value.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the given index exists.
    • dateValue

      LocalDate dateValue(String columnName)
      Gets a LocalDate column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with the given name exists.
    • dateValue

      LocalDate dateValue(int columnIndex)
      Gets a LocalDate column value.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the given index exists.
    • timeValue

      LocalTime timeValue(String columnName)
      Gets a LocalTime column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with the given name exists.
    • timeValue

      LocalTime timeValue(int columnIndex)
      Gets a LocalTime column value.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the given index exists.
    • datetimeValue

      LocalDateTime datetimeValue(String columnName)
      Gets a LocalDateTime column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with the given name exists.
    • datetimeValue

      LocalDateTime datetimeValue(int columnIndex)
      Gets a LocalDateTime column value.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the iven index exists.
    • timestampValue

      Instant timestampValue(String columnName)
      Gets a Instant column value.
      Parameters:
      columnName - Column name in SQL-parser style notation; e.g.,
      "myColumn" - "MYCOLUMN", returns the index of the column ignores case sensitivity,
      "\"MyColumn\"" - "MyColumn", returns the index of the column with respect to case sensitivity.
      Returns:
      Column value.
      Throws:
      IllegalArgumentException - If no column with the given name exists.
    • timestampValue

      Instant timestampValue(int columnIndex)
      Gets a Instant column value.
      Parameters:
      columnIndex - Column index.
      Returns:
      Column value.
      Throws:
      IndexOutOfBoundsException - If no column with the given index exists.
    • iterator

      default Iterator<Object> iterator()
      Specified by:
      iterator in interface Iterable<Object>