Class ListWithDefault<T>
- java.lang.Object
- 
- groovy.lang.ListWithDefault<T>
 
- 
- All Implemented Interfaces:
- java.lang.Iterable<T>,- java.util.Collection<T>,- java.util.List<T>
 
 public final class ListWithDefault<T> extends java.lang.Object implements java.util.List<T>A wrapper forListwhich automatically grows the list when eitherget(int)orgetAt(int)is called with an index greater than or equal tosize().- Since:
- 1.8.7
 
- 
- 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int i, T t)booleanadd(T t)booleanaddAll(int i, java.util.Collection<? extends T> ts)booleanaddAll(java.util.Collection<? extends T> ts)voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> objects)booleanequals(java.lang.Object obj)Tget(int index)Returns the element at the given index but grows the list if needed.TgetAt(int index)Overwrites subscript operator handling by redirecting toget(int).java.util.List<T>getDelegate()ClosuregetInitClosure()inthashCode()intindexOf(java.lang.Object o)booleanisEmpty()booleanisLazyDefaultValues()java.util.Iterator<T>iterator()intlastIndexOf(java.lang.Object o)java.util.ListIterator<T>listIterator()java.util.ListIterator<T>listIterator(int i)static <T> ListWithDefault<T>newInstance(java.util.List<T> items, boolean lazyDefaultValues, Closure initClosure)Tremove(int i)booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> objects)booleanretainAll(java.util.Collection<?> objects)Tset(int i, T t)intsize()ListWithDefault<T>subList(int fromIndex, int toIndex)Returns a view of a portion of this list.java.lang.Object[]toArray()<T> T[]toArray(T[] ts)
 
- 
- 
- 
Method Detail- 
getDelegatepublic java.util.List<T> getDelegate() 
 - 
isLazyDefaultValuespublic boolean isLazyDefaultValues() 
 - 
getInitClosurepublic Closure getInitClosure() 
 - 
newInstancepublic static <T> ListWithDefault<T> newInstance(java.util.List<T> items, boolean lazyDefaultValues, Closure initClosure) 
 - 
sizepublic int size() 
 - 
isEmptypublic boolean isEmpty() 
 - 
containspublic boolean contains(java.lang.Object o) 
 - 
iteratorpublic java.util.Iterator<T> iterator() 
 - 
toArraypublic java.lang.Object[] toArray() 
 - 
toArraypublic <T> T[] toArray(T[] ts) 
 - 
addpublic boolean add(T t) 
 - 
removepublic boolean remove(java.lang.Object o) 
 - 
containsAllpublic boolean containsAll(java.util.Collection<?> objects) 
 - 
addAllpublic boolean addAll(java.util.Collection<? extends T> ts) 
 - 
addAllpublic boolean addAll(int i, java.util.Collection<? extends T> ts)- Specified by:
- addAllin interface- java.util.List<T>
 
 - 
removeAllpublic boolean removeAll(java.util.Collection<?> objects) 
 - 
retainAllpublic boolean retainAll(java.util.Collection<?> objects) 
 - 
clearpublic void clear() 
 - 
getAtpublic T getAt(int index) Overwrites subscript operator handling by redirecting toget(int).- Parameters:
- index- an index (might be greater or equal to- size(), or smaller than 0)
- Returns:
- the value at the given indexor the default value
 
 - 
getpublic T get(int index) 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(int)as it a) possibly modifies the underlying list and b) does NOT throw anIndexOutOfBoundsExceptionwhenindex < 0 || index >= size().- Specified by:
- getin interface- java.util.List<T>
- Parameters:
- index- an index (might be greater or equal to- size(), or smaller than 0)
- Returns:
- the value at the given indexor the default value
 
 - 
indexOfpublic int indexOf(java.lang.Object o) - Specified by:
- indexOfin interface- java.util.List<T>
 
 - 
lastIndexOfpublic int lastIndexOf(java.lang.Object o) - Specified by:
- lastIndexOfin interface- java.util.List<T>
 
 - 
listIteratorpublic java.util.ListIterator<T> listIterator() - Specified by:
- listIteratorin interface- java.util.List<T>
 
 - 
listIteratorpublic java.util.ListIterator<T> listIterator(int i) - Specified by:
- listIteratorin interface- java.util.List<T>
 
 - 
equalspublic boolean equals(java.lang.Object obj) 
 - 
hashCodepublic int hashCode() 
 - 
subListpublic ListWithDefault<T> subList(int fromIndex, int toIndex) Returns a view of a portion of this list. This method returns a list with the same lazy list settings as the original list.- Specified by:
- subListin interface- java.util.List<T>
- Parameters:
- fromIndex- low endpoint of the subList (inclusive)
- toIndex- upper endpoint of the subList (exclusive)
- Returns:
- a view of a specified range within this list, keeping all lazy list settings
 
 
- 
 
-