smithers.extras
Class NumberString

java.lang.Object
  extended by smithers.extras.NumberString

public class NumberString
extends java.lang.Object

Provides a series of methods for converting between numeric values, and Strings. Supports the following:


Type long double
Digits Supported Output only
Words Output only
Options: language, scale
Output only
Options: language, scale
Roman Numerals Output only Unsupported

Languages
English
French/Francais
German/Deutsch
TODO: The following is out of date! A NumberString object contains a number (either a long or a double) as well as the options to be used.
The following types of method are availiable:
Type Prefix Function
Accessors get Get the number or option.
Modifiers set Set the number or option.
Encoders to Format the number in the specified style.
Decoders from Parse a string in from the specified style.
The accessors and modifiers are only instance methods. The encoders are instance methods, but static shortcut methods are availiable. The decoders are currently only static methods.


Field Summary
static java.lang.String DEUTSCH
          German
static java.lang.String ENGLISH
          English
static java.lang.String FRANCAIS
          French
static java.lang.String FRENCH
          French
static java.lang.String GERMAN
          German
static int LONG_SCALE_MILLIARD
          The long scale.
static int LONG_SCALE_NO_MILLIARD
          The long scale.
static int SHORT_SCALE
          The short scale.
 
Constructor Summary
NumberString()
          Constructs a new NumberString object with the default properties.
NumberString(java.lang.String language)
          Constructs a new NumberString object with properties derived from a specified language.
NumberString(java.lang.String language, int scale)
          Constructs a new NumberString object with the specified properties.
 
Method Summary
 java.lang.String getLanguage()
          Gets the language of this NumberString.
 int getScale()
          Gets the scale of this NumberString.
static long longFromDigits(java.lang.String text)
          Converts a string of digits into a long value.
 long longFromWords(java.lang.String text)
          Converts a string of words into a long value.
static void main(java.lang.String[] args)
          For testing.
 void setLanguage(java.lang.String language)
          Sets the language of this NumberString.
 void setOptions(java.lang.String language)
          Sets the all the options of this NumberString based on a language.
 void setScale(int scale)
          Sets the scale of this NumberString.
static java.lang.String toDigits(double number)
          Converts a double value into a string of digits.
 java.lang.String toDigits(long number)
          Converts a long value into a string of digits.
 java.lang.String toRomanNumerals(long number)
          Converts a long value into a string of roman numerals.
 java.lang.String toWords(double number)
          Converts a double value into a string of words.
 java.lang.String toWords(long number)
          Converts a long value into a string of words.
static java.lang.String toWords(long number, java.lang.String language)
          Converts a long value into a string of words using the specified language.
static java.lang.String toWords(long number, java.lang.String language, int scale)
          Converts a long value into a string of words using the specified language and scale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENGLISH

public static final java.lang.String ENGLISH
English

See Also:
Constant Field Values

FRENCH

public static final java.lang.String FRENCH
French

See Also:
Constant Field Values

FRANCAIS

public static final java.lang.String FRANCAIS
French

See Also:
Constant Field Values

GERMAN

public static final java.lang.String GERMAN
German

See Also:
Constant Field Values

DEUTSCH

public static final java.lang.String DEUTSCH
German

See Also:
Constant Field Values

SHORT_SCALE

public static final int SHORT_SCALE
The short scale. One billion = 109.

See Also:
Constant Field Values

LONG_SCALE_NO_MILLIARD

public static final int LONG_SCALE_NO_MILLIARD
The long scale. One billion = 1012. One thousand million = 109

See Also:
Constant Field Values

LONG_SCALE_MILLIARD

public static final int LONG_SCALE_MILLIARD
The long scale. One billion = 1012. One milliard = 109

See Also:
Constant Field Values
Constructor Detail

NumberString

public NumberString()
Constructs a new NumberString object with the default properties.


NumberString

public NumberString(java.lang.String language)
Constructs a new NumberString object with properties derived from a specified language. The parameter should be one of the language constants defined in this class.

Parameters:
language - the language

NumberString

public NumberString(java.lang.String language,
                    int scale)
Constructs a new NumberString object with the specified properties. The parameters should be chosen from the language and scale constants defined in this class.

Parameters:
language - the language
scale - the scale to use
Method Detail

getLanguage

public java.lang.String getLanguage()
Gets the language of this NumberString.

Returns:
the language

getScale

public int getScale()
Gets the scale of this NumberString.

Returns:
the scale

setOptions

public void setOptions(java.lang.String language)
Sets the all the options of this NumberString based on a language. The parameter should be equal to one of the language constants defined in this class.

Parameters:
language - the language to derive the options from

setLanguage

public void setLanguage(java.lang.String language)
Sets the language of this NumberString. The parameter should be equal to one of the language constants defined in this class.

Parameters:
language - the new language

setScale

public void setScale(int scale)
Sets the scale of this NumberString. The parameter should be equal to one of the scale constants defined in this class.

Parameters:
scale - the new scale

toDigits

public java.lang.String toDigits(long number)
Converts a long value into a string of digits.

Parameters:
number - the long value
Returns:
the digits which represent number in base 10

toDigits

public static java.lang.String toDigits(double number)
Converts a double value into a string of digits.

Parameters:
number - the double value
Returns:
the digits which represent number in base 10

longFromDigits

public static long longFromDigits(java.lang.String text)
Converts a string of digits into a long value.

Parameters:
text - the string of digits
Returns:
the long value of the string in base 10

toWords

public java.lang.String toWords(long number)
Converts a long value into a string of words.

Parameters:
number - the long value
Returns:
a string of words representing number

toWords

public static java.lang.String toWords(long number,
                                       java.lang.String language)
Converts a long value into a string of words using the specified language. Determines the scale based on the language.

Parameters:
number - the long value
language - the language to use
Returns:
a string of words representing number
See Also:
toWords(long)

toWords

public static java.lang.String toWords(long number,
                                       java.lang.String language,
                                       int scale)
Converts a long value into a string of words using the specified language and scale.

Parameters:
number - the long value
language - the language to use
scale - the scale to use
Returns:
a string of words representing number
See Also:
toWords(long)

toWords

public java.lang.String toWords(double number)
Converts a double value into a string of words. Tentative

Parameters:
number - the double value
Returns:
a string of words representing number

longFromWords

public long longFromWords(java.lang.String text)
Converts a string of words into a long value. IN PROGRESS. ENGLISH ONLY.

Parameters:
text - a string of words
Returns:
the long value of the string

toRomanNumerals

public java.lang.String toRomanNumerals(long number)
Converts a long value into a string of roman numerals. Warning: do not use for values >>1000 since this can take a very long time and generate a very long string.

Parameters:
number - the long value
Returns:
a string of letters representing number

main

public static void main(java.lang.String[] args)
For testing. Creates a single NumberString and a number and attempts to output it using each of the three methods. Run with the -h option to list options.

Parameters:
args - the arguments