@Test(expected = IllegalArgumentException.class) public void testInvalidNumber1() { Validator.validate("IIII"); }
public static void validate(final String romanNumber) { if (romanNumber == null || romanNumber.trim().length() == 0) { throw new IllegalArgumentException(romanNumber + " is not a valid Roman number."); } final int len = romanNumber.length(); char currentChar = '\u0000'; for (int index = 0; index < len; index++) { currentChar = Character.toUpperCase(romanNumber.charAt(index)); if (romanNumber.toUpperCase().matches( Character.toUpperCase(currentChar) + "{" + (repeatMap.get(currentChar) + 1) + ",}")) { throw new IllegalArgumentException(currentChar + " can not be repeated more than " + repeatMap.get(currentChar) + " times in succession."); } } }
Validator { public static void validate(final String romanNumber) { if (romanNumber == null || romanNumber.trim().length() == 0) { throw new IllegalArgumentException(romanNumber + " is not a valid Roman number."); } final int len = romanNumber.length(); char currentChar = '\u0000'; for (int index = 0; index < len; index++) { currentChar = Character.toUpperCase(romanNumber.charAt(index)); if (romanNumber.toUpperCase().matches( Character.toUpperCase(currentChar) + "{" + (repeatMap.get(currentChar) + 1) + ",}")) { throw new IllegalArgumentException(currentChar + " can not be repeated more than " + repeatMap.get(currentChar) + " times in succession."); } } } }
Validator { public static void validate(final String romanNumber) { if (romanNumber == null || romanNumber.trim().length() == 0) { throw new IllegalArgumentException(romanNumber + " is not a valid Roman number."); } final int len = romanNumber.length(); char currentChar = '\u0000'; for (int index = 0; index < len; index++) { currentChar = Character.toUpperCase(romanNumber.charAt(index)); if (romanNumber.toUpperCase().matches( Character.toUpperCase(currentChar) + "{" + (repeatMap.get(currentChar) + 1) + ",}")) { throw new IllegalArgumentException(currentChar + " can not be repeated more than " + repeatMap.get(currentChar) + " times in succession."); } } }  }
Validator { public static void validate(final String romanNumber) { if (romanNumber == null || romanNumber.trim().length() == 0) { throw new IllegalArgumentException(romanNumber + " is not a valid Roman number."); } final int len = romanNumber.length(); char currentChar = '\u0000'; for (int index = 0; index < len; index++) { currentChar = Character.toUpperCase(romanNumber.charAt(index)); if (romanNumber.toUpperCase().matches( Character.toUpperCase(currentChar) + "{" + (repeatMap.get(currentChar) + 1) + ",}")) { throw new IllegalArgumentException(currentChar + " can not be repeated more than " + repeatMap.get(currentChar) + " times in succession."); } } }  static void validate(final String romanNumber); }
Validator { public static void validate(final String romanNumber) { if (romanNumber == null || romanNumber.trim().length() == 0) { throw new IllegalArgumentException(romanNumber + " is not a valid Roman number."); } final int len = romanNumber.length(); char currentChar = '\u0000'; for (int index = 0; index < len; index++) { currentChar = Character.toUpperCase(romanNumber.charAt(index)); if (romanNumber.toUpperCase().matches( Character.toUpperCase(currentChar) + "{" + (repeatMap.get(currentChar) + 1) + ",}")) { throw new IllegalArgumentException(currentChar + " can not be repeated more than " + repeatMap.get(currentChar) + " times in succession."); } } }  static void validate(final String romanNumber); static final Map<Character, Integer> repeatMap; }