|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgroovy.lang.ListWithDefault<T>
public final class ListWithDefault<T>
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()
.
Method Summary | ||
---|---|---|
void |
add(int i,
T t)
|
|
boolean |
add(T t)
|
|
boolean |
addAll(java.util.Collection<? extends T> ts)
|
|
boolean |
addAll(int i,
java.util.Collection<? extends T> ts)
|
|
void |
clear()
|
|
boolean |
contains(java.lang.Object o)
|
|
boolean |
containsAll(java.util.Collection<?> objects)
|
|
boolean |
equals(java.lang.Object obj)
|
|
T |
get(int index)
Returns the element at the given index but grows the list if needed. |
|
T |
getAt(int index)
Overwrites subscript operator handling by redirecting to get(int) . |
|
int |
hashCode()
|
|
int |
indexOf(java.lang.Object o)
|
|
boolean |
isEmpty()
|
|
java.util.Iterator<T> |
iterator()
|
|
int |
lastIndexOf(java.lang.Object o)
|
|
java.util.ListIterator<T> |
listIterator()
|
|
java.util.ListIterator<T> |
listIterator(int i)
|
|
static
|
newInstance(java.util.List<T> items,
boolean lazyDefaultValues,
Closure initClosure)
|
|
T |
remove(int i)
|
|
boolean |
remove(java.lang.Object o)
|
|
boolean |
removeAll(java.util.Collection<?> objects)
|
|
boolean |
retainAll(java.util.Collection<?> objects)
|
|
T |
set(int i,
T t)
|
|
int |
size()
|
|
java.util.List<T> |
subList(int fromIndex,
int toIndex)
Returns a view of a portion of this list. |
|
java.lang.Object[] |
toArray()
|
|
|
toArray(T[] ts)
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <T> java.util.List<T> newInstance(java.util.List<T> items, boolean lazyDefaultValues, Closure initClosure)
public int size()
size
in interface java.util.Collection<T>
size
in interface java.util.List<T>
public boolean isEmpty()
isEmpty
in interface java.util.Collection<T>
isEmpty
in interface java.util.List<T>
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<T>
contains
in interface java.util.List<T>
public java.util.Iterator<T> iterator()
iterator
in interface java.lang.Iterable<T>
iterator
in interface java.util.Collection<T>
iterator
in interface java.util.List<T>
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<T>
toArray
in interface java.util.List<T>
public <T> T[] toArray(T[] ts)
toArray
in interface java.util.Collection<T>
toArray
in interface java.util.List<T>
public boolean add(T t)
add
in interface java.util.Collection<T>
add
in interface java.util.List<T>
public boolean remove(java.lang.Object o)
remove
in interface java.util.Collection<T>
remove
in interface java.util.List<T>
public boolean containsAll(java.util.Collection<?> objects)
containsAll
in interface java.util.Collection<T>
containsAll
in interface java.util.List<T>
public boolean addAll(java.util.Collection<? extends T> ts)
addAll
in interface java.util.Collection<T>
addAll
in interface java.util.List<T>
public boolean addAll(int i, java.util.Collection<? extends T> ts)
addAll
in interface java.util.List<T>
public boolean removeAll(java.util.Collection<?> objects)
removeAll
in interface java.util.Collection<T>
removeAll
in interface java.util.List<T>
public boolean retainAll(java.util.Collection<?> objects)
retainAll
in interface java.util.Collection<T>
retainAll
in interface java.util.List<T>
public void clear()
clear
in interface java.util.Collection<T>
clear
in interface java.util.List<T>
public T getAt(int index)
get(int)
.
index
- an index (might be greater or equal to size()
, or smaller than 0)
index
or the default valuepublic T get(int index)
index
is
greater than or equal to size()
, the list will grow to the new size and a default value calculated
using the initClosure
will be used to populate the missing value and returned.
If lazyDefaultValues
is true
any 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 the initClosure
to populate the list for the
given list value. Hence, when in this mode, nulls cannot be stored in this list.
If lazyDefaultValues
is false
any gaps when growing the list are filled
eagerly by calling the initClosure
for all gap indexes during list growth.
No calls to initClosure
are 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(int)
as it a) possibly modifies the underlying list and b) does
NOT throw an IndexOutOfBoundsException
when index < 0 || index >= size()
.
get
in interface java.util.List<T>
index
- an index (might be greater or equal to size()
, or smaller than 0)
index
or the default valuepublic T set(int i, T t)
set
in interface java.util.List<T>
public void add(int i, T t)
add
in interface java.util.List<T>
public T remove(int i)
remove
in interface java.util.List<T>
public int indexOf(java.lang.Object o)
indexOf
in interface java.util.List<T>
public int lastIndexOf(java.lang.Object o)
lastIndexOf
in interface java.util.List<T>
public java.util.ListIterator<T> listIterator()
listIterator
in interface java.util.List<T>
public java.util.ListIterator<T> listIterator(int i)
listIterator
in interface java.util.List<T>
public boolean equals(java.lang.Object obj)
equals
in interface java.util.Collection<T>
equals
in interface java.util.List<T>
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface java.util.Collection<T>
hashCode
in interface java.util.List<T>
hashCode
in class java.lang.Object
public java.util.List<T> subList(int fromIndex, int toIndex)
subList
in interface java.util.List<T>
fromIndex
- low endpoint of the subList (inclusive)toIndex
- upper endpoint of the subList (exclusive)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |