Class RomanNumeral

java.lang.Object
net.okapia.osid.torrefacto.util.RomanNumeral

public class RomanNumeral extends Object
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 Details

    • RomanNumeral

      public RomanNumeral()
      Constructs a new RomanNumeral.
  • Method Details

    • toRoman

      public static String toRoman(long number)
      Encodes a non-negative integer as a Roman numeral, e.g. 14 as "XIV". Zero is encoded as N.
      Parameters:
      number - the number to encode, zero or greater
      Returns:
      the Roman numeral
      Throws:
      InvalidArgumentException - number is negative
    • fromRoman

      public static long fromRoman(String roman)
      Decodes a Roman numeral to its integer value, e.g. "XIV" to 14. N is 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 - roman is not a valid Roman numeral
      NullArgumentException - roman is null