public abstract class LazyList extends ArrayList
Internally, it only stores identifiers (as a list passed at initialization). Instances are only retrieved when invoking the get(int index) method of the list. This load-on-demand technique is also known as lazy materialization.
Instances can be added or removed from list via class methods. You can both add the instance to the list or instance identifier. If you need to retrieve the list of identifiers stored internally use the getIds method which returns an array of strings.
Modifier and Type | Field and Description |
---|---|
protected boolean |
discardDuplicates
Flag indicating if duplicated elements are allowed.
|
protected int |
fetchSize
The number of elements fetched when invoking the get(index) method.
|
protected List |
instanceList
List of instances already retrieved by the lazy calls.
|
modCount
Constructor and Description |
---|
LazyList(boolean discardDuplicates)
Constructs an empty list.
|
LazyList(Collection c,
boolean discardDuplicates)
Constructs a list from the identifiers of the specified collection,
in the order they are returned by the collection's iterator.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
Object o)
Inserts the specified element at the specified position in this
list.
|
boolean |
add(Object o)
Appends the specified element to the end of this list.
|
boolean |
addAll(Collection c)
Appends all of the elements in the specified Collection to the end of
this list, in the order that they are returned by the
specified Collection's Iterator.
|
boolean |
addAll(int index,
Collection c)
Not supported.
|
boolean |
contains(Object o)
Returns true if this list contains the specified element.
|
abstract LazyList |
createLazyList(Collection c)
Creates a brand new lazy list initialiaed with the given list of identifiers.
|
Object |
get(int index)
Retrieves the instance at specified position.
|
int |
getFetchSize()
The number of elements fetched when invoking the get(index) method.
|
String |
getId(int index)
Retrieve identifier stored at given position.
|
String[] |
getIds()
Retrieve identifiers stored internally in the lazy list.
|
abstract String |
getInstanceId(Object o)
Retreives the identifier of an instance.
|
int |
indexOf(Object elem)
Searches for the first occurence of the given argument, testing
for equality using the equals method.
|
abstract boolean |
isInstance(Object o)
Check if object is an business object or an identifier.
|
int |
lastIndexOf(Object elem)
Returns the index of the last occurrence of the specified object in
this list.
|
abstract List |
loadInstances(String[] ids)
Loads the instances with the given identifiers.
|
boolean |
remove(Object o)
Removes the process from the collection
|
boolean |
removeAll(Collection c)
Removes from this collection all of its elements that are contained in
the specified collection (optional operation).
|
boolean |
removeId(String id)
Remove identifier from list.
|
Object |
set(int index,
Object element)
Replaces the element at the specified position in this list with
the specified element.
|
void |
setFetchSize(int fetchSize)
The number of elements fetched when invoking the get(index) method.
|
List |
subList(int fromIndex,
int toIndex)
Returns a view of the portion of this list between fromIndex,
inclusive, and toIndex, exclusive.
|
clear, clone, ensureCapacity, isEmpty, iterator, listIterator, listIterator, remove, removeRange, retainAll, size, toArray, toArray, trimToSize
equals, hashCode
containsAll, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
containsAll, equals, hashCode
protected List instanceList
protected boolean discardDuplicates
protected int fetchSize
public LazyList(boolean discardDuplicates)
discardDuplicates
- Ensure list not contains duplicates.public LazyList(Collection c, boolean discardDuplicates)
c
- the collection of ids.discardDuplicates
- Ensure list not contains duplicates.public int getFetchSize()
public void setFetchSize(int fetchSize)
public abstract boolean isInstance(Object o)
public abstract String getInstanceId(Object o)
public abstract List loadInstances(String[] ids)
public abstract LazyList createLazyList(Collection c)
public String[] getIds()
public String getId(int index)
index
- public boolean removeId(String id)
public Object get(int index)
public boolean remove(Object o)
public boolean contains(Object o)
public int indexOf(Object elem)
indexOf
in interface List
indexOf
in class ArrayList
elem
- an object.Object.equals(Object)
public int lastIndexOf(Object elem)
lastIndexOf
in interface List
lastIndexOf
in class ArrayList
elem
- the desired element.public boolean add(Object o)
public void add(int index, Object o)
add
in interface List
add
in class ArrayList
index
- index at which the specified element is to be inserted.o
- element to be inserted.
If trying to add an instance then its identifier is added instead of the whole instance.IndexOutOfBoundsException
- if index is out of range
(index < 0 || index > size()).public boolean addAll(Collection c)
addAll
in interface Collection
addAll
in interface List
addAll
in class ArrayList
c
- the collection of both instances or ids.
If trying to add an instance then its identifier is added instead of the whole instance.IndexOutOfBoundsException
- if index out of range (index
< 0 || index > size()).public boolean addAll(int index, Collection c)
public boolean removeAll(Collection c)
This implementation retrieves the elements from the target collection and performs single remove operations for each one of these elements.
public Object set(int index, Object element)
set
in interface List
set
in class ArrayList
index
- index of element to replace.element
- element to be stored at the specified position.IndexOutOfBoundsException
- if index out of range
(index < 0 || index >= size()).public List subList(int fromIndex, int toIndex)
Copyright © 2012-2015 JBoss by Red Hat. All Rights Reserved.