Class CombinationUtil


  • public final class CombinationUtil
    extends Object
    Common utilities used for integer array which represent combinations or test inputs. All combinations are represented by an array containing the value indexes for each parameter. This means the parameters are 0 through array length minus one. For example, if the first parameter is set to its first value, and the second one to its third value, the resulting array would look like this. [0, 2]. If a parameter does not have a value in a combination, this is represented via NO_VALUE.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int NO_VALUE
      The value used to indicate that a parameter has not been assigned a value in a combination.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void add​(int[] combination, int[] toBeAdded)
      Adds the combination to be added to the first one.
      static boolean canBeAdded​(int[] combination, int[] toBeAdded, ConstraintChecker constraintChecker)
      Checks whether the combinations to be added can be added to the given combinations.
      static boolean contains​(int[] firstCombination, int[] secondCombination)
      Checks whether the first combinations contains the second one.
      static boolean containsAllParameters​(int[] combination, int untilParameter)
      Checks whether all the combination contains all parameters until the given index, that is whether all fields in the combination array until the index are not set to NO_VALUE.
      static boolean containsAllParameters​(int[] combination, it.unimi.dsi.fastutil.ints.IntSet parameterIndices)
      Checks whether a combinations contains all parameter, that is whether the field for all given parameters is not set to NO_VALUE.
      static int[] emptyCombination​(int size)
      Creates a new combinations which is empty.
      static int numberOfSetParameters​(int[] combination)
      Calculates the number of parameters in the combinations not set to NO_VALUE.
      static boolean sameForAllGivenParameters​(int[] first, int[] second, it.unimi.dsi.fastutil.ints.IntSet parameters)
      Checks whether the two combinations have exactly the same value for each of the given parameters.
    • Field Detail

      • NO_VALUE

        public static final int NO_VALUE
        The value used to indicate that a parameter has not been assigned a value in a combination.
        See Also:
        Constant Field Values
    • Method Detail

      • emptyCombination

        public static int[] emptyCombination​(int size)
        Creates a new combinations which is empty. A combinations is empty if no parameter has a set value, so each entry of the returned array is NO_VALUE. For example, for the size 5, [-1, -1, -1, -1, -1] is returned.
        Parameters:
        size - the number of parameters for the combinations. Must be greater that or equal to zero
        Returns:
        a combination with the given number of parameters all set to NO_VALUE
      • contains

        public static boolean contains​(int[] firstCombination,
                                       int[] secondCombination)
        Checks whether the first combinations contains the second one. The contains relation is defined as follows: A combination contains another combination if it has the same values for all values which are set in the other combination. Here is a list of two example combinations and a value for stating whether the first one contains the second one: [0] [-1] true [-1] [0] false [0] [0] true [-1] [-1] true Both combinations need to be of the same length.
        Parameters:
        firstCombination - a combination. Must not be null
        secondCombination - a combination for which it is checked whether it is contained in the first one. Must not be null and must be of the same size as the first combination
        Returns:
        whether the second combination is contained in the first one as defined by the rules above
      • canBeAdded

        public static boolean canBeAdded​(int[] combination,
                                         int[] toBeAdded,
                                         ConstraintChecker constraintChecker)
        Checks whether the combinations to be added can be added to the given combinations. A combination can added if it either has the exact same value for each index, or another value iff the original combination's value at that position has not been set, or the other value is the empty value. Examples: [0] [0] true [-1] [0] true [0] [-1] true [-1] [-1] true [0] [1] false [0, -1] [0, 1] true Both combinations have to be of the same length. It is further checked whether the resulting combination would satisfy the given constraints checker.
        Parameters:
        combination - a combination. Must not be null
        toBeAdded - another combination which should be added to the first one. Must not be null and must be of the same size as the first combination
        constraintChecker - checks whether the result combination would be valid. Must not be null. If this is not important, pass a NoConstraintChecker
        Returns:
        whether the combination to be added can be added according to the rules explained above
      • add

        public static void add​(int[] combination,
                               int[] toBeAdded)
        Adds the combination to be added to the first one. This means all values in the first combination are overwritten except if the ones which would be overwriting are NO_VALUE. canBeAdded(int[], int[], ConstraintChecker) would return true for both combinations if the result combinations only differs form the first given combinations in places where it was NO_VALUE. Examples: [0] [-1] becomes [0] [-1] [0] becomes [0] [0, -1, 2, -1] [-1, 2, 2, -1] becomes [0, 2, 2, -1]
        Parameters:
        combination - a combination. Must not be null
        toBeAdded - another combination which is added to the first one using the rules explained above. Must not be null and must be the same length as the first combination
      • containsAllParameters

        public static boolean containsAllParameters​(int[] combination,
                                                    it.unimi.dsi.fastutil.ints.IntSet parameterIndices)
        Checks whether a combinations contains all parameter, that is whether the field for all given parameters is not set to NO_VALUE.
        Parameters:
        combination - the combination. Must not be null
        parameterIndices - the parameter to check. Must not be null but can be empty
        Returns:
        whether the given combination contains all parameters
      • containsAllParameters

        public static boolean containsAllParameters​(int[] combination,
                                                    int untilParameter)
        Checks whether all the combination contains all parameters until the given index, that is whether all fields in the combination array until the index are not set to NO_VALUE.
        Parameters:
        combination - a combination
        untilParameter - the parameter index until which to check (inclusively
        Returns:
        whether the combinations does not have NO_VALUE on any given parameter index
      • sameForAllGivenParameters

        public static boolean sameForAllGivenParameters​(int[] first,
                                                        int[] second,
                                                        it.unimi.dsi.fastutil.ints.IntSet parameters)
        Checks whether the two combinations have exactly the same value for each of the given parameters.
        Parameters:
        first - a combination. Must not be null
        second - another combination. Must not be null and must be the same length as the first combination
        parameters - the parameters to check (indices)
        Returns:
        whether both combinations have the given parameters set to the same value
      • numberOfSetParameters

        public static int numberOfSetParameters​(int[] combination)
        Calculates the number of parameters in the combinations not set to NO_VALUE.
        Parameters:
        combination - a combination. Most not be null
        Returns:
        the number of parameters in the combination not set