Package com.ibm.icu.text
Class NumeratorSubstitution
- java.lang.Object
-
- com.ibm.icu.text.NFSubstitution
-
- com.ibm.icu.text.NumeratorSubstitution
-
class NumeratorSubstitution extends NFSubstitution
A substitution that multiplies the number being formatted (which is between 0 and 1) by the base value of the rule that owns it and formats the result. It is represented by << in the rules in a fraction rule set.
-
-
Field Summary
Fields Modifier and Type Field Description private double
denominator
The denominator of the fraction we're finding the numerator for.private boolean
withZeros
True if we format leading zeros (this is a hack for Hebrew spellout)-
Fields inherited from class com.ibm.icu.text.NFSubstitution
numberFormat, pos, ruleSet
-
-
Constructor Summary
Constructors Constructor Description NumeratorSubstitution(int pos, double denominator, NFRuleSet ruleSet, java.lang.String description)
Constructs a NumeratorSubstitution.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description double
calcUpperBound(double oldUpperBound)
Sets the upper bound down to this rule's base valuedouble
composeRuleValue(double newRuleValue, double oldRuleValue)
Divides the result of parsing the substitution by the partial parse result.java.lang.Number
doParse(java.lang.String text, java.text.ParsePosition parsePosition, double baseValue, double upperBound, boolean lenientParse, int nonNumericalExecutedRuleMask, int recursionCount)
Dispatches to the inherited version of this function, but makes sure that lenientParse is off.void
doSubstitution(double number, java.lang.StringBuilder toInsertInto, int position, int recursionCount)
Performs a mathematical operation on the number, formats it using either ruleSet or decimalFormat, and inserts the result into toInsertInto.boolean
equals(java.lang.Object that)
Tests two NumeratorSubstitutions for equality(package private) static java.lang.String
fixdesc(java.lang.String description)
(package private) char
tokenChar()
The token character for a NumeratorSubstitution is <double
transformNumber(double number)
Returns the number being formatted times the denominator.long
transformNumber(long number)
Returns the number being formatted times the denominator.-
Methods inherited from class com.ibm.icu.text.NFSubstitution
doSubstitution, getPos, hashCode, isModulusSubstitution, makeSubstitution, setDecimalFormatSymbols, setDivisor, toString
-
-
-
-
Constructor Detail
-
NumeratorSubstitution
NumeratorSubstitution(int pos, double denominator, NFRuleSet ruleSet, java.lang.String description)
Constructs a NumeratorSubstitution. In addition to the inherited fields, a NumeratorSubstitution keeps track of a denominator, which is merely the base value of the rule that owns it.
-
-
Method Detail
-
fixdesc
static java.lang.String fixdesc(java.lang.String description)
-
equals
public boolean equals(java.lang.Object that)
Tests two NumeratorSubstitutions for equality- Overrides:
equals
in classNFSubstitution
- Parameters:
that
- The other NumeratorSubstitution- Returns:
- true if the two objects are functionally equivalent
-
doSubstitution
public void doSubstitution(double number, java.lang.StringBuilder toInsertInto, int position, int recursionCount)
Performs a mathematical operation on the number, formats it using either ruleSet or decimalFormat, and inserts the result into toInsertInto.- Overrides:
doSubstitution
in classNFSubstitution
- Parameters:
number
- The number being formatted.toInsertInto
- The string we insert the result intoposition
- The position in toInsertInto where the owning rule's rule text begins (this value is added to this substitution's position to determine exactly where to insert the new text)
-
transformNumber
public long transformNumber(long number)
Returns the number being formatted times the denominator.- Specified by:
transformNumber
in classNFSubstitution
- Parameters:
number
- The number being formatted- Returns:
- number * denominator
-
transformNumber
public double transformNumber(double number)
Returns the number being formatted times the denominator.- Specified by:
transformNumber
in classNFSubstitution
- Parameters:
number
- The number being formatted- Returns:
- number * denominator
-
doParse
public java.lang.Number doParse(java.lang.String text, java.text.ParsePosition parsePosition, double baseValue, double upperBound, boolean lenientParse, int nonNumericalExecutedRuleMask, int recursionCount)
Dispatches to the inherited version of this function, but makes sure that lenientParse is off.- Overrides:
doParse
in classNFSubstitution
- Parameters:
text
- The string to parseparsePosition
- On entry, ignored, but assumed to be 0. On exit, this is updated to point to the first unmatched character (or 0 if the substitution didn't match)baseValue
- A partial parse result that should be combined with the result of this parseupperBound
- When searching the rule set for a rule matching the string passed in, only rules with base values lower than this are consideredlenientParse
- If true and matching against rules fails, the substitution will also try matching the text against numerals using a default-constructed NumberFormat. If false, no extra work is done. (This value is false whenever the formatter isn't in lenient-parse mode, but is also false under some conditions even when the formatter _is_ in lenient-parse mode.)- Returns:
- If there's a match, this is the result of composing baseValue with whatever was returned from matching the characters. This will be either a Long or a Double. If there's no match this is Long.valueOf(0) (not null), and parsePosition is left unchanged.
-
composeRuleValue
public double composeRuleValue(double newRuleValue, double oldRuleValue)
Divides the result of parsing the substitution by the partial parse result.- Specified by:
composeRuleValue
in classNFSubstitution
- Parameters:
newRuleValue
- The result of parsing the substitutionoldRuleValue
- The owning rule's base value- Returns:
- newRuleValue / oldRuleValue
-
calcUpperBound
public double calcUpperBound(double oldUpperBound)
Sets the upper bound down to this rule's base value- Specified by:
calcUpperBound
in classNFSubstitution
- Parameters:
oldUpperBound
- Ignored- Returns:
- The base value of the rule owning this substitution
-
tokenChar
char tokenChar()
The token character for a NumeratorSubstitution is <- Specified by:
tokenChar
in classNFSubstitution
- Returns:
- '<'
-
-