org.springframework.util
Class AutoPopulatingList

java.lang.Object
  extended by org.springframework.util.AutoPopulatingList
All Implemented Interfaces:
Serializable, Iterable, Collection, List

public class AutoPopulatingList
extends Object
implements List, Serializable

Simple 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) utility methods.

Inspired by LazyList from Commons Collections.

Since:
2.0
Author:
Rob Harrop, Juergen Hoeller
See Also:
Serialized Form

Nested Class Summary
static interface AutoPopulatingList.ElementFactory
          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 Summary
AutoPopulatingList(AutoPopulatingList.ElementFactory elementFactory)
          Creates a new AutoPopulatingList that is backed by a standard ArrayList and creates new elements on demand using the supplied AutoPopulatingList.ElementFactory.
AutoPopulatingList(Class 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(List backingList, AutoPopulatingList.ElementFactory elementFactory)
          Creates a new AutoPopulatingList that is backed by the supplied List and creates new elements on demand using the supplied AutoPopulatingList.ElementFactory.
AutoPopulatingList(List backingList, Class 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.
 
Method Summary
 void add(int index, Object element)
           
 boolean add(Object o)
           
 boolean addAll(Collection c)
           
 boolean addAll(int index, Collection c)
           
 void clear()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection c)
           
 boolean equals(Object o)
           
 Object get(int index)
          Get the element at the supplied index, creating it if there is no element at that index.
 int hashCode()
           
 int indexOf(Object o)
           
 boolean isEmpty()
           
 Iterator iterator()
           
 int lastIndexOf(Object o)
           
 ListIterator listIterator()
           
 ListIterator listIterator(int index)
           
 Object remove(int index)
           
 boolean remove(Object o)
           
 boolean removeAll(Collection c)
           
 boolean retainAll(Collection c)
           
 Object set(int index, Object element)
           
 int size()
           
 List subList(int fromIndex, int toIndex)
           
 Object[] toArray()
           
 Object[] toArray(Object[] a)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AutoPopulatingList

public AutoPopulatingList(Class 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

public AutoPopulatingList(List backingList,
                          Class 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.


AutoPopulatingList

public AutoPopulatingList(AutoPopulatingList.ElementFactory elementFactory)
Creates a new AutoPopulatingList that is backed by a standard ArrayList and creates new elements on demand using the supplied AutoPopulatingList.ElementFactory.


AutoPopulatingList

public AutoPopulatingList(List backingList,
                          AutoPopulatingList.ElementFactory elementFactory)
Creates a new AutoPopulatingList that is backed by the supplied List and creates new elements on demand using the supplied AutoPopulatingList.ElementFactory.

Method Detail

add

public void add(int index,
                Object element)
Specified by:
add in interface List

add

public boolean add(Object o)
Specified by:
add in interface Collection
Specified by:
add in interface List

addAll

public boolean addAll(Collection c)
Specified by:
addAll in interface Collection
Specified by:
addAll in interface List

addAll

public boolean addAll(int index,
                      Collection c)
Specified by:
addAll in interface List

clear

public void clear()
Specified by:
clear in interface Collection
Specified by:
clear in interface List

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection
Specified by:
contains in interface List

containsAll

public boolean containsAll(Collection c)
Specified by:
containsAll in interface Collection
Specified by:
containsAll in interface List

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection
Specified by:
equals in interface List
Overrides:
equals in class Object

get

public Object get(int index)
Get the element at the supplied index, creating it if there is no element at that index.

Specified by:
get in interface List

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection
Specified by:
hashCode in interface List
Overrides:
hashCode in class Object

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection
Specified by:
isEmpty in interface List

iterator

public Iterator iterator()
Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface List

lastIndexOf

public int lastIndexOf(Object o)
Specified by:
lastIndexOf in interface List

listIterator

public ListIterator listIterator()
Specified by:
listIterator in interface List

listIterator

public ListIterator listIterator(int index)
Specified by:
listIterator in interface List

remove

public Object remove(int index)
Specified by:
remove in interface List

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection
Specified by:
remove in interface List

removeAll

public boolean removeAll(Collection c)
Specified by:
removeAll in interface Collection
Specified by:
removeAll in interface List

retainAll

public boolean retainAll(Collection c)
Specified by:
retainAll in interface Collection
Specified by:
retainAll in interface List

set

public Object set(int index,
                  Object element)
Specified by:
set in interface List

size

public int size()
Specified by:
size in interface Collection
Specified by:
size in interface List

subList

public List subList(int fromIndex,
                    int toIndex)
Specified by:
subList in interface List

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List

toArray

public Object[] toArray(Object[] a)
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List


Copyright © 2002-2008 The Spring Framework.