Package org.jibx.util
Class SparseArrayIterator
- java.lang.Object
-
- org.jibx.util.SparseArrayIterator
-
- All Implemented Interfaces:
java.util.Iterator
public class SparseArrayIterator extends java.lang.Object implements java.util.IteratorIterator class for sparse values in an array. This type of iterator can be used for an object array which has references interspersed withnulls.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description static SparseArrayIteratorEMPTY_ITERATOREmpty iterator.private java.lang.Object[]m_arrayArray supplying values for iteration.private intm_offsetOffset of next iteration value.
-
Constructor Summary
Constructors Modifier Constructor Description privateSparseArrayIterator(java.lang.Object[] array)Internal constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanadvance()Advance to next iteration value.static java.util.IteratorbuildIterator(java.lang.Object[] array)Build iterator.booleanhasNext()Check for iteration element available.java.lang.Objectnext()Get next iteration element.voidremove()Remove element from iteration.
-
-
-
Field Detail
-
EMPTY_ITERATOR
public static final SparseArrayIterator EMPTY_ITERATOR
Empty iterator.
-
m_array
private java.lang.Object[] m_array
Array supplying values for iteration.
-
m_offset
private int m_offset
Offset of next iteration value.
-
-
Method Detail
-
advance
protected boolean advance()
Advance to next iteration value. This advances the current position in the array to the next non-nullvalue.- Returns:
trueif element available,falseif not
-
hasNext
public boolean hasNext()
Check for iteration element available.- Specified by:
hasNextin interfacejava.util.Iterator- Returns:
trueif element available,falseif not
-
next
public java.lang.Object next()
Get next iteration element.- Specified by:
nextin interfacejava.util.Iterator- Returns:
- next iteration element
- Throws:
java.util.NoSuchElementException- if past end of iteration
-
remove
public void remove()
Remove element from iteration. This optional operation is not supported and always throws an exception.- Specified by:
removein interfacejava.util.Iterator- Throws:
java.lang.UnsupportedOperationException- for unsupported operation
-
buildIterator
public static java.util.Iterator buildIterator(java.lang.Object[] array)
Build iterator.- Parameters:
array- array containing values to be iterated (may benull)- Returns:
- constructed iterator
-
-