Package org.jibx.util
Class LazyList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList
-
- org.jibx.util.LazyList
-
- All Implemented Interfaces:
java.lang.Iterable
,java.util.Collection
,java.util.List
public class LazyList extends java.util.AbstractList
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
Fields Modifier and Type Field Description static java.util.Iterator
EMPTY_ITERATOR
Singleton iterator for empty collection.static LazyList
EMPTY_LIST
Unmodifiable empty list instance.private java.lang.Object[]
m_array
Backing array (lazy instantiation,null
if not used).private int
m_limit
Maximum number of items allowed before resizing.private int
m_size
Number of items currently present in list.
-
Constructor Summary
Constructors Constructor Description LazyList()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, java.lang.Object element)
void
compact()
Compact the list, removing anynull
values.java.lang.Object
get(int index)
int
getModCount()
Get modify counter.java.util.Iterator
iterator()
private void
makeSpace(int count)
Make sure space is available for adding to the list.java.lang.Object
remove(int index)
void
remove(int from, int to)
Remove range of values.protected void
removeRange(int from, int to)
java.lang.Object
set(int index, java.lang.Object element)
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
-
-
-
-
Field Detail
-
EMPTY_ITERATOR
public static final java.util.Iterator EMPTY_ITERATOR
Singleton iterator for empty collection.
-
EMPTY_LIST
public static final LazyList EMPTY_LIST
Unmodifiable empty list instance.
-
m_size
private int m_size
Number of items currently present in list.
-
m_limit
private int m_limit
Maximum number of items allowed before resizing.
-
m_array
private java.lang.Object[] m_array
Backing array (lazy instantiation,null
if not used).
-
-
Method Detail
-
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
public java.lang.Object get(int index)
- Specified by:
get
in interfacejava.util.List
- Specified by:
get
in classjava.util.AbstractList
-
size
public int size()
- Specified by:
size
in interfacejava.util.Collection
- Specified by:
size
in interfacejava.util.List
- Specified by:
size
in classjava.util.AbstractCollection
-
add
public void add(int index, java.lang.Object element)
- Specified by:
add
in interfacejava.util.List
- Overrides:
add
in classjava.util.AbstractList
-
iterator
public java.util.Iterator iterator()
- Specified by:
iterator
in interfacejava.util.Collection
- Specified by:
iterator
in interfacejava.lang.Iterable
- Specified by:
iterator
in interfacejava.util.List
- Overrides:
iterator
in classjava.util.AbstractList
-
remove
public java.lang.Object remove(int index)
- Specified by:
remove
in interfacejava.util.List
- Overrides:
remove
in classjava.util.AbstractList
-
set
public java.lang.Object set(int index, java.lang.Object element)
- Specified by:
set
in interfacejava.util.List
- Overrides:
set
in classjava.util.AbstractList
-
removeRange
protected void removeRange(int from, int to)
- Overrides:
removeRange
in classjava.util.AbstractList
-
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.
-
-