Example usage for org.apache.commons.validator.routines.checkdigit CheckDigitException CheckDigitException

List of usage examples for org.apache.commons.validator.routines.checkdigit CheckDigitException CheckDigitException

Introduction

In this page you can find the example usage for org.apache.commons.validator.routines.checkdigit CheckDigitException CheckDigitException.

Prototype

public CheckDigitException(String msg) 

Source Link

Document

Construct an Exception with a message.

Usage

From source file:be.fgov.minfin.webForm.util.ISINValidationUtil.java

public int calculcateModulus(String code, boolean includesCheckDigit) throws CheckDigitException {
    StringBuilder transformed = new StringBuilder(code.length() * 2);
    if (includesCheckDigit) {
        char checkDigit = code.charAt(code.length() - 1); // Choppe le dernier caractre
        if (!Character.isDigit(checkDigit)) {
            throw new CheckDigitException("Invalid checkdigit[" + checkDigit + "] in " + code);
        }//from www  . j a  v  a2s  .  co  m
    }
    for (int i = 0; i < code.length(); i++) {
        int charValue = Character.getNumericValue(code.charAt(i));
        if (charValue < 0 || charValue > 35) {
            throw new CheckDigitException("Invalid Character[" + (i + 1) + "] = '" + charValue + "'");
        }
        transformed.append(charValue);
    }
    //Doit retourner 0 pour que ce soit valide
    return super.calculateModulus(transformed.toString(), includesCheckDigit);
}