Class Combinations.LexicographicComparator

java.lang.Object
org.apache.commons.numbers.combinatorics.Combinations.LexicographicComparator
All Implemented Interfaces:
java.io.Serializable, java.util.Comparator<int[]>
Enclosing class:
Combinations

public static class Combinations.LexicographicComparator
extends java.lang.Object
implements java.util.Comparator<int[]>, java.io.Serializable
Defines a lexicographic ordering of the combinations. The comparison is based on the value (in base 10) represented by the digit (interpreted in base n) in the input array, in reverse order. For example if c is {3, 2, 1}, and n is 3, the method will return 18.
See Also:
Serialized Form
  • Constructor Summary

    Constructors 
    Constructor Description
    LexicographicComparator​(int n, int k)  
  • Method Summary

    Modifier and Type Method Description
    int compare​(int[] c1, int[] c2)
    int getK()
    Gets the number of elements in each combination.
    int getN()
    Gets the size of the set from which combinations are drawn.

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface java.util.Comparator

    equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
  • Constructor Details

    • LexicographicComparator

      public LexicographicComparator​(int n, int k)
      Parameters:
      n - Size of the set from which subsets are selected.
      k - Size of the subsets to be enumerated.
  • Method Details

    • getN

      public int getN()
      Gets the size of the set from which combinations are drawn.
      Returns:
      the size of the universe.
    • getK

      public int getK()
      Gets the number of elements in each combination.
      Returns:
      the size of the subsets.
    • compare

      public int compare​(int[] c1, int[] c2)
      Specified by:
      compare in interface java.util.Comparator<int[]>
      Throws:
      java.lang.IllegalArgumentException - if the array lengths are not equal to k.
      java.lang.IllegalArgumentException - if an element of the array is not within the interval [0, n).