Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
twitch
live-coding-fr
Commits
049abcfb
Commit
049abcfb
authored
Nov 24, 2020
by
Colin DAMON
Browse files
Use conversion map for conversions
parent
435dc53b
Changes
1
Hide whitespace changes
Inline
Side-by-side
tcr-roman-numerals/src/main/java/fr/ippon/kata/numeral/Numerals.java
View file @
049abcfb
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
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment