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 Iterator
Singleton iterator for empty collection.static final LazyList
Unmodifiable empty list instance.private Object[]
Backing array (lazy instantiation,null
if not used).private int
Maximum number of items allowed before resizing.private int
Number of items currently present in list.Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
compact()
Compact the list, removing anynull
values.get
(int index) int
Get modify counter.iterator()
private void
makeSpace
(int count) Make sure space is available for adding to the list.remove
(int index) void
remove
(int from, int to) Remove range of values.protected void
removeRange
(int from, int to) int
size()
Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, subList
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods 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,null
if 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:
get
in interfaceList
- Specified by:
get
in classAbstractList
-
size
public int size()- Specified by:
size
in interfaceCollection
- Specified by:
size
in interfaceList
- Specified by:
size
in classAbstractCollection
-
add
- Specified by:
add
in interfaceList
- Overrides:
add
in classAbstractList
-
iterator
- Specified by:
iterator
in interfaceCollection
- Specified by:
iterator
in interfaceIterable
- Specified by:
iterator
in interfaceList
- Overrides:
iterator
in classAbstractList
-
remove
- Specified by:
remove
in interfaceList
- Overrides:
remove
in classAbstractList
-
set
- Specified by:
set
in interfaceList
- Overrides:
set
in classAbstractList
-
removeRange
protected void removeRange(int from, int to) - Overrides:
removeRange
in 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 anynull
values.
-