class CheckDigitLuhnMod10Verifier implements CheckDigitVerifier {

    public boolean isValid(String id) {

        int currentDigit;
        int idSum = 0;
        int position = 0; //the current position number (to calc odd/even proc)

        for (int i = id.length() - 1; i >= 0; i--) {
            //get the current rightmost digit from the string
            String idCurrentRightmostDigit = id.substring(i, i + 1);

            //parse to int the current rightmost digit, if fail return false (not-valid id)
            try {
                currentDigit = Integer.parseInt(idCurrentRightmostDigit);
            } catch (NumberFormatException e) {
                return false;
            }

            // double value of every 2nd rightmost digit
            // if value 2 digits (for example: 18 ),
            // then sum the digits (made easy by subtracting 9, for example, 18 -> 1+8 = 9, same as 18-9 = 9)
            if (position % 2 != 0) {
                currentDigit *= 2;
                if (currentDigit > 9)
                    currentDigit -= 9;
            }
            position++; //increase the proc number

            //summarize the processed digits
            idSum += currentDigit;
        }

        //if digits sum is exactly divisible by 10, return true (valid), else false (not-valid)
        return (idSum % 10 == 0);
    }

    private  CheckDigitLuhnMod10Verifier();

}