@Override protected int toInt(char character, int leftPos, int rightPos) throws CheckDigitException { if (rightPos == 1 && character == 'X') { return 10; // CHECKSTYLE IGNORE MagicNumber } return super.toInt(character, leftPos, rightPos); } }
/** * <p>Convert a character at a specified position to an * integer value.</p> * * <p>Character 'X' check digit converted to 10.</p> * * @param character The character to convert. * @param leftPos The position of the character in the code, counting from left to right * @param rightPos The position of the character in the code, counting from right to left * @return The integer value of the character. * @throws CheckDigitException if an error occurs. */ @Override protected int toInt(char character, int leftPos, int rightPos) throws CheckDigitException { if (rightPos == 1 && character == 'X') { return 10; // CHECKSTYLE IGNORE MagicNumber } return super.toInt(character, leftPos, rightPos); }
/** * Calculate the modulus for a code. * * @param code The code to calculate the modulus for. * @param includesCheckDigit Whether the code includes the Check Digit or not. * @return The modulus value * @throws CheckDigitException if an error occurs calculating the modulus * for the specified code */ protected int calculateModulus(String code, boolean includesCheckDigit) throws CheckDigitException { int total = 0; for (int i = 0; i < code.length(); i++) { int lth = code.length() + (includesCheckDigit ? 0 : 1); int leftPos = i + 1; int rightPos = lth - i; int charValue = toInt(code.charAt(i), leftPos, rightPos); total += weightedValue(charValue, leftPos, rightPos); } if (total == 0) { throw new CheckDigitException("Invalid code, sum is zero"); } return total % modulus; }
@Override protected int toInt(char character, int leftPos, int rightPos) throws CheckDigitException { if (rightPos == 1 && character == 'X') { return 10; // CHECKSTYLE IGNORE MagicNumber } return super.toInt(character, leftPos, rightPos); } }
/** * <p>Convert a character at a specified position to an * integer value.</p> * * <p>Character 'X' check digit converted to 10.</p> * * @param character The character to convert. * @param leftPos The position of the character in the code, counting from left to right * @param rightPos The position of the character in the code, counting from right to left * @return The integer value of the character. * @throws CheckDigitException if an error occurs. */ @Override protected int toInt(char character, int leftPos, int rightPos) throws CheckDigitException { if (rightPos == 1 && character == 'X') { return 10; // CHECKSTYLE IGNORE MagicNumber } return super.toInt(character, leftPos, rightPos); }
/** * <p>Convert a character at a specified position to an * integer value.</p> * * <p>Character 'X' check digit converted to 10.</p> * * @param character The character to convert. * @param leftPos The position of the character in the code, counting from left to right * @param rightPos The position of the character in the code, counting from right to left * @return The integer value of the character. * @throws CheckDigitException if an error occurs. */ protected int toInt(char character, int leftPos, int rightPos) throws CheckDigitException { if (rightPos == 1 && character == 'X') { return 10; } return super.toInt(character, leftPos, rightPos); }
/** * Calculate the modulus for a code. * * @param code The code to calculate the modulus for. * @param includesCheckDigit Whether the code includes the Check Digit or not. * @return The modulus value * @throws CheckDigitException if an error occurs calculating the modulus * for the specified code */ protected int calculateModulus(String code, boolean includesCheckDigit) throws CheckDigitException { int total = 0; for (int i = 0; i < code.length(); i++) { int lth = code.length() + (includesCheckDigit ? 0 : 1); int leftPos = i + 1; int rightPos = lth - i; int charValue = toInt(code.charAt(i), leftPos, rightPos); total += weightedValue(charValue, leftPos, rightPos); } if (total == 0) { throw new CheckDigitException("Invalid code, sum is zero"); } return total % modulus; }
/** * Calculate the modulus for a code. * * @param code The code to calculate the modulus for. * @param includesCheckDigit Whether the code includes the Check Digit or not. * @return The modulus value * @throws CheckDigitException if an error occurs calculating the modulus * for the specified code */ protected int calculateModulus(String code, boolean includesCheckDigit) throws CheckDigitException { int total = 0; for (int i = 0; i < code.length(); i++) { int lth = code.length() + (includesCheckDigit ? 0 : 1); int leftPos = i + 1; int rightPos = lth - i; int charValue = toInt(code.charAt(i), leftPos, rightPos); total += weightedValue(charValue, leftPos, rightPos); } if (total == 0) { throw new CheckDigitException("Invalid code, sum is zero"); } return total % modulus; }
/** * Calculate the modulus for a code. * * @param code The code to calculate the modulus for. * @param includesCheckDigit Whether the code includes the Check Digit or not. * @return The modulus value * @throws CheckDigitException if an error occurs calculating the modulus * for the specified code */ protected int calculateModulus(String code, boolean includesCheckDigit) throws CheckDigitException { int total = 0; for (int i = 0; i < code.length(); i++) { int lth = code.length() + (includesCheckDigit ? 0 : 1); int leftPos = i + 1; int rightPos = lth - i; int charValue = toInt(code.charAt(i), leftPos, rightPos); total += weightedValue(charValue, leftPos, rightPos); } if (total == 0) { throw new CheckDigitException("Invalid code, sum is zero"); } return total % modulus; }