Class Rows.Row

java.lang.Object
io.inversion.utils.Rows.Row
All Implemented Interfaces:
Map<String,Object>
Enclosing class:
Rows

public static class Rows.Row extends Object implements Map<String,Object>
Represents a single row in a database result set where values can be accessed by a zero based integer index or by a case insensitive key/column name.

It is not possible to implement both List and Map but that is the practical purpose of this class.

  • Constructor Details

    • Row

      public Row()
  • Method Details

    • getKey

      public String getKey(int index)
      Parameters:
      index - the column key to get
      Returns:
      the key/column name for the given index
    • getString

      public String getString(int index)
      Parameters:
      index - the column number to get
      Returns:
      the value at index stringified if it exists
    • getString

      public String getString(String key)
      Parameters:
      key - the column name to get
      Returns:
      the value for key stringified if it exists
    • getInt

      public int getInt(int index)
      Parameters:
      index - the column number to get
      Returns:
      the value at index stringified and parsed as an int if it exists
    • getInt

      public int getInt(String key)
      Parameters:
      key - the column name to get
      Returns:
      the value for key stringified and parsed as an int if it exists
    • getLong

      public long getLong(int index)
      Parameters:
      index - the column value to get
      Returns:
      the value at index stringified and parsed as a long if it exists
    • getLong

      public long getLong(String key)
      Parameters:
      key - the columnn name to get
      Returns:
      the value for key stringified and parsed as a long if it exists
    • getFloat

      public float getFloat(int index)
      Parameters:
      index - the column number to get
      Returns:
      the value at index stringified and parsed as a float if it exists
    • getFloat

      public float getFloat(String key)
      Parameters:
      key - the column name to get
      Returns:
      the value for key stringified and parsed as a float if it exists
    • getBoolean

      public boolean getBoolean(int index)
      Parameters:
      index - the column number to get
      Returns:
      the value at index stringified and parsed as a boolean if it exists
    • getBoolean

      public boolean getBoolean(String key)
      Parameters:
      key - the key of the value to get
      Returns:
      the value for key stringified and parsed as a boolean if it exists
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • size

      public int size()
      Specified by:
      size in interface Map<String,Object>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<String,Object>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<String,Object>
    • indexOf

      public int indexOf(String key)
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<String,Object>
    • get

      public Object get(String key)
      Gets the value for the key/column.
      Parameters:
      key - the column name to get
      Returns:
      the value at the index associate with key if it exists, otherwise null.
    • get

      public Object get(int index) throws ArrayIndexOutOfBoundsException
      Parameters:
      index - the column number to get
      Returns:
      the value at index
      Throws:
      ArrayIndexOutOfBoundsException - if index is >= values.length()
    • get

      public Object get(Object keyOrIndex)
      Specified by:
      get in interface Map<String,Object>
      Parameters:
      keyOrIndex - the String key or an Integer index to retrieve
      Returns:
      the value at keyOrIndex as an Integer index or the value for keyOrIndex as a String key
    • set

      public void set(int index, Object value)
      Sets the indexth column to value
      Parameters:
      index - the column number to set
      value - the value to set
    • add

      public void add(Object value)
      Adds value as the last column
      Parameters:
      value - the value to add
    • put

      public Object put(String key, Object value)
      Translates key into a column index and inserts value at that index.

      If key does not exists, it is add to the shared RowKeys as the last column.

      Specified by:
      put in interface Map<String,Object>
      Parameters:
      key - the column name to set
      value - the column value to set
    • remove

      public Object remove(Object key)
      Sets the value for keyOrIndex to null.

      It does not actually remove the key from RowKeys or remove the Row list element because RowKeys is shared across all Row instances and the iteration order and number of keys/columns needs to be the same for all of them.

      Specified by:
      remove in interface Map<String,Object>
      Parameters:
      key - the String key or an Integer index to remove.
      Returns:
      the previous value for the column
    • putAll

      public void putAll(Map<? extends String,? extends Object> m)
      Specified by:
      putAll in interface Map<String,Object>
    • clear

      public void clear()
      Sets all values to null, but does not modify RowKeys or change the length of values.
      Specified by:
      clear in interface Map<String,Object>
    • keySet

      public Set<String> keySet()
      Specified by:
      keySet in interface Map<String,Object>
      Returns:
      the RowKeys keySet which is common to all Row instances in this Rows.
      See Also:
      • Rows.RowKeys.keySet()
    • values

      public Collection<Object> values()
      Specified by:
      values in interface Map<String,Object>
    • asList

      public List<Object> asList()
    • entrySet

      public Set<Map.Entry<String,Object>> entrySet()
      Specified by:
      entrySet in interface Map<String,Object>
      Returns:
      a new LinkedHashSet of key/value pairs preserving column iteration order.