|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object
|
+--org.apache.commons.collections.collection.AbstractCollectionDecorator
|
+--org.apache.commons.collections.list.AbstractListDecorator
|
+--org.apache.commons.collections.list.LazyList
Decorates another List to create objects in the list on demand.
When the get(int) method is called with an index greater than
the size of the list, the list will automatically grow in size and return
a new object from the specified factory. The gaps will be filled by null.
If a get method call encounters a null, it will be replaced with a new
object from the factory. Thus this list is unsuitable for storing null
objects.
For instance:
Factory factory = new Factory() {
public Object create() {
return new Date();
}
}
List lazy = LazyList.decorate(new ArrayList(), factory);
Object obj = lazy.get(3);
After the above code is executed, obj will contain
a new Date instance. Furthermore, that Date
instance is the fourth element in the list. The first, second,
and third element are all set to null.
| Method Summary | |
static java.util.List |
decorate(java.util.List list,
Factory factory)
Factory method to create a lazily instantiating list. |
java.lang.Object |
get(int index)
Decorate the get method to perform the lazy behaviour. |
java.util.List |
subList(int fromIndex,
int toIndex)
|
| Methods inherited from class org.apache.commons.collections.list.AbstractListDecorator |
add, addAll, indexOf, lastIndexOf, listIterator, listIterator, remove, set |
| Methods inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator |
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.List |
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
| Method Detail |
public static java.util.List decorate(java.util.List list,
Factory factory)
list - the list to decorate, must not be nullfactory - the factory to use for creation, must not be null
java.lang.IllegalArgumentException - if list or factory is nullpublic java.lang.Object get(int index)
If the requested index is greater than the current size, the list will grow to the new size and a new object will be returned from the factory. Indexes in-between the old size and the requested size are left with a placeholder that is replaced with a factory object when requested.
get in interface java.util.Listget in class AbstractListDecoratorindex - the index to retrieve
public java.util.List subList(int fromIndex,
int toIndex)
subList in interface java.util.ListsubList in class AbstractListDecorator
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||