Commit 5cabb1e6 authored by Colin DAMON's avatar Colin DAMON
Browse files

Inline optional

parent 3f286ab8
......@@ -4,13 +4,17 @@ import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.Optional;
import java.util.TreeMap;
import java.util.function.Function;
public class Numerals {
private static final NavigableMap<Integer, String> CONVERSIONS = buildConversions();
public static String toRoman(int arabic) {
Optional<Entry<Integer, String>> highestKnownConversion = Optional.ofNullable(CONVERSIONS.floorEntry(arabic));
return highestKnownConversion.map(conversion -> conversion.getValue() + toRoman(arabic - conversion.getKey())).orElse("");
return Optional.ofNullable(CONVERSIONS.floorEntry(arabic)).map(romanRepresentation(arabic)).orElse("");
}
private static Function<Entry<Integer, String>, String> romanRepresentation(int arabic) {
return conversion -> conversion.getValue() + toRoman(arabic - conversion.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