Class GCodedSequencesGenerator

java.lang.Object
com.glitchybyte.glib.combinatorics.GCodedSequencesGenerator
All Implemented Interfaces:
Iterable<int[]>
Direct Known Subclasses:
GCodedCombinations, GCodedPermutations

public abstract class GCodedSequencesGenerator extends Object implements Iterable<int[]>
Abstract coded sequence generator.

The code itself is a sequence of indexes.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final boolean
    Whether to allow duplicate items in a sequence.
    final int
    Number of items.
    final int
    Maximum size of a sequence.
    final int
    Minimum size of a sequence.
  • Constructor Summary

    Constructors
    Constructor
    Description
    GCodedSequencesGenerator(int itemCount, boolean allowDuplicateItems)
    Creates a coded sequence generator of a size equal to itemCount.
    GCodedSequencesGenerator(int itemCount, boolean allowDuplicateItems, int minSize, int maxSize)
    Creates a coded sequence generator with an iterator with the given characteristics.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract boolean
    incCode(int[] code)
    Increases the code one step.
    Iterator<int[]>
    Returns an iterator over elements of type int[].

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Field Details

    • itemCount

      public final int itemCount
      Number of items.
    • allowDuplicateItems

      public final boolean allowDuplicateItems
      Whether to allow duplicate items in a sequence.
    • minSize

      public final int minSize
      Minimum size of a sequence.
    • maxSize

      public final int maxSize
      Maximum 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 - true if 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 to itemCount.
      Parameters:
      itemCount - Number of unique items.
      allowDuplicateItems - true if a sequence can use the same item more than once.
  • Method Details

    • iterator

      public Iterator<int[]> iterator()
      Returns an iterator over elements of type int[].
      Specified by:
      iterator in interface Iterable<int[]>
      Returns:
      Iterator.
    • 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:
      true if code was increased.