Source:
public boolean isValid(String identifier) throws UnallowedIdentifierException { if (identifier.indexOf("-") <= 0) { throw new UnallowedIdentifierException( "Identifier \"" + identifier + "\" must contain a hyphen followed by a check digit character (A-J)."); } if (identifier.endsWith("-")) { throw new UnallowedIdentifierException( "Identifier \"" + identifier + "\" must not end with a hyphen - a check digit character (A-J) must follow."); } String idWithoutCheckDigit = identifier.substring(0, identifier.indexOf("-")); checkAllowedIdentifier(idWithoutCheckDigit); int computedCheckDigit = getCheckDigit(idWithoutCheckDigit); String checkDigit = identifier.substring(identifier.indexOf("-") + 1, identifier.length()); if (checkDigit.length() != 1) { throw new UnallowedIdentifierException("Identifier must have a check digit of length 1."); } if ("A".equalsIgnoreCase(checkDigit)) { checkDigit = "0"; } if ("B".equalsIgnoreCase(checkDigit)) { checkDigit = "1"; } if ("C".equalsIgnoreCase(checkDigit)) { checkDigit = "2"; } if ("D".equalsIgnoreCase(checkDigit)) { checkDigit = "3"; } if ("E".equalsIgnoreCase(checkDigit)) { checkDigit = "4"; } if ("F".equalsIgnoreCase(checkDigit)) { checkDigit = "5"; } if ("G".equalsIgnoreCase(checkDigit)) { checkDigit = "6"; } if ("H".equalsIgnoreCase(checkDigit)) { checkDigit = "7"; } if ("I".equalsIgnoreCase(checkDigit)) { checkDigit = "8"; } if ("J".equalsIgnoreCase(checkDigit)) { checkDigit = "9"; } int givenCheckDigit = 10; try { givenCheckDigit = Integer.valueOf(checkDigit); } catch (NumberFormatException e) { throw new UnallowedIdentifierException( "Check digit must either be a character from A to J or a single digit integer."); } return (computedCheckDigit == givenCheckDigit); }

Target:
public boolean isValid(String identifier) throws UnallowedIdentifierException { if (identifier.indexOf("-") < 1) { throw new UnallowedIdentifierException( "Identifier \"" + identifier + "\" must contain a hyphen followed by a check digit character (A-J)."); } if (identifier.endsWith("-")) { throw new UnallowedIdentifierException( "Identifier \"" + identifier + "\" must not end with a hyphen - a check digit character (A-J) must follow."); } String idWithoutCheckDigit = identifier.substring(0, identifier.indexOf("-")); checkAllowedIdentifier(idWithoutCheckDigit); int computedCheckDigit = getCheckDigit(idWithoutCheckDigit); String checkDigit = identifier.substring(identifier.indexOf("-") + 1, identifier.length()); if (checkDigit.length() != 1) { throw new UnallowedIdentifierException("Identifier must have a check digit of length 1."); } if ("A".equalsIgnoreCase(checkDigit)) { checkDigit = "0"; } if ("B".equalsIgnoreCase(checkDigit)) { checkDigit = "1"; } if ("C".equalsIgnoreCase(checkDigit)) { checkDigit = "2"; } if ("D".equalsIgnoreCase(checkDigit)) { checkDigit = "3"; } if ("E".equalsIgnoreCase(checkDigit)) { checkDigit = "4"; } if ("F".equalsIgnoreCase(checkDigit)) { checkDigit = "5"; } if ("G".equalsIgnoreCase(checkDigit)) { checkDigit = "6"; } if ("H".equalsIgnoreCase(checkDigit)) { checkDigit = "7"; } if ("I".equalsIgnoreCase(checkDigit)) { checkDigit = "8"; } if ("J".equalsIgnoreCase(checkDigit)) { checkDigit = "9"; } int givenCheckDigit = 10; try { givenCheckDigit = Integer.valueOf(checkDigit); } catch (NumberFormatException e) { throw new UnallowedIdentifierException( "Check digit must either be a character from A to J or a single digit integer."); } return (computedCheckDigit == givenCheckDigit); }