public class AutoPopulatingList<E>
extends java.lang.Object
implements java.util.List<E>, java.io.Serializable
List wrapper class that allows for elements to be
automatically populated as they are requested. This is particularly
useful for data binding to Lists, allowing for elements
to be created and added to the List in 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 LazyList from Commons Collections.
| Modifier and Type | Class and Description |
|---|---|
static interface |
AutoPopulatingList.ElementFactory<E>
Factory interface for creating elements for an index-based access
data structure such as a
List. |
static class |
AutoPopulatingList.ElementInstantiationException
Exception to be thrown from ElementFactory.
|
| Constructor and Description |
|---|
AutoPopulatingList(AutoPopulatingList.ElementFactory<E> elementFactory)
Creates a new
AutoPopulatingList that is backed by a standard
ArrayList and creates new elements on demand using the supplied AutoPopulatingList.ElementFactory. |
AutoPopulatingList(java.lang.Class<? extends E> elementClass)
Creates a new
AutoPopulatingList that is backed by a standard
ArrayList and adds new instances of the supplied element Class
to the backing List on demand. |
AutoPopulatingList(java.util.List<E> backingList,
AutoPopulatingList.ElementFactory<E> elementFactory)
Creates a new
AutoPopulatingList that is backed by the supplied List
and creates new elements on demand using the supplied AutoPopulatingList.ElementFactory. |
AutoPopulatingList(java.util.List<E> backingList,
java.lang.Class<? extends E> elementClass)
Creates a new
AutoPopulatingList that is backed by the supplied List
and adds new instances of the supplied element Class to the backing
List on demand. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E o) |
void |
add(int index,
E element) |
boolean |
addAll(java.util.Collection<? extends E> c) |
boolean |
addAll(int index,
java.util.Collection<? extends E> c) |
void |
clear() |
boolean |
contains(java.lang.Object o) |
boolean |
containsAll(java.util.Collection<?> c) |
boolean |
equals(java.lang.Object other) |
E |
get(int index)
Get the element at the supplied index, creating it if there is
no element at that index.
|
int |
hashCode() |
int |
indexOf(java.lang.Object o) |
boolean |
isEmpty() |
java.util.Iterator<E> |
iterator() |
int |
lastIndexOf(java.lang.Object o) |
java.util.ListIterator<E> |
listIterator() |
java.util.ListIterator<E> |
listIterator(int index) |
E |
remove(int index) |
boolean |
remove(java.lang.Object o) |
boolean |
removeAll(java.util.Collection<?> c) |
boolean |
retainAll(java.util.Collection<?> c) |
E |
set(int index,
E element) |
int |
size() |
java.util.List<E> |
subList(int fromIndex,
int toIndex) |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
public AutoPopulatingList(java.lang.Class<? extends E> elementClass)
AutoPopulatingList that is backed by a standard
ArrayList and adds new instances of the supplied element Class
to the backing List on demand.public AutoPopulatingList(java.util.List<E> backingList, java.lang.Class<? extends E> elementClass)
AutoPopulatingList that is backed by the supplied List
and adds new instances of the supplied element Class to the backing
List on demand.public AutoPopulatingList(AutoPopulatingList.ElementFactory<E> elementFactory)
AutoPopulatingList that is backed by a standard
ArrayList and creates new elements on demand using the supplied AutoPopulatingList.ElementFactory.public AutoPopulatingList(java.util.List<E> backingList, AutoPopulatingList.ElementFactory<E> elementFactory)
AutoPopulatingList that is backed by the supplied List
and creates new elements on demand using the supplied AutoPopulatingList.ElementFactory.public boolean add(E o)
public boolean addAll(java.util.Collection<? extends E> c)
public boolean addAll(int index,
java.util.Collection<? extends E> c)
addAll in interface java.util.List<E>public void clear()
public boolean contains(java.lang.Object o)
public boolean containsAll(java.util.Collection<?> c)
public E get(int index)
get in interface java.util.List<E>public int indexOf(java.lang.Object o)
indexOf in interface java.util.List<E>public boolean isEmpty()
public java.util.Iterator<E> iterator()
public int lastIndexOf(java.lang.Object o)
lastIndexOf in interface java.util.List<E>public java.util.ListIterator<E> listIterator()
listIterator in interface java.util.List<E>public java.util.ListIterator<E> listIterator(int index)
listIterator in interface java.util.List<E>public boolean remove(java.lang.Object o)
public boolean removeAll(java.util.Collection<?> c)
public boolean retainAll(java.util.Collection<?> c)
public int size()
public java.util.List<E> subList(int fromIndex, int toIndex)
subList in interface java.util.List<E>public java.lang.Object[] toArray()
public <T> T[] toArray(T[] a)
public boolean equals(java.lang.Object other)