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.OfInt
Enumerates the states of aStateSet
. Also provides an iterator for native int.- Version:
- JFlex 1.8.2
- See Also:
StateSet
-
-
Field Summary
Fields Modifier and Type Field Description private long[]
bits
Reference to the array of the StateSet to iterate overprivate static boolean
DEBUG
Local compile-time DEBUG flagprivate int
index
Current index into the StateSet array.private long
mask
mask = 1 << offset
private int
offset
Current 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 void
advance()
Advance to the next element in the set.boolean
hasMoreElements()
Determine if there are further elements in the set to be returned.boolean
hasNext()
Iterator interface method fornextElement()
.int
nextElement()
Return the next element from the set.int
nextInt()
Iterator interface method forhasMoreElements()
void
reset(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.length
indicates 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 throwNullPointerException
when 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
- theStateSet
object 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
- theStateSet
object 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:
hasNext
in interfacejava.util.Iterator<java.lang.Integer>
-
nextInt
public int nextInt()
Iterator interface method forhasMoreElements()
- Specified by:
nextInt
in interfacejava.util.PrimitiveIterator.OfInt
-
-