Class ModUtil
java.lang.Object
org.hibernate.validator.internal.util.ModUtil
Helper class for modulo 10/11.
- Author:
- Hardy Ferentschik
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
calculateLuhnMod10Check
(List<Integer> digits) Calculate Luhn Modulo 10 checksum (Luhn algorithm implementation)static int
calculateMod10Check
(List<Integer> digits, int multiplier, int weight) Calculate Generic Modulo 10 checksumstatic int
calculateMod11Check
(List<Integer> digits) Calculate Modulo 11 checksum assuming that the threshold is Integer.MAX_VALUEstatic int
calculateMod11Check
(List<Integer> digits, int threshold) Calculate Modulo 11 checksumstatic int
calculateModXCheckWithWeights
(List<Integer> digits, int moduloParam, int threshold, int... weights) Calculate ModulomoduloParam
checksum with given weights.
-
Method Details
-
calculateLuhnMod10Check
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
Calculate Generic Modulo 10 checksum- Parameters:
digits
- The digits over which to calculate the checksummultiplier
- Multiplier used for the odd digits in the algorithmweight
- Multiplier used for the even digits in the algorithm- Returns:
- the result of the mod10 checksum calculation
-
calculateMod11Check
Calculate Modulo 11 checksum- Parameters:
digits
- the digits for which to calculate the checksumthreshold
- the threshold for the Mod11 algorithm multiplier growth- Returns:
- the result of the mod11 checksum calculation
-
calculateMod11Check
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 ModulomoduloParam
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 checksummoduloParam
- modulo parameter to be usedweights
- weights for the sum.- Returns:
- the result of mod checksum calculation
-