Class ListWithDefault<T>
- All Implemented Interfaces:
- Iterable<T>,- Collection<T>,- List<T>
List which automatically grows the list when either get(int) or
 getAt(int) is called with an index greater than or equal to size().- Since:
- 1.8.7
- 
Method SummaryModifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int i, Collection<? extends T> ts) booleanaddAll(Collection<? extends T> ts) voidclear()booleanbooleancontainsAll(Collection<?> objects) booleanget(int index) Returns the element at the given index but grows the list if needed.getAt(int index) Overwrites subscript operator handling by redirecting toget(int).inthashCode()intbooleanisEmpty()booleaniterator()intlistIterator(int i) static <T> ListWithDefault<T>newInstance(List<T> items, boolean lazyDefaultValues, Closure initClosure) remove(int i) booleanbooleanremoveAll(Collection<?> objects) booleanretainAll(Collection<?> objects) intsize()subList(int fromIndex, int toIndex) Returns a view of a portion of this list.Object[]toArray()<U> U[]toArray(U[] ts) Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.CollectionparallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.ListreplaceAll, sort, spliterator
- 
Method Details- 
getDelegate
- 
isLazyDefaultValuespublic boolean isLazyDefaultValues()
- 
getInitClosure
- 
newInstancepublic static <T> ListWithDefault<T> newInstance(List<T> items, boolean lazyDefaultValues, Closure initClosure) 
- 
sizepublic int size()
- 
isEmptypublic boolean isEmpty()
- 
contains
- 
iterator
- 
toArray
- 
toArraypublic <U> U[] toArray(U[] ts) 
- 
add
- 
remove
- 
containsAll- Specified by:
- containsAllin interface- Collection<T>
- Specified by:
- containsAllin interface- List<T>
 
- 
addAll
- 
addAll
- 
removeAll
- 
retainAll
- 
clearpublic void clear()
- 
getAtOverwrites 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
 
- 
getReturns 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().
- 
set
- 
add
- 
remove
- 
indexOf
- 
lastIndexOf- Specified by:
- lastIndexOfin interface- List<T>
 
- 
listIterator- Specified by:
- listIteratorin interface- List<T>
 
- 
listIterator- Specified by:
- listIteratorin interface- List<T>
 
- 
equals
- 
hashCodepublic int hashCode()
- 
subListReturns a view of a portion of this list. This method returns a list with the same lazy list settings as the original list.
 
-