/** * Validate the Verhoeff <i>Check Digit</i> for a code. * * @param code The code to validate * @return <code>true</code> if the check digit is valid, * otherwise <code>false</code> */ @Override public boolean isValid(String code) { if (code == null || code.length() == 0) { return false; } try { return (calculateChecksum(code, true) == 0); } catch (CheckDigitException e) { return false; } }
/** * Calculate a Verhoeff <i>Check Digit</i> for a code. * * @param code The code to calculate the Check Digit for * @return The calculated Check Digit * @throws CheckDigitException if an error occurs calculating * the check digit for the specified code */ @Override public String calculate(String code) throws CheckDigitException { if (code == null || code.length() == 0) { throw new CheckDigitException("Code is missing"); } int checksum = calculateChecksum(code, false); return Integer.toString(INV_TABLE[checksum]); }
/** * Validate the Verhoeff <i>Check Digit</i> for a code. * * @param code The code to validate * @return <code>true</code> if the check digit is valid, * otherwise <code>false</code> */ @Override public boolean isValid(String code) { if (code == null || code.length() == 0) { return false; } try { return (calculateChecksum(code, true) == 0); } catch (CheckDigitException e) { return false; } }
/** * Calculate a Verhoeff <i>Check Digit</i> for a code. * * @param code The code to calculate the Check Digit for * @return The calculated Check Digit * @throws CheckDigitException if an error occurs calculating * the check digit for the specified code */ @Override public String calculate(String code) throws CheckDigitException { if (code == null || code.length() == 0) { throw new CheckDigitException("Code is missing"); } int checksum = calculateChecksum(code, false); return Integer.toString(INV_TABLE[checksum]); }