Commit 3f286ab8 authored by Colin DAMON's avatar Colin DAMON
Browse files

Delete initial zero condition

parent e3612d12
...@@ -2,18 +2,15 @@ package fr.ippon.kata.numeral; ...@@ -2,18 +2,15 @@ package fr.ippon.kata.numeral;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.NavigableMap; import java.util.NavigableMap;
import java.util.Optional;
import java.util.TreeMap; import java.util.TreeMap;
public class Numerals { public class Numerals {
private static final NavigableMap<Integer, String> CONVERSIONS = buildConversions(); private static final NavigableMap<Integer, String> CONVERSIONS = buildConversions();
public static String toRoman(int arabic) { public static String toRoman(int arabic) {
if (arabic == 0) { Optional<Entry<Integer, String>> highestKnownConversion = Optional.ofNullable(CONVERSIONS.floorEntry(arabic));
return ""; return highestKnownConversion.map(conversion -> conversion.getValue() + toRoman(arabic - conversion.getKey())).orElse("");
}
Entry<Integer, String> highestKnownConversion = CONVERSIONS.floorEntry(arabic);
return highestKnownConversion.getValue() + toRoman(arabic - highestKnownConversion.getKey());
} }
private static NavigableMap<Integer, String> buildConversions() { 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