Skip to content
Snippets Groups Projects
Commit 049abcfb authored by Colin DAMON's avatar Colin DAMON
Browse files

Use conversion map for conversions

parent 435dc53b
No related branches found
No related tags found
1 merge request!37Resolve "TCR Roman Numerals"
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() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment