Package org.xcsp.common.enumerations
Class EnumerationAbstract
- java.lang.Object
-
- org.xcsp.common.enumerations.EnumerationAbstract
-
- All Implemented Interfaces:
Iterator<int[]>
- Direct Known Subclasses:
EnumerationCartesian
,EnumerationOfPermutations
public abstract class EnumerationAbstract extends Object implements Iterator<int[]>
This class is the root class for all subclasses allowing us to iterate over combinations, permutations, ...
-
-
Field Summary
Fields Modifier and Type Field Description int[]
currTupleOfIdxs
The current tuple composed of indexes (of values)protected boolean
indexesMatchValues
Indicates if indexes match values (i.e., if the value at indexi
is alwaysi
).protected Boolean
nextTuple
Indicates if the methodhasNext()
has already been called.
-
Constructor Summary
Constructors Constructor Description EnumerationAbstract(int tupleLength, boolean indexesMatchValues)
Builds an object that can be used for enumerating tuples, each of them with the specified length.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
computeFirstTuple()
Computes the first tuple (called at reset time).void
displayAllTuples()
Displays all tuples of this enumeration.void
execute(java.util.function.Consumer<int[]> c)
abstract boolean
hasNext()
int[]
next()
DO NOT MODIFY the tuple that is returned.void
reset()
Resets the object, so as to be able to iterate again over all tuples of the enumeration.int[][]
toArray()
Returns an array with all tuples that can be enumerated.int[][]
toArray(java.util.function.Predicate<int[]> p)
Returns an array with all tuples that can be enumerated while being accepted by the specified predicate.protected abstract int
valAt(int pos)
Returns the value of the current tuple at the specified position.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Field Detail
-
nextTuple
protected Boolean nextTuple
Indicates if the methodhasNext()
has already been called. This is not the case if the value of this field isnull
. Otherwise, the value of this field indicates the presence (Boolean.TRUE
) or the absence (Boolean.FALSE
) of another tuple already computed.
-
currTupleOfIdxs
public final int[] currTupleOfIdxs
The current tuple composed of indexes (of values)
-
indexesMatchValues
protected final boolean indexesMatchValues
Indicates if indexes match values (i.e., if the value at indexi
is alwaysi
).
-
-
Constructor Detail
-
EnumerationAbstract
public EnumerationAbstract(int tupleLength, boolean indexesMatchValues)
Builds an object that can be used for enumerating tuples, each of them with the specified length.- Parameters:
tupleLength
- the length of each tuple in the enumerationindexesMatchValues
-true
iff indexes (of values) and values match, i.e. if the value at indexi
is alwaysi
)
-
-
Method Detail
-
computeFirstTuple
protected abstract void computeFirstTuple()
Computes the first tuple (called at reset time).
-
reset
public void reset()
Resets the object, so as to be able to iterate again over all tuples of the enumeration.
-
valAt
protected abstract int valAt(int pos)
Returns the value of the current tuple at the specified position.- Parameters:
pos
- the position of an integer in the tuple- Returns:
- the value of the current tuple at the specified position
-
next
public int[] next()
DO NOT MODIFY the tuple that is returned.
-
execute
public void execute(java.util.function.Consumer<int[]> c)
-
toArray
public int[][] toArray(java.util.function.Predicate<int[]> p)
Returns an array with all tuples that can be enumerated while being accepted by the specified predicate.- Parameters:
p
- a predicate used to test the tuples in the enumeration- Returns:
- an array with all tuples that can be enumerated while being accepted by the specified predicate
-
toArray
public int[][] toArray()
Returns an array with all tuples that can be enumerated. The array is lexicographically sorted.- Returns:
- an array with all tuples that can be enumerated
-
displayAllTuples
public void displayAllTuples()
Displays all tuples of this enumeration.
-
-