Package org.jibx.util
Class LazyList
java.lang.Object
java.util.AbstractCollection
java.util.AbstractList
org.jibx.util.LazyList
- All Implemented Interfaces:
Iterable,Collection,List,SequencedCollection
List implementation with lazy array construction and modification tracking. The lazy array construction is a minor
optimization, to save the added overhead of a backing array for lists which are frequently empty. The modification
tracking feature supports filtered list construction with result caching.
- Author:
- Dennis M. Sosnoski
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final IteratorSingleton iterator for empty collection.static final LazyListUnmodifiable empty list instance.private Object[]Backing array (lazy instantiation,nullif not used).private intMaximum number of items allowed before resizing.private intNumber of items currently present in list.Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidcompact()Compact the list, removing anynullvalues.get(int index) intGet modify counter.iterator()private voidmakeSpace(int count) Make sure space is available for adding to the list.remove(int index) voidremove(int from, int to) Remove range of values.protected voidremoveRange(int from, int to) intsize()Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addAll, addFirst, addLast, contains, containsAll, getFirst, getLast, isEmpty, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Field Details
-
EMPTY_ITERATOR
Singleton iterator for empty collection. -
EMPTY_LIST
Unmodifiable empty list instance. -
m_size
private int m_sizeNumber of items currently present in list. -
m_limit
private int m_limitMaximum number of items allowed before resizing. -
m_array
Backing array (lazy instantiation,nullif not used).
-
-
Constructor Details
-
LazyList
public LazyList()
-
-
Method Details
-
makeSpace
private void makeSpace(int count) Make sure space is available for adding to the list. This grows the size of the backing array, if necessary.- Parameters:
count-
-
get
- Specified by:
getin interfaceList- Specified by:
getin classAbstractList
-
size
public int size()- Specified by:
sizein interfaceCollection- Specified by:
sizein interfaceList- Specified by:
sizein classAbstractCollection
-
add
- Specified by:
addin interfaceList- Overrides:
addin classAbstractList
-
iterator
- Specified by:
iteratorin interfaceCollection- Specified by:
iteratorin interfaceIterable- Specified by:
iteratorin interfaceList- Overrides:
iteratorin classAbstractList
-
remove
- Specified by:
removein interfaceList- Overrides:
removein classAbstractList
-
set
- Specified by:
setin interfaceList- Overrides:
setin classAbstractList
-
removeRange
protected void removeRange(int from, int to) - Overrides:
removeRangein classAbstractList
-
getModCount
public int getModCount()Get modify counter. This supports tracking changes to determine when cached filters need to be updated.- Returns:
- count
-
remove
public void remove(int from, int to) Remove range of values. This is just a public version of the protected base class methodremoveRange(int, int)- Parameters:
from-to-
-
compact
public void compact()Compact the list, removing anynullvalues.
-