Class Rows
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Rows.Row>,Collection<Rows.Row>,List<Rows.Row>,RandomAccess
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.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents 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 classAn ordered list of case insensitive key/column names shared by all Row instances in a Rows. -
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionRows()Creates an empty Rows with no keys/columns.Creates a Rows with keys/columns equal tokeysCreates a Rows with keys/columns equal tokeysCreates a Rows with a single Row with keys/columns equal torow.getKeySet() -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds the key/values fromrowas a new Row.booleanaddAll(int index, Collection<? extends Rows.Row> rows) Calls#addRow(int, Map)for each Row inrowsbooleanaddAll(Collection<? extends Rows.Row> rows) Calls#addRow(Map)for each Row inrowsintAdds a key/column for each Row at the end of the iteration order.addRow()Adds a new empty Row to the end of the list.Addsvaluesas the newindexth Row.Addsvaluesas the newindexth Row.Insert key/values frommapas the newindexth Row.Addsvaluesas a new Row to the end of the list.Addsvaluesas a new Row to the end of the list.Adds key/values frommapto a new Row.keyList()keySet()voidAddsvalueto the end oflastRow.voidSets 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, trimToSizeMethods inherited from class java.util.AbstractCollection
containsAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.List
containsAll
-
Constructor Details
-
Rows
public Rows()Creates an empty Rows with no keys/columns. -
Rows
Creates a Rows with a single Row with keys/columns equal torow.getKeySet()- Parameters:
row- key pars to add
-
Rows
Creates a Rows with keys/columns equal tokeys- Parameters:
keys- the column names
-
Rows
Creates a Rows with keys/columns equal tokeys- Parameters:
keys- the column keys
-
-
Method Details
-
keyList
- Returns:
- the ordered key/column names
-
keySet
- Returns:
- key/column names as a set that preserves iteration order
-
addKey
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
Adds a new empty Row to the end of the list.- Returns:
- the new last/current row
-
addRow
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
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
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
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
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
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:
-
put
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
Addsvalueto the end oflastRow.- Parameters:
value- the value to store
-
add
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.
-
addAll
Calls#addRow(Map)for each Row inrows -
addAll
Calls#addRow(int, Map)for each Row inrows
-