@Test public void romanNumberTest() { Assert.assertEquals(-1, TurkishNumbers.romanToDecimal("foo")); Assert.assertEquals(-1, TurkishNumbers.romanToDecimal("IIIIIII")); Assert.assertEquals(1987, TurkishNumbers.romanToDecimal("MCMLXXXVII")); }
public static int romanToDecimal(String s) { if (s == null || s.isEmpty() || !romanNumeralPattern.matcher(s).matches()) { return -1; } final Matcher matcher = Pattern.compile("M|CM|D|CD|C|XC|L|XL|X|IX|V|IV|I").matcher(s); final int[] decimalValues = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; final String[] romanNumerals = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; int result = 0; while (matcher.find()) { for (int i = 0; i < romanNumerals.length; i++) { if (romanNumerals[i].equals(matcher.group(0))) { result += decimalValues[i]; } } } return result; }
TurkishNumbers { public static int romanToDecimal(String s) { if (s == null || s.isEmpty() || !romanNumeralPattern.matcher(s).matches()) { return -1; } final Matcher matcher = Pattern.compile("M|CM|D|CD|C|XC|L|XL|X|IX|V|IV|I").matcher(s); final int[] decimalValues = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; final String[] romanNumerals = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; int result = 0; while (matcher.find()) { for (int i = 0; i < romanNumerals.length; i++) { if (romanNumerals[i].equals(matcher.group(0))) { result += decimalValues[i]; } } } return result; } }
TurkishNumbers { public static int romanToDecimal(String s) { if (s == null || s.isEmpty() || !romanNumeralPattern.matcher(s).matches()) { return -1; } final Matcher matcher = Pattern.compile("M|CM|D|CD|C|XC|L|XL|X|IX|V|IV|I").matcher(s); final int[] decimalValues = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; final String[] romanNumerals = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; int result = 0; while (matcher.find()) { for (int i = 0; i < romanNumerals.length; i++) { if (romanNumerals[i].equals(matcher.group(0))) { result += decimalValues[i]; } } } return result; }  }
TurkishNumbers { public static int romanToDecimal(String s) { if (s == null || s.isEmpty() || !romanNumeralPattern.matcher(s).matches()) { return -1; } final Matcher matcher = Pattern.compile("M|CM|D|CD|C|XC|L|XL|X|IX|V|IV|I").matcher(s); final int[] decimalValues = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; final String[] romanNumerals = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; int result = 0; while (matcher.find()) { for (int i = 0; i < romanNumerals.length; i++) { if (romanNumerals[i].equals(matcher.group(0))) { result += decimalValues[i]; } } } return result; }  static Map<String, String> getOrdinalMap(); static String convertToString(long input); static String convertNumberToString(String input); static long singleWordNumberValue(String word); static List<String> replaceNumberStrings(List<String> inputSequence); static List<String> seperateConnectedNumbers(List<String> inputSequence); static List<String> seperateConnectedNumbers(String input); static long convertToNumber(String... words); static long convertToNumber(String text); static String convertOrdinalNumberString(String input); static List<String> separateNumbers(String s); static String getOrdinal(String input); static boolean hasNumber(String s); static boolean hasOnlyNumber(String s); static int romanToDecimal(String s); }
TurkishNumbers { public static int romanToDecimal(String s) { if (s == null || s.isEmpty() || !romanNumeralPattern.matcher(s).matches()) { return -1; } final Matcher matcher = Pattern.compile("M|CM|D|CD|C|XC|L|XL|X|IX|V|IV|I").matcher(s); final int[] decimalValues = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; final String[] romanNumerals = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; int result = 0; while (matcher.find()) { for (int i = 0; i < romanNumerals.length; i++) { if (romanNumerals[i].equals(matcher.group(0))) { result += decimalValues[i]; } } } return result; }  static Map<String, String> getOrdinalMap(); static String convertToString(long input); static String convertNumberToString(String input); static long singleWordNumberValue(String word); static List<String> replaceNumberStrings(List<String> inputSequence); static List<String> seperateConnectedNumbers(List<String> inputSequence); static List<String> seperateConnectedNumbers(String input); static long convertToNumber(String... words); static long convertToNumber(String text); static String convertOrdinalNumberString(String input); static List<String> separateNumbers(String s); static String getOrdinal(String input); static boolean hasNumber(String s); static boolean hasOnlyNumber(String s); static int romanToDecimal(String s); static final long MAX_NUMBER; static final long MIN_NUMBER; }