Commit 049abcfb authored by Colin DAMON's avatar Colin DAMON

Use conversion map for conversions

parent 435dc53b
package fr.ippon.kata.numeral;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.TreeMap;
......@@ -7,15 +8,12 @@ public class Numerals {
private static final NavigableMap<Integer, String> CONVERSIONS = buildConversions();
public static String toRoman(int arabic) {
if (arabic >= 5) {
return "V" + toRoman(arabic - 5);
if (arabic == 0) {
return "";
}
if (arabic == 4) {
return "IV";
}
return "I".repeat(arabic);
Entry<Integer, String> highestKnownConversion = CONVERSIONS.floorEntry(arabic);
return highestKnownConversion.getValue() + toRoman(arabic - highestKnownConversion.getKey());
}
private static NavigableMap<Integer, String> buildConversions() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment