Class 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>
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 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)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.lang.IterableforEachMethods inherited from interface java.util.ListreplaceAll, sort, spliterator
- 
Method Details- 
getDelegate
- 
isLazyDefaultValuespublic boolean isLazyDefaultValues()
- 
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)
- 
iterator
- 
toArraypublic java.lang.Object[] toArray()
- 
toArraypublic <T> T[] toArray(T[] ts)
- 
add
- 
removepublic boolean remove(java.lang.Object o)
- 
containsAllpublic boolean containsAll(java.util.Collection<?> objects)
- 
addAll
- 
addAll- 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()
- 
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().- 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
 
- 
set- Specified by:
- setin interface- java.util.List<T>
 
- 
add- Specified by:
- addin interface- java.util.List<T>
 
- 
remove- Specified by:
- removein interface- java.util.List<T>
 
- 
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>
 
- 
listIterator- Specified by:
- listIteratorin interface- java.util.List<T>
 
- 
listIterator- Specified by:
- listIteratorin interface- java.util.List<T>
 
- 
equalspublic boolean equals(java.lang.Object obj)
- 
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.- 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
 
 
-