public final class ListWithDefault extends Object
A wrapper for List which automatically grows the list when either get(int) or
getAt(int) is called with an index greater than or equal to size().
| Type | Name and description |
|---|---|
boolean |
add(Object t) |
void |
add(int i, Object t) |
boolean |
addAll(Collection ts) |
boolean |
addAll(int i, Collection ts) |
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection objects) |
boolean |
equals(Object obj) |
Object |
get(int index)Returns the element at the given index but grows the list if needed. |
Object |
getAt(int index)Overwrites subscript operator handling by redirecting to get(int). |
List |
getDelegate() |
Closure |
getInitClosure() |
int |
hashCode() |
int |
indexOf(Object o) |
boolean |
isEmpty() |
boolean |
isLazyDefaultValues() |
Iterator |
iterator() |
int |
lastIndexOf(Object o) |
ListIterator |
listIterator() |
ListIterator |
listIterator(int i) |
static List |
newInstance(List items, boolean lazyDefaultValues, Closure initClosure) |
boolean |
remove(Object o) |
Object |
remove(int i) |
boolean |
removeAll(Collection objects) |
boolean |
retainAll(Collection objects) |
Object |
set(int i, Object t) |
int |
size() |
List |
subList(int fromIndex, int toIndex) |
Object[] |
toArray() |
Object[] |
toArray(Object[] ts) |
Returns the element at the given index but grows the list if needed. If the requestedindexis greater than or equal tosize(), the list will grow to the new size and a default value calculated using theinitClosurewill be used to populate the missing value and returned.If
lazyDefaultValuesistrueany gaps when growing the list are filled with nulls. Subsequent attempts to retrieve items from the list from those gap index values will, upon finding null, call theinitClosureto populate the list for the given list value. Hence, when in this mode, nulls cannot be stored in this list. IflazyDefaultValuesisfalseany gaps when growing the list are filled eagerly by calling theinitClosurefor all gap indexes during list growth. No calls toinitClosureare made except during list growth and it is ok to store null values in the list when in this mode.This implementation breaks the contract of List.get as it a) possibly modifies the underlying list and b) does NOT throw an IndexOutOfBoundsException when
index < 0 || index >= size().
index - an index (might be greater or equal to size(), or smaller than 0)index or the default valueOverwrites subscript operator handling by redirecting to get(int).
index - an index (might be greater or equal to size(), or smaller than 0)index or the default value