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
-
C
- value of 100
-
D
- value of 500
-
I
- value of 1
-
L
- value of 50
-
M
- value of 1000
-
V
- value of 5
-
X
- value of 10
-
RomanNumberFormat(boolean)
- Creates a new RomanNumberSequence object.
-
format(double, StringBuffer, FieldPosition)
- Formats the provided double as a Roman Number by converting to a long.
-
format(long, StringBuffer, FieldPosition)
- Formats the provided long as a Roman Number.
-
main(String[])
- This method is for testing the class.
-
parse(String, ParsePosition)
- Parses a string containing a number expressed in Roman Numerals and
converts it to a
Number
.
I
public static final int I
- value of 1
V
public static final int V
- value of 5
X
public static final int X
- value of 10
L
public static final int L
- value of 50
C
public static final int C
- value of 100
D
public static final int D
- value of 500
M
public static final int M
- value of 1000
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.
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.
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.
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.
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