Class Rows.Row

  • All Implemented Interfaces:
    java.util.Map<java.lang.String,​java.lang.Object>
    Enclosing class:
    Rows

    public static class Rows.Row
    extends java.lang.Object
    implements java.util.Map<java.lang.String,​java.lang.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.

    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      Row()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.lang.Object value)
      Adds value as the last column
      java.util.List<java.lang.Object> asList()  
      void clear()
      Sets all values to null, but does not modify RowKeys or change the length of values.
      boolean containsKey​(java.lang.Object key)  
      boolean containsValue​(java.lang.Object value)  
      java.util.Set<java.util.Map.Entry<java.lang.String,​java.lang.Object>> entrySet()  
      java.lang.Object get​(int index)  
      java.lang.Object get​(java.lang.Object keyOrIndex)  
      java.lang.Object get​(java.lang.String key)
      Gets the value for the key/column.
      boolean getBoolean​(int index)  
      boolean getBoolean​(java.lang.String key)  
      float getFloat​(int index)  
      float getFloat​(java.lang.String key)  
      int getInt​(int index)  
      int getInt​(java.lang.String key)  
      java.lang.String getKey​(int index)  
      long getLong​(int index)  
      long getLong​(java.lang.String key)  
      java.lang.String getString​(int index)  
      java.lang.String getString​(java.lang.String key)  
      int indexOf​(java.lang.String key)  
      boolean isEmpty()  
      java.util.Set<java.lang.String> keySet()  
      java.lang.Object put​(java.lang.String key, java.lang.Object value)
      Translates key into a column index and inserts value at that index.
      void putAll​(java.util.Map<? extends java.lang.String,​? extends java.lang.Object> m)  
      java.lang.Object remove​(java.lang.Object key)
      Sets the value for keyOrIndex to null.
      void set​(int index, java.lang.Object value)
      Sets the indexth column to value
      int size()  
      java.lang.String toString()  
      java.util.Collection<java.lang.Object> values()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Constructor Detail

      • Row

        public Row()
    • Method Detail

      • getKey

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

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

        public java.lang.String getString​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<java.lang.String,​java.lang.Object>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<java.lang.String,​java.lang.Object>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<java.lang.String,​java.lang.Object>
      • indexOf

        public int indexOf​(java.lang.String key)
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<java.lang.String,​java.lang.Object>
      • get

        public java.lang.Object get​(java.lang.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 java.lang.Object get​(int index)
                             throws java.lang.ArrayIndexOutOfBoundsException
        Parameters:
        index - the column number to get
        Returns:
        the value at index
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if index is >= values.length()
      • get

        public java.lang.Object get​(java.lang.Object keyOrIndex)
        Specified by:
        get in interface java.util.Map<java.lang.String,​java.lang.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,
                        java.lang.Object value)
        Sets the indexth column to value
        Parameters:
        index - the column number to set
        value - the value to set
      • add

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

        public java.lang.Object put​(java.lang.String key,
                                    java.lang.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 java.util.Map<java.lang.String,​java.lang.Object>
        Parameters:
        key - the column name to set
        value - the column value to set
      • remove

        public java.lang.Object remove​(java.lang.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 java.util.Map<java.lang.String,​java.lang.Object>
        Parameters:
        key - the String key or an Integer index to remove.
        Returns:
        the previous value for the column
      • putAll

        public void putAll​(java.util.Map<? extends java.lang.String,​? extends java.lang.Object> m)
        Specified by:
        putAll in interface java.util.Map<java.lang.String,​java.lang.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 java.util.Map<java.lang.String,​java.lang.Object>
      • keySet

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

        public java.util.Collection<java.lang.Object> values()
        Specified by:
        values in interface java.util.Map<java.lang.String,​java.lang.Object>
      • asList

        public java.util.List<java.lang.Object> asList()
      • entrySet

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