All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.mitre.tjt.text.RomanNumberFormat

org.mitre.tjt.text.RomanNumberFormat

public class RomanNumberFormat
This class implements a NumberFormat that generates Roman Numerals that represent the integer value provided.

Author:
Tim Taylor

Variable Index

 o C
value of 100
 o D
value of 500
 o I
value of 1
 o L
value of 50
 o M
value of 1000
 o V
value of 5
 o X
value of 10

Constructor Index

 o RomanNumberFormat(boolean)
Creates a new RomanNumberSequence object.

Method Index

 o format(double, StringBuffer, FieldPosition)
Formats the provided double as a Roman Number by converting to a long.
 o format(long, StringBuffer, FieldPosition)
Formats the provided long as a Roman Number.
 o main(String[])
This method is for testing the class.
 o parse(String, ParsePosition)
Parses a string containing a number expressed in Roman Numerals and converts it to a Number.

Variables

 o I
 public static final int I
value of 1

 o V
 public static final int V
value of 5

 o X
 public static final int X
value of 10

 o L
 public static final int L
value of 50

 o C
 public static final int C
value of 100

 o D
 public static final int D
value of 500

 o M
 public static final int M
value of 1000

Constructors

 o RomanNumberFormat
 public RomanNumberFormat(boolean upperCase)
Creates a new RomanNumberSequence object. The formats generated by this object will use uppercase letters if upperCase is true, lower case otherwise.

Parameters:
upperCase - True if the format methods should use upper case letters, (ie: IX). If false, lowercase letters will be used.

Methods

 o format
 public StringBuffer format(double number,
                            StringBuffer result,
                            FieldPosition fieldPosition)
Formats the provided double as a Roman Number by converting to a long. Loss of precision may result, however, Roman Numbers don't have fractions.

Parameters:
number - The number to format as a Roman Number.
result - The StringBuffer to write the formated number to.
fieldPosition - The field position in the result.
Returns:
The StringBuffer provided in result with the formated value of number appended.
 o format
 public StringBuffer format(long number,
                            StringBuffer result,
                            FieldPosition fieldPosition)
Formats the provided long as a Roman Number.

Parameters:
number - The number to format as a Roman Number.
result - The StringBuffer to write the formated number to.
fieldPosition - The field position in the result.
Returns:
The StringBuffer provided in result with the formated value of number appended.
 o parse
 public Number parse(String text,
                     ParsePosition parsePosition)
Parses a string containing a number expressed in Roman Numerals and converts it to a Number. The parsePosition will be set to the character following the last character parsed.

Parameters:
text - The string to parse the number from.
parsePosition - On input, contains the position in text to start parse at. On return, contains the position that caused parsing to stop.
Returns:
The parsed number. This will be an instance of java.lang.Long.
 o main
 public static void main(String args[]) throws Exception
This method is for testing the class.

Parameters:
args - The first argument should be either true or false. It determines if the returned string is uppercase (true) or lowercase (false). The second argument should be a number to format.

All Packages  Class Hierarchy  This Package  Previous  Next  Index