com.internationalnetwork.util
Class NumberGrammar

Object
  extended by com.internationalnetwork.util.NumberGrammar

public class NumberGrammar
extends Object

The NumberGrammar class returns small but useful strings depending on the value of a number.

Behind the scenes the code is written to be efficient, thus each iteration of each method is a complete copy of the other rather than making a call to a more central method.  Of course, the preferred approach is to call one centralized method to simplify coding, but in this case the anticipated use for these methods is in situations where speed likely is important, so it was chosen not to use the preferred approach.  All the code is carefully maintained to ensure that changes made to one method will be made the same way to all (and then tested to ensure consistency), and although the code requires more effort to maintain as a result, it is better overall because fewer CPU cycles are required at run time (the most efficient code is in the methods without parameters which simply return the previously returned result, or the blank non-NULL default, thus their use is strongly encouraged whenever possible in order to eliminate redundant comparisons and ensure a more efficient execution in the end).


Field Summary
static int AM
          Gets or Sets the AM time string text returned by ampm().
static int ND
          Gets or Sets the ND suffix string text returned by th().
static int PLURAL
          Gets or Sets the plural string text returned by s().
static int PM
          Gets or Sets the PM time string text returned by ampm().
static int RD
          Gets or Sets the RD suffix string text returned by th().
static int SINGULAR
          Gets or Sets the singular string text returned by s().
static int ST
          Gets or Sets the ST suffix string text returned by th().
static int TH
          Gets or Sets the TH suffix string text returned by th().
static String VERSION
          Version number of this Package (read-only).
 
Constructor Summary
NumberGrammar()
           
 
Method Summary
 String ampm()
          Returns the previous result returned by ampm(hour), or an empty string if no previous result is known.
 String ampm(byte hour)
          Returns "am" or "pm" depending on the value of the hour passed in, and will even support future days represented by additional hours (e.g., the hours of 24 through 47 would represent tomorrow).
 String ampm(double hour)
          Returns "am" or "pm" depending on the value of the hour passed in, and will even support future days represented by additional hours (e.g., the hours of 24 through 47 would represent tomorrow).
 String ampm(float hour)
          Returns "am" or "pm" depending on the value of the hour passed in, and will even support future days represented by additional hours (e.g., the hours of 24 through 47 would represent tomorrow).
 String ampm(int hour)
          Returns "am" or "pm" depending on the value of the hour passed in, and will even support future days represented by additional hours (e.g., the hours of 24 through 47 would represent tomorrow).
 String ampm(long hour)
          Returns "am" or "pm" depending on the value of the hour passed in, and will even support future days represented by additional hours (e.g., the hours of 24 through 47 would represent tomorrow).
 String ampm(short hour)
          Returns "am" or "pm" depending on the value of the hour passed in, and will even support future days represented by additional hours (e.g., the hours of 24 through 47 would represent tomorrow).
 String get(int constant)
          Returns currently defined string text for the specified function, or returns NULL to indicate an error (e.g., incompatible constant used).
 String s()
          Returns the previous result returned by s(value), or an empty string if no previous result is known.
 String s(boolean value)
          Returns an "s" only if the value is 0 (where "false = 0" and "true = 1"), which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.
 String s(byte value)
          Returns an "s" only if the value is 0, less than -1, or greater than 1, which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.
 String s(double value)
          Returns an "s" only if the value is 0, less than -1, or greater than 1, which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.
 String s(float value)
          Returns an "s" only if the value is 0, less than -1, or greater than 1, which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.
 String s(int value)
          Returns an "s" only if the value is 0, less than -1, or greater than 1, which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.
 String s(long value)
          Returns an "s" only if the value is 0, less than -1, or greater than 1, which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.
 String s(short value)
          Returns an "s" only if the value is 0, less than -1, or greater than 1, which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.
 String s(String value)
          Returns an "s" only if the value is 0, less than -1, or greater than 1, which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.
 boolean set(int constant, String newText)
          Changes the string text for the specified function, returns TRUE if successful, or FALSE if unsuccessful (e.g., incompatible constant used).
 String th()
          Returns the previous result returned by th(value), or an empty string if no previous result is known.
 String th(byte value)
          Returns an "st," "nd," "rd," or "th" two-letter string depending on the value, which is useful for signifying the position in something such as a race, a high score in a game, or a list of tasks.
 String th(double value)
          Returns an "st," "nd," "rd," or "th" two-letter string depending on the value, which is useful for signifying the position in something such as a race, a high score in a game, or a list of tasks.
 String th(float value)
          Returns an "st," "nd," "rd," or "th" two-letter string depending on the value, which is useful for signifying the position in something such as a race, a high score in a game, or a list of tasks.
 String th(int value)
          Returns an "st," "nd," "rd," or "th" two-letter string depending on the value, which is useful for signifying the position in something such as a race, a high score in a game, or a list of tasks.
 String th(long value)
          Returns an "st," "nd," "rd," or "th" two-letter string depending on the value, which is useful for signifying the position in something such as a race, a high score in a game, or a list of tasks.
 String th(short value)
          Returns an "st," "nd," "rd," or "th" two-letter string depending on the value, which is useful for signifying the position in something such as a race, a high score in a game, or a list of tasks.
 String th(String value)
          Returns an "st," "nd," "rd," or "th" two-letter string depending on the value, which is useful for signifying the position in something such as a race, a high score in a game, or a list of tasks.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AM

public static final int AM
Gets or Sets the AM time string text returned by ampm().

See Also:
Constant Field Values

ND

public static final int ND
Gets or Sets the ND suffix string text returned by th().

See Also:
Constant Field Values

PLURAL

public static final int PLURAL
Gets or Sets the plural string text returned by s().

See Also:
Constant Field Values

PM

public static final int PM
Gets or Sets the PM time string text returned by ampm().

See Also:
Constant Field Values

RD

public static final int RD
Gets or Sets the RD suffix string text returned by th().

See Also:
Constant Field Values

SINGULAR

public static final int SINGULAR
Gets or Sets the singular string text returned by s().

See Also:
Constant Field Values

ST

public static final int ST
Gets or Sets the ST suffix string text returned by th().

See Also:
Constant Field Values

TH

public static final int TH
Gets or Sets the TH suffix string text returned by th().

See Also:
Constant Field Values

VERSION

public static final String VERSION
Version number of this Package (read-only).

See Also:
Constant Field Values
Constructor Detail

NumberGrammar

public NumberGrammar()
Method Detail

ampm

public String ampm()
Returns the previous result returned by ampm(hour), or an empty string if no previous result is known.

Minimum version requirement: Version 1.01.


ampm

public String ampm(byte hour)
Returns "am" or "pm" depending on the value of the hour passed in, and will even support future days represented by additional hours (e.g., the hours of 24 through 47 would represent tomorrow).

Minimum version requirement: Version 1.01.


ampm

public String ampm(double hour)
Returns "am" or "pm" depending on the value of the hour passed in, and will even support future days represented by additional hours (e.g., the hours of 24 through 47 would represent tomorrow).

Minimum version requirement: Version 1.01.


ampm

public String ampm(float hour)
Returns "am" or "pm" depending on the value of the hour passed in, and will even support future days represented by additional hours (e.g., the hours of 24 through 47 would represent tomorrow).

Minimum version requirement: Version 1.01.


ampm

public String ampm(int hour)
Returns "am" or "pm" depending on the value of the hour passed in, and will even support future days represented by additional hours (e.g., the hours of 24 through 47 would represent tomorrow).

Minimum version requirement: Version 1.01.


ampm

public String ampm(long hour)
Returns "am" or "pm" depending on the value of the hour passed in, and will even support future days represented by additional hours (e.g., the hours of 24 through 47 would represent tomorrow).

Minimum version requirement: Version 1.01.


ampm

public String ampm(short hour)
Returns "am" or "pm" depending on the value of the hour passed in, and will even support future days represented by additional hours (e.g., the hours of 24 through 47 would represent tomorrow).

Minimum version requirement: Version 1.01.


get

public String get(int constant)
Returns currently defined string text for the specified function, or returns NULL to indicate an error (e.g., incompatible constant used).


s

public String s()
Returns the previous result returned by s(value), or an empty string if no previous result is known.

Minimum version requirement: Version 1.01.


s

public String s(boolean value)
Returns an "s" only if the value is 0 (where "false = 0" and "true = 1"), which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.

For example, when counting some containers we could use the following code to ensure that the letter "s" is added after the word "container" only if the quantity is not 1 or -1:

NumberGrammar ng = new NumberGrammar;
System.out.println("A total of " + containers + "container" + ng.s(containers) + " are ready for shipping.");

Instead of using "container(s)" the letter "s" is added as needed.


s

public String s(byte value)
Returns an "s" only if the value is 0, less than -1, or greater than 1, which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.

For example, when counting some containers we could use the following code to ensure that the letter "s" is added after the word "container" only if the quantity is not 1 or -1:

NumberGrammar ng = new NumberGrammar;
System.out.println("A total of " + containers + "container" + ng.s(containers) + " are ready for shipping.");

Instead of using "container(s)" the letter "s" is added as needed.


s

public String s(double value)
Returns an "s" only if the value is 0, less than -1, or greater than 1, which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.

For example, when counting some containers we could use the following code to ensure that the letter "s" is added after the word "container" only if the quantity is not 1 or -1:

NumberGrammar ng = new NumberGrammar;
System.out.println("A total of " + containers + "container" + ng.s(containers) + " are ready for shipping.");

Instead of using "container(s)" the letter "s" is added as needed.


s

public String s(float value)
Returns an "s" only if the value is 0, less than -1, or greater than 1, which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.

For example, when counting some containers we could use the following code to ensure that the letter "s" is added after the word "container" only if the quantity is not 1 or -1:

NumberGrammar ng = new NumberGrammar;
System.out.println("A total of " + containers + "container" + ng.s(containers) + " are ready for shipping.");

Instead of using "container(s)" the letter "s" is added as needed.


s

public String s(int value)
Returns an "s" only if the value is 0, less than -1, or greater than 1, which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.

For example, when counting some containers we could use the following code to ensure that the letter "s" is added after the word "container" only if the quantity is not 1 or -1:

NumberGrammar ng = new NumberGrammar;
System.out.println("A total of " + containers + "container" + ng.s(containers) + " are ready for shipping.");

Instead of using "container(s)" the letter "s" is added as needed.


s

public String s(long value)
Returns an "s" only if the value is 0, less than -1, or greater than 1, which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.

For example, when counting some containers we could use the following code to ensure that the letter "s" is added after the word "container" only if the quantity is not 1 or -1:

NumberGrammar ng = new NumberGrammar;
System.out.println("A total of " + containers + "container" + ng.s(containers) + " are ready for shipping.");

Instead of using "container(s)" the letter "s" is added as needed.


s

public String s(short value)
Returns an "s" only if the value is 0, less than -1, or greater than 1, which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.

For example, when counting some containers we could use the following code to ensure that the letter "s" is added after the word "container" only if the quantity is not 1 or -1:

NumberGrammar ng = new NumberGrammar;
System.out.println("A total of " + containers + "container" + ng.s(containers) + " are ready for shipping.");

Instead of using "container(s)" the letter "s" is added as needed.


s

public String s(String value)
Returns an "s" only if the value is 0, less than -1, or greater than 1, which is useful for adding the letter "s" after a string that represents an item when explaining a quantity.

For example, when counting some containers we could use the following code to ensure that the letter "s" is added after the word "container" only if the quantity is not 1 or -1:

NumberGrammar ng = new NumberGrammar;
System.out.println("A total of " + containers + "container" + ng.s(containers) + " are ready for shipping.");

Instead of using "container(s)" the letter "s" is added as needed.


set

public boolean set(int constant,
                   String newText)
Changes the string text for the specified function, returns TRUE if successful, or FALSE if unsuccessful (e.g., incompatible constant used).


th

public String th()
Returns the previous result returned by th(value), or an empty string if no previous result is known.

Minimum version requirement: Version 1.01.


th

public String th(byte value)
Returns an "st," "nd," "rd," or "th" two-letter string depending on the value, which is useful for signifying the position in something such as a race, a high score in a game, or a list of tasks.

For example, we could use the following code to display a list of items:

NumberGrammar ng = new NumberGrammar;
for (int number = 1; number <= 3; number++) {
System.out.println(number + ng.th(number) + " item");
}

Instead of using "Item number #" the appropriate letters are added to show "1st item," "2nd item," and "3rd item" as needed.


th

public String th(double value)
Returns an "st," "nd," "rd," or "th" two-letter string depending on the value, which is useful for signifying the position in something such as a race, a high score in a game, or a list of tasks.

For example, we could use the following code to display a list of items:

NumberGrammar ng = new NumberGrammar;
for (int number = 1; number <= 3; number++) {
System.out.println(number + ng.th(number) + " item");
}

Instead of using "Item number #" the appropriate letters are added to show "1st item," "2nd item," and "3rd item" as needed.


th

public String th(float value)
Returns an "st," "nd," "rd," or "th" two-letter string depending on the value, which is useful for signifying the position in something such as a race, a high score in a game, or a list of tasks.

For example, we could use the following code to display a list of items:

NumberGrammar ng = new NumberGrammar;
for (int number = 1; number <= 3; number++) {
System.out.println(number + ng.th(number) + " item");
}

Instead of using "Item number #" the appropriate letters are added to show "1st item," "2nd item," and "3rd item" as needed.


th

public String th(int value)
Returns an "st," "nd," "rd," or "th" two-letter string depending on the value, which is useful for signifying the position in something such as a race, a high score in a game, or a list of tasks.

For example, we could use the following code to display a list of items:

NumberGrammar ng = new NumberGrammar;
for (int number = 1; number <= 3; number++) {
System.out.println(number + ng.th(number) + " item");
}

Instead of using "Item number #" the appropriate letters are added to show "1st item," "2nd item," and "3rd item" as needed.


th

public String th(long value)
Returns an "st," "nd," "rd," or "th" two-letter string depending on the value, which is useful for signifying the position in something such as a race, a high score in a game, or a list of tasks.

For example, we could use the following code to display a list of items:

NumberGrammar ng = new NumberGrammar;
for (int number = 1; number <= 3; number++) {
System.out.println(number + ng.th(number) + " item");
}

Instead of using "Item number #" the appropriate letters are added to show "1st item," "2nd item," and "3rd item" as needed.


th

public String th(short value)
Returns an "st," "nd," "rd," or "th" two-letter string depending on the value, which is useful for signifying the position in something such as a race, a high score in a game, or a list of tasks.

For example, we could use the following code to display a list of items:

NumberGrammar ng = new NumberGrammar;
for (int number = 1; number <= 3; number++) {
System.out.println(number + ng.th(number) + " item");
}

Instead of using "Item number #" the appropriate letters are added to show "1st item," "2nd item," and "3rd item" as needed.


th

public String th(String value)
Returns an "st," "nd," "rd," or "th" two-letter string depending on the value, which is useful for signifying the position in something such as a race, a high score in a game, or a list of tasks.

For example, we could use the following code to display a list of items:

NumberGrammar ng = new NumberGrammar;
for (int number = 1; number <= 3; number++) {
System.out.println(number + ng.th(number) + " item");
}

Instead of using "Item number #" the appropriate letters are added to show "1st item," "2nd item," and "3rd item" as needed.