Class Rows
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<Rows.Row>
-
- io.inversion.utils.Rows
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<Rows.Row>,java.util.Collection<Rows.Row>,java.util.List<Rows.Row>,java.util.RandomAccess
public class Rows extends java.util.ArrayList<Rows.Row>
An utility abstraction of a database result set where all childRowobjects are themselves maps that share the same case insensitive key set.The idea is to be a little more memory efficient, offer zero base integer index or case insensitive key/column name access, and have key/column order match on all rows.
This was initially developed so that a JDBC
ResultSetcould be loaded into a list of maps without having to replicate the keys for every row.Implementation Notes:
While Row implements Map, it actually uses a List to maintain its values.
A instance of the
RowKeys, which maintains a Map from case insensitive string keys their index position in each Row's list, is shared by all Row instances.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRows.RowRepresents 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.protected static classRows.RowKeysAn ordered list of case insensitive key/column names shared by all Row instances in a Rows.
-
Constructor Summary
Constructors Constructor Description Rows()Creates an empty Rows with no keys/columns.Rows(java.lang.String[] keys)Creates a Rows with keys/columns equal tokeysRows(java.util.List<java.lang.String> keys)Creates a Rows with keys/columns equal tokeysRows(java.util.Map row)Creates a Rows with a single Row with keys/columns equal torow.getKeySet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(Rows.Row row)Adds the key/values fromrowas a new Row.booleanaddAll(int index, java.util.Collection<? extends Rows.Row> rows)Calls#addRow(int, Map)for each Row inrowsbooleanaddAll(java.util.Collection<? extends Rows.Row> rows)Calls#addRow(Map)for each Row inrowsintaddKey(java.lang.String key)Adds a key/column for each Row at the end of the iteration order.Rows.RowaddRow()Adds a new empty Row to the end of the list.Rows.RowaddRow(int index, java.lang.Object[] values)Addsvaluesas the newindexth Row.Rows.RowaddRow(int index, java.util.List values)Addsvaluesas the newindexth Row.Rows.RowaddRow(int index, java.util.Map map)Insert key/values frommapas the newindexth Row.Rows.RowaddRow(java.lang.Object[] values)Addsvaluesas a new Row to the end of the list.Rows.RowaddRow(java.util.List values)Addsvaluesas a new Row to the end of the list.Rows.RowaddRow(java.util.Map map)Adds key/values frommapto a new Row.java.util.List<java.lang.String>keyList()java.util.Set<java.lang.String>keySet()voidput(java.lang.Object value)Addsvalueto the end oflastRow.voidput(java.lang.String key, java.lang.Object value)Sets key/value onlastRow.-
Methods inherited from class java.util.ArrayList
add, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
-
-
-
Constructor Detail
-
Rows
public Rows()
Creates an empty Rows with no keys/columns.
-
Rows
public Rows(java.util.Map row)
Creates a Rows with a single Row with keys/columns equal torow.getKeySet()- Parameters:
row- key pars to add
-
Rows
public Rows(java.lang.String[] keys)
Creates a Rows with keys/columns equal tokeys- Parameters:
keys- the column names
-
Rows
public Rows(java.util.List<java.lang.String> keys)
Creates a Rows with keys/columns equal tokeys- Parameters:
keys- the column keys
-
-
Method Detail
-
keyList
public java.util.List<java.lang.String> keyList()
- Returns:
- the ordered key/column names
-
keySet
public java.util.Set<java.lang.String> keySet()
- Returns:
- key/column names as a set that preserves iteration order
-
addKey
public int addKey(java.lang.String key)
Adds a key/column for each Row at the end of the iteration order.- Parameters:
key- the new key to add- Returns:
- the integer index of key/column which will be
keys.size() -1if the key is new or the existing index if a case insensitive match ofkeyalready exited
-
addRow
public Rows.Row addRow()
Adds a new empty Row to the end of the list.- Returns:
- the new last/current row
-
addRow
public Rows.Row addRow(java.util.Map map)
Adds key/values frommapto a new Row.- Parameters:
map- the key/values to add to the new Row- Returns:
- the new last/current Row
- See Also:
addRow()
-
addRow
public Rows.Row addRow(int index, java.util.Map map)
Insert key/values frommapas the newindexth Row.If RowKeys has not been initialized, it will be initialized with
map.keySet().If RowKeys has been initialized, only keys/values with a case insensitive matching key in RowKeys will be copied into the new Row.
- Parameters:
index- the position to insert the new Row or -1 to indicate the 'at the end'map- the key/values to add to the new Row- Returns:
- the new last/current Row
- See Also:
addRow(int, Object[])
-
addRow
public Rows.Row addRow(java.util.List values)
Addsvaluesas a new Row to the end of the list.- Parameters:
values- the values to add to the new Row- Returns:
- the new last/current Row
- See Also:
addRow(int, Object[])
-
addRow
public Rows.Row addRow(int index, java.util.List values)
Addsvaluesas the newindexth Row.- Parameters:
index- the position to insert the new Row or -1 to indicate the 'at the end'values- the values to add to the new Row- Returns:
- the new last/current Row
- See Also:
addRow(int, Object[])
-
addRow
public Rows.Row addRow(java.lang.Object[] values)
Addsvaluesas a new Row to the end of the list.- Parameters:
values- the values to add to the new Row- Returns:
- the new last/current Row
- See Also:
addRow(int, Object[])
-
addRow
public Rows.Row addRow(int index, java.lang.Object[] values)
Addsvaluesas the newindexth Row.The returned Row becomes
lastRow- Parameters:
index- the position to insert the new Row or -1 to indicate the 'at the end'values- the values to add to the new Row- Returns:
- the new last/current Row
- See Also:
addRow(int, Object[])
-
put
public void put(java.lang.String key, java.lang.Object value)Sets key/value onlastRow.If RowKeys does not have a case insensitive match for
keythenkeyautomatically becomes the new last column for all rows.- Parameters:
key- the row keyvalue- the value to store
-
put
public void put(java.lang.Object value)
Addsvalueto the end oflastRow.- Parameters:
value- the value to store
-
add
public boolean add(Rows.Row row)
Adds the key/values fromrowas a new Row.The actual Row object is not added to the Rows list because its RowKeys object will not be the same. Instead all key/values are copied into a new Row.
- Specified by:
addin interfacejava.util.Collection<Rows.Row>- Specified by:
addin interfacejava.util.List<Rows.Row>- Overrides:
addin classjava.util.ArrayList<Rows.Row>- Parameters:
row- a map containing the key/values to add- See Also:
addRow(Map)
-
addAll
public boolean addAll(java.util.Collection<? extends Rows.Row> rows)
Calls#addRow(Map)for each Row inrows
-
-