public class Rows extends java.util.ArrayList<Rows.Row>
Row objects 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 ResultSet could 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.
| Modifier and Type | Class and Description |
|---|---|
static class |
Rows.Row
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.
|
protected static class |
Rows.RowKeys
An ordered list of case insensitive key/column names shared by all Row instances in a Rows.
|
| Constructor and Description |
|---|
Rows()
Creates an empty Rows with no keys/columns.
|
Rows(java.util.List<java.lang.String> keys)
Creates a Rows with keys/columns equal to
keys |
Rows(java.util.Map row)
Creates a Rows with a single Row with keys/columns equal to
row.getKeySet() |
Rows(java.lang.String[] keys)
Creates a Rows with keys/columns equal to
keys |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(Rows.Row row)
Adds the key/values from
row as a new Row. |
boolean |
addAll(java.util.Collection<? extends Rows.Row> rows)
Calls
#addRow(Map) for each Row in rows |
boolean |
addAll(int index,
java.util.Collection<? extends Rows.Row> rows)
Calls
#addRow(int, Map) for each Row in rows |
int |
addKey(java.lang.String key)
Adds a key/column for each Row at the end of the iteration order.
|
Rows.Row |
addRow()
Adds a new empty Row to the end of the list.
|
Rows.Row |
addRow(int index,
java.util.List values)
Adds
values as the new indexth Row. |
Rows.Row |
addRow(int index,
java.util.Map map)
Insert key/values from
map as the new indexth Row. |
Rows.Row |
addRow(int index,
java.lang.Object[] values)
Adds
values as the new indexth Row. |
Rows.Row |
addRow(java.util.List values)
Adds
valuesas a new Row to the end of the list. |
Rows.Row |
addRow(java.util.Map map)
Adds key/values from
map to a new Row. |
Rows.Row |
addRow(java.lang.Object[] values)
Adds
valuesas a new Row to the end of the list. |
java.util.List<java.lang.String> |
keyList() |
java.util.Set<java.lang.String> |
keySet() |
void |
put(java.lang.Object value)
Adds
value to the end of lastRow. |
void |
put(java.lang.String key,
java.lang.Object value)
Sets key/value on
lastRow. |
add, clear, clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSizepublic Rows()
public Rows(java.util.Map row)
row.getKeySet()row - key pars to addpublic Rows(java.lang.String[] keys)
keyskeys - the column namespublic Rows(java.util.List<java.lang.String> keys)
keyskeys - the column keyspublic java.util.List<java.lang.String> keyList()
public java.util.Set<java.lang.String> keySet()
public int addKey(java.lang.String key)
key - the new key to addkeys.size() -1 if the key is new or the existing index if a case insensitive match of key already exitedpublic Rows.Row addRow()
public Rows.Row addRow(java.util.Map map)
map to a new Row.map - the key/values to add to the new RowaddRow()public Rows.Row addRow(int index, java.util.Map map)
map as the new indexth 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.
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 RowaddRow(int, Object[])public Rows.Row addRow(java.util.List values)
valuesas a new Row to the end of the list.values - the values to add to the new RowaddRow(int, Object[])public Rows.Row addRow(int index, java.util.List values)
values as the new indexth Row.index - the position to insert the new Row or -1 to indicate the 'at the end'values - the values to add to the new RowaddRow(int, Object[])public Rows.Row addRow(java.lang.Object[] values)
valuesas a new Row to the end of the list.values - the values to add to the new RowaddRow(int, Object[])public Rows.Row addRow(int index, java.lang.Object[] values)
values as the new indexth Row.
The returned Row becomes lastRow
index - the position to insert the new Row or -1 to indicate the 'at the end'values - the values to add to the new RowaddRow(int, Object[])public void put(java.lang.String key,
java.lang.Object value)
lastRow.
If RowKeys does not have a case insensitive match for key then key
automatically becomes the new last column for all rows.
key - the row keyvalue - the value to storepublic void put(java.lang.Object value)
value to the end of lastRow.value - the value to storepublic boolean add(Rows.Row row)
row as 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.
add in interface java.util.Collection<Rows.Row>add in interface java.util.List<Rows.Row>add in class java.util.ArrayList<Rows.Row>row - a map containing the key/values to addaddRow(Map)public boolean addAll(java.util.Collection<? extends Rows.Row> rows)
#addRow(Map) for each Row in rowsCopyright © 2021 Rocket Partners, LLC. All rights reserved.