Class ModUtil


  • public final class ModUtil
    extends Object
    Helper class for modulo 10/11.
    Author:
    Hardy Ferentschik
    • Method Detail

      • calculateLuhnMod10Check

        public static int calculateLuhnMod10Check​(List<Integer> digits)
        Calculate Luhn Modulo 10 checksum (Luhn algorithm implementation)
        Parameters:
        digits - The digits over which to calculate the checksum
        Returns:
        the result of the mod10 checksum calculation
      • calculateMod10Check

        public static int calculateMod10Check​(List<Integer> digits,
                                              int multiplier,
                                              int weight)
        Calculate Generic Modulo 10 checksum
        Parameters:
        digits - The digits over which to calculate the checksum
        multiplier - Multiplier used for the odd digits in the algorithm
        weight - Multiplier used for the even digits in the algorithm
        Returns:
        the result of the mod10 checksum calculation
      • calculateMod11Check

        public static int calculateMod11Check​(List<Integer> digits,
                                              int threshold)
        Calculate Modulo 11 checksum
        Parameters:
        digits - the digits for which to calculate the checksum
        threshold - the threshold for the Mod11 algorithm multiplier growth
        Returns:
        the result of the mod11 checksum calculation
      • calculateMod11Check

        public static int calculateMod11Check​(List<Integer> digits)
        Calculate Modulo 11 checksum assuming that the threshold is Integer.MAX_VALUE
        Parameters:
        digits - the digits for which to calculate the checksum
        Returns:
        the result of the mod11 checksum calculation
      • calculateModXCheckWithWeights

        public static int calculateModXCheckWithWeights​(List<Integer> digits,
                                                        int moduloParam,
                                                        int threshold,
                                                        int... weights)
        Calculate Modulo moduloParam checksum with given weights. If no weights are provided then weights similar to Modulo 11 checksum will be used. In case when there will be not enough weights provided the ones provided will be used in a looped manner.
        Parameters:
        digits - the digits for which to calculate the checksum
        moduloParam - modulo parameter to be used
        weights - weights for the sum.
        Returns:
        the result of mod checksum calculation