Class LazyList
-
- All Implemented Interfaces:
Serializable,Iterable,Collection,List
@Deprecated(since="2021-04-30") public class LazyList extends AbstractSerializableListDecorator
Deprecated.Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.Decorates anotherListto 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,objwill contain a newDateinstance. Furthermore, thatDateinstance is the fourth element in the list. The first, second, and third element are all set tonull.This class differs from
GrowthListbecause here growth occurs on get, whereGrowthListgrows on set and add. However, they could easily be used together by decorating twice.This class is Serializable from Commons Collections 3.1.
- Since:
- Commons Collections 3.0
- See Also:
GrowthList, Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Listdecorate(List list, Factory factory)Deprecated.Factory method to create a lazily instantiating list.Objectget(int index)Deprecated.Decorate the get method to perform the lazy behaviour.ListsubList(int fromIndex, int toIndex)Deprecated.-
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 interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
-
-
-
Method Detail
-
decorate
public static List decorate(List list, Factory factory)
Deprecated.Factory method to create a lazily instantiating list.- Parameters:
list- the list to decorate, must not be nullfactory- the factory to use for creation, must not be null- Throws:
IllegalArgumentException- if list or factory is null
-
get
public Object get(int index)
Deprecated.Decorate the get method to perform the lazy behaviour.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.
- Specified by:
getin interfaceList- Overrides:
getin classAbstractListDecorator- Parameters:
index- the index to retrieve
-
subList
public List subList(int fromIndex, int toIndex)
Deprecated.- Specified by:
subListin interfaceList- Overrides:
subListin classAbstractListDecorator
-
-