Class GCodedSequencesGenerator
java.lang.Object
com.glitchybyte.glib.combinatorics.GCodedSequencesGenerator
- All Implemented Interfaces:
Iterable<int[]>
- Direct Known Subclasses:
GCodedCombinations,GCodedPermutations
Abstract coded sequence generator.
The code itself is a sequence of indexes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal booleanWhether to allow duplicate items in a sequence.final intNumber of items.final intMaximum size of a sequence.final intMinimum size of a sequence. -
Constructor Summary
ConstructorsConstructorDescriptionGCodedSequencesGenerator(int itemCount, boolean allowDuplicateItems) Creates a coded sequence generator of a size equal toitemCount.GCodedSequencesGenerator(int itemCount, boolean allowDuplicateItems, int minSize, int maxSize) Creates a coded sequence generator with an iterator with the given characteristics. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
itemCount
public final int itemCountNumber of items. -
allowDuplicateItems
public final boolean allowDuplicateItemsWhether to allow duplicate items in a sequence. -
minSize
public final int minSizeMinimum size of a sequence. -
maxSize
public final int maxSizeMaximum size of a sequence.
-
-
Constructor Details
-
GCodedSequencesGenerator
public GCodedSequencesGenerator(int itemCount, boolean allowDuplicateItems, int minSize, int maxSize) Creates a coded sequence generator with an iterator with the given characteristics.- Parameters:
itemCount- Number of unique items.allowDuplicateItems-trueif a sequence can use the same item more than once.minSize- Minimum size of a sequence.maxSize- Maximum size of a sequence.
-
GCodedSequencesGenerator
public GCodedSequencesGenerator(int itemCount, boolean allowDuplicateItems) Creates a coded sequence generator of a size equal toitemCount.- Parameters:
itemCount- Number of unique items.allowDuplicateItems-trueif a sequence can use the same item more than once.
-
-
Method Details
-
iterator
Returns an iterator over elements of typeint[]. -
incCode
protected abstract boolean incCode(int[] code) Increases the code one step.Implementations do not need to worry about
allowDuplicateItems. The iterator will check that and requests another one as necessary.- Parameters:
code- Current code.- Returns:
trueif code was increased.
-