Package org.springframework.util
Class AutoPopulatingList<E>
- java.lang.Object
- org.springframework.util.AutoPopulatingList<E>
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,List<E>
public class AutoPopulatingList<E> extends Object implements List<E>, Serializable
SimpleListwrapper class that allows for elements to be automatically populated as they are requested. This is particularly useful for data binding toLists, allowing for elements to be created and added to theListin a "just in time" fashion.Note: This class is not thread-safe. To create a thread-safe version, use the
Collections.synchronizedList(java.util.List<T>)utility methods.Inspired by
LazyListfrom Commons Collections.- Since:
- 2.0
- Author:
- Rob Harrop, Juergen Hoeller
- See Also:
- Serialized Form
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAutoPopulatingList.ElementFactory<E>Factory interface for creating elements for an index-based access data structure such as aList.static classAutoPopulatingList.ElementInstantiationExceptionException to be thrown from ElementFactory.
Constructor Summary
Constructors Constructor Description AutoPopulatingList(Class<? extends E> elementClass)Creates a newAutoPopulatingListthat is backed by a standardArrayListand adds new instances of the suppliedelement Classto the backingListon demand.AutoPopulatingList(List<E> backingList, Class<? extends E> elementClass)Creates a newAutoPopulatingListthat is backed by the suppliedListand adds new instances of the suppliedelement Classto the backingListon demand.AutoPopulatingList(List<E> backingList, AutoPopulatingList.ElementFactory<E> elementFactory)Creates a newAutoPopulatingListthat is backed by the suppliedListand creates new elements on demand using the suppliedAutoPopulatingList.ElementFactory.AutoPopulatingList(AutoPopulatingList.ElementFactory<E> elementFactory)Creates a newAutoPopulatingListthat is backed by a standardArrayListand creates new elements on demand using the suppliedAutoPopulatingList.ElementFactory.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, E element)booleanadd(E o)booleanaddAll(int index, Collection<? extends E> c)booleanaddAll(Collection<? extends E> c)voidclear()booleancontains(Object o)booleancontainsAll(Collection<?> c)booleanequals(Object other)Eget(int index)Get the element at the supplied index, creating it if there is no element at that index.inthashCode()intindexOf(Object o)booleanisEmpty()Iterator<E>iterator()intlastIndexOf(Object o)ListIterator<E>listIterator()ListIterator<E>listIterator(int index)Eremove(int index)booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanretainAll(Collection<?> c)Eset(int index, E element)intsize()List<E>subList(int fromIndex, int toIndex)Object[]toArray()<T> T[]toArray(T[] a)Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
replaceAll, sort, spliterator
Constructor Detail
AutoPopulatingList
public AutoPopulatingList(Class<? extends E> elementClass)
Creates a newAutoPopulatingListthat is backed by a standardArrayListand adds new instances of the suppliedelement Classto the backingListon demand.
AutoPopulatingList
public AutoPopulatingList(List<E> backingList, Class<? extends E> elementClass)
Creates a newAutoPopulatingListthat is backed by the suppliedListand adds new instances of the suppliedelement Classto the backingListon demand.
AutoPopulatingList
public AutoPopulatingList(AutoPopulatingList.ElementFactory<E> elementFactory)
Creates a newAutoPopulatingListthat is backed by a standardArrayListand creates new elements on demand using the suppliedAutoPopulatingList.ElementFactory.
AutoPopulatingList
public AutoPopulatingList(List<E> backingList, AutoPopulatingList.ElementFactory<E> elementFactory)
Creates a newAutoPopulatingListthat is backed by the suppliedListand creates new elements on demand using the suppliedAutoPopulatingList.ElementFactory.
Method Detail
addAll
public boolean addAll(Collection<? extends E> c)
addAll
public boolean addAll(int index, Collection<? extends E> c)
clear
public void clear()
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceList<E>
get
public E get(int index)
Get the element at the supplied index, creating it if there is no element at that index.
isEmpty
public boolean isEmpty()
lastIndexOf
public int lastIndexOf(Object o)
- Specified by:
lastIndexOfin interfaceList<E>
listIterator
public ListIterator<E> listIterator()
- Specified by:
listIteratorin interfaceList<E>
listIterator
public ListIterator<E> listIterator(int index)
- Specified by:
listIteratorin interfaceList<E>
removeAll
public boolean removeAll(Collection<?> c)
retainAll
public boolean retainAll(Collection<?> c)
size
public int size()
toArray
public <T> T[] toArray(T[] a)