Package jflex.state
Class StateSetEnumerator
- java.lang.Object
-
- jflex.state.StateSetEnumerator
-
- All Implemented Interfaces:
java.util.Iterator<java.lang.Integer>,java.util.PrimitiveIterator<java.lang.Integer,java.util.function.IntConsumer>,java.util.PrimitiveIterator.OfInt
public final class StateSetEnumerator extends java.lang.Object implements java.util.PrimitiveIterator.OfIntEnumerates the states of aStateSet. Also provides an iterator for native int.- Version:
- JFlex 1.9.1
- See Also:
StateSet
-
-
Field Summary
Fields Modifier and Type Field Description private long[]bitsReference to the array of the StateSet to iterate overprivate static booleanDEBUGLocal compile-time DEBUG flagprivate intindexCurrent index into the StateSet array.private longmaskmask = 1 << offsetprivate intoffsetCurrent offset into the StateSet array
-
Constructor Summary
Constructors Constructor Description StateSetEnumerator()Creates a new StateSetEnumerator that is not yet associated with a StateSet.StateSetEnumerator(StateSet states)Construct a StateSetEnumerator for a given StateSet.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidadvance()Advance to the next element in the set.booleanhasMoreElements()Determine if there are further elements in the set to be returned.booleanhasNext()Iterator interface method fornextElement().intnextElement()Return the next element from the set.intnextInt()Iterator interface method forhasMoreElements()voidreset(StateSet states)Reset this enumerator/iterator and associate it with a given StateSet.
-
-
-
Field Detail
-
DEBUG
private static final boolean DEBUG
Local compile-time DEBUG flag- See Also:
- Constant Field Values
-
index
private int index
Current index into the StateSet array.index >= bits.lengthindicates that there are no further elements in the set.
-
offset
private int offset
Current offset into the StateSet array
-
mask
private long mask
mask = 1 << offset
-
bits
private long[] bits
Reference to the array of the StateSet to iterate over
-
-
Constructor Detail
-
StateSetEnumerator
public StateSetEnumerator()
Creates a new StateSetEnumerator that is not yet associated with a StateSet.hasMoreElements()andnextElement()will throwNullPointerExceptionwhen used beforereset(StateSet)
-
StateSetEnumerator
public StateSetEnumerator(StateSet states)
Construct a StateSetEnumerator for a given StateSet. This should be the default constructor to use.- Parameters:
states- theStateSetobject to iterate over.- See Also:
StateSet.states()
-
-
Method Detail
-
reset
public void reset(StateSet states)
Reset this enumerator/iterator and associate it with a given StateSet.- Parameters:
states- theStateSetobject to iterate over.
-
advance
private void advance()
Advance to the next element in the set.Precondition: there are more elements in the set.
-
hasMoreElements
public boolean hasMoreElements()
Determine if there are further elements in the set to be returned.- Returns:
- true iff there are more elements in the set.
-
nextElement
public int nextElement()
Return the next element from the set.Precondition:
hasMoreElements()returns true- Returns:
- the next element.
- Throws:
java.util.NoSuchElementException- if there is no further element- See Also:
hasMoreElements()
-
hasNext
public boolean hasNext()
Iterator interface method fornextElement().- Specified by:
hasNextin interfacejava.util.Iterator<java.lang.Integer>
-
nextInt
public int nextInt()
Iterator interface method forhasMoreElements()- Specified by:
nextIntin interfacejava.util.PrimitiveIterator.OfInt
-
-