Created
August 19, 2014 16:04
-
-
Save vemacs/463e8914d7319bfb17c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.collect.BiMap; | |
import com.google.common.collect.ImmutableBiMap; | |
public class RomanNumerals { | |
private static final BiMap<String, Integer> ROMAN_INT_MAP = new ImmutableBiMap.Builder<String, Integer>() | |
.put("i", 1) | |
.put("ii", 2) | |
.put("iii", 3) | |
.put("iv", 4) | |
.put("v", 5) | |
.put("vi", 6) | |
.put("vii", 7) | |
.put("viii", 8) | |
.put("ix", 9) | |
.put("x", 10) | |
.build(); | |
public static int intFromRomanString(String roman) { | |
return ROMAN_INT_MAP.get(roman.toLowerCase()); | |
} | |
public static String romanStringFromInt(int integer) { | |
return ROMAN_INT_MAP.inverse().get(integer).toUpperCase(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment