Class RomanNumeral
java.lang.Object
net.okapia.osid.torrefacto.util.RomanNumeral
Conversions between non-negative integers and Roman numerals. Zero
is written as
N (the medieval nulla), since the
Romans had no symbol for it.
Decoding is strict: only canonical numerals are accepted, so
non-standard forms such as IIII, VV, or
IC are rejected even though their additive value could
be guessed.-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
RomanNumeral
public RomanNumeral()Constructs a newRomanNumeral.
-
-
Method Details
-
toRoman
Encodes a non-negative integer as a Roman numeral, e.g. 14 as"XIV". Zero is encoded asN.- Parameters:
number- the number to encode, zero or greater- Returns:
- the Roman numeral
- Throws:
InvalidArgumentException-numberis negative
-
fromRoman
Decodes a Roman numeral to its integer value, e.g."XIV"to 14.Nis zero. The string is trimmed and matched case-insensitively. The decoded value is re-encoded and compared, so non-canonical forms (IIII,VV,IC) are rejected.- Parameters:
roman- a valid Roman numeral- Returns:
- the integer value, zero or greater
- Throws:
InvalidArgumentException-romanis not a valid Roman numeralNullArgumentException-romanisnull
-