Package com.ibm.icu.text
Class NumeratorSubstitution
java.lang.Object
com.ibm.icu.text.NFSubstitution
com.ibm.icu.text.NumeratorSubstitution
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
FieldsModifier and TypeFieldDescriptionprivate final double
The denominator of the fraction we're finding the numerator for.private final boolean
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
ConstructorsConstructorDescriptionNumeratorSubstitution
(int pos, double denominator, NFRuleSet ruleSet, String description) Constructs a NumeratorSubstitution. -
Method Summary
Modifier and TypeMethodDescriptiondouble
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.doParse
(String text, ParsePosition parsePosition, double baseValue, double upperBound, boolean lenientParse, int nonNumericalExecutedRuleMask) Dispatches to the inherited version of this function, but makes sure that lenientParse is off.void
doSubstitution
(double number, 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
Tests two NumeratorSubstitutions for equality(package private) static String
(package private) char
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
-
Field Details
-
denominator
private final double denominatorThe denominator of the fraction we're finding the numerator for. (The base value of the rule that owns this substitution.) -
withZeros
private final boolean withZerosTrue if we format leading zeros (this is a hack for Hebrew spellout)
-
-
Constructor Details
-
NumeratorSubstitution
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 Details
-
fixdesc
-
equals
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, 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 Number doParse(String text, ParsePosition parsePosition, double baseValue, double upperBound, boolean lenientParse, int nonNumericalExecutedRuleMask) 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 new Long(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:
- '<'
-