public class LazyList
extends Object
implements List, Serializable
LazyList wraps around a standard ArrayList and ensures that any get() activity which returns a null
value will return a freshly instantiated item instead.
This class should allow the Component Builder framework to function well within a form-based UI, where child components are added / removed at the web page level.
This class is similar in intent to the Apache commons-collections version, but my implementation differs in the following ways:
Constructor and Description |
---|
LazyList(Class instantiatingClass)
Base constructor for a lazy list.
|
LazyList(List<?> list,
Class instantiatingClass)
Complete constructor for a lazy list.
|
Modifier and Type | Method and Description |
---|---|
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 object) |
Object |
get(int index)
Intercepts the get() method to create new items if get() might return null.
|
Class |
getInstantiatingClass()
Accessor for the class that will be instantiated lazily
|
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)
Intercepts the subList method to maintain a LazyList on the returned sublist.
|
Object[] |
toArray() |
Object[] |
toArray(Object[] a) |
String |
toString() |
public LazyList(Class instantiatingClass)
instantiatingClass
- the class that will be instantiated when get() returns nullIllegalArgumentException
- if either the list or class are nullpublic LazyList(List<?> list, Class instantiatingClass)
list
- the underlying list that will be wrappedinstantiatingClass
- the class that will be instantiated when get() returns nullIllegalArgumentException
- if either the list or class are nullpublic boolean equals(Object object)
equals
in interface Collection
equals
in interface List
equals
in class Object
Object.equals(Object)
public int hashCode()
hashCode
in interface Collection
hashCode
in interface List
hashCode
in class Object
Object.hashCode()
public String toString()
toString
in class Object
Object.toString()
public Object get(int index)
If an index is requested beyond the bounds of the list size, the list will extend to that position and interim positions will also be instantiated.
get
in interface List
index
- the index to retrievepublic List<?> subList(int fromIndex, int toIndex)
subList
in interface List
List.subList(int, int)
public Class getInstantiatingClass()
public int size()
size
in interface Collection
size
in interface List
List.size()
public boolean isEmpty()
isEmpty
in interface Collection
isEmpty
in interface List
List.isEmpty()
public boolean contains(Object o)
contains
in interface Collection
contains
in interface List
List.contains(java.lang.Object)
public Iterator<?> iterator()
iterator
in interface Iterable
iterator
in interface Collection
iterator
in interface List
List.iterator()
public Object[] toArray()
toArray
in interface Collection
toArray
in interface List
List.toArray()
public Object[] toArray(Object[] a)
toArray
in interface Collection
toArray
in interface List
List.toArray(Object[])
public boolean add(Object o)
add
in interface Collection
add
in interface List
List.add(java.lang.Object)
public boolean remove(Object o)
remove
in interface Collection
remove
in interface List
List.remove(java.lang.Object)
public boolean containsAll(Collection c)
containsAll
in interface Collection
containsAll
in interface List
List.containsAll(java.util.Collection)
public boolean addAll(Collection c)
addAll
in interface Collection
addAll
in interface List
List.addAll(java.util.Collection)
public boolean addAll(int index, Collection c)
addAll
in interface List
List.addAll(int, java.util.Collection)
public boolean removeAll(Collection c)
removeAll
in interface Collection
removeAll
in interface List
List.removeAll(java.util.Collection)
public boolean retainAll(Collection c)
retainAll
in interface Collection
retainAll
in interface List
List.retainAll(java.util.Collection)
public void clear()
clear
in interface Collection
clear
in interface List
List.clear()
public Object set(int index, Object element)
set
in interface List
List.set(int, java.lang.Object)
public void add(int index, Object element)
add
in interface List
List.add(int, java.lang.Object)
public Object remove(int index)
remove
in interface List
List.remove(int)
public int indexOf(Object o)
indexOf
in interface List
List.indexOf(java.lang.Object)
public int lastIndexOf(Object o)
lastIndexOf
in interface List
List.lastIndexOf(java.lang.Object)
public ListIterator<?> listIterator()
listIterator
in interface List
List.listIterator()
public ListIterator<?> listIterator(int index)
listIterator
in interface List
List.listIterator(int)
Copyright 2010 - 2019 by Brian Uri!
Generated on 09/15/2016 12:36 PM
https://ddmsence.urizone.net/