Package com.ibm.icu.text
Class FractionalPartSubstitution
java.lang.Object
com.ibm.icu.text.NFSubstitution
com.ibm.icu.text.FractionalPartSubstitution
A substitution that formats the fractional part of a number. This is
represented by >> in a fraction rule.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleantrue if this substitution should have the default "by digits" behavior, false otherwiseprivate final booleantrue if we automatically insert spaces to separate names of digits set to false by '>>>' in fraction rules, used by Thai.Fields inherited from class com.ibm.icu.text.NFSubstitution
numberFormat, pos, ruleSet -
Constructor Summary
ConstructorsConstructorDescriptionFractionalPartSubstitution(int pos, NFRuleSet ruleSet, String description) Constructs a FractionalPartSubstitution. -
Method Summary
Modifier and TypeMethodDescriptiondoublecalcUpperBound(double oldUpperBound) Not used.doublecomposeRuleValue(double newRuleValue, double oldRuleValue) Returns the sum of the two partial parse results.doParse(String text, ParsePosition parsePosition, double baseValue, double upperBound, boolean lenientParse, int nonNumericalExecutedRuleMask) If in "by digits" mode, parses the string as if it were a string of individual digits; otherwise, uses the superclass function.voiddoSubstitution(double number, StringBuilder toInsertInto, int position, int recursionCount) If in "by digits" mode, fills in the substitution one decimal digit at a time using the rule set containing this substitution.(package private) charThe token character for a FractionalPartSubstitution is >.doubletransformNumber(double number) Returns the fractional part of the number.longtransformNumber(long number) Returns the fractional part of the number, which will always be zero if it's a long.Methods inherited from class com.ibm.icu.text.NFSubstitution
doSubstitution, equals, getPos, hashCode, isModulusSubstitution, makeSubstitution, setDecimalFormatSymbols, setDivisor, toString
-
Field Details
-
byDigits
private final boolean byDigitstrue if this substitution should have the default "by digits" behavior, false otherwise -
useSpaces
private final boolean useSpacestrue if we automatically insert spaces to separate names of digits set to false by '>>>' in fraction rules, used by Thai.
-
-
Constructor Details
-
FractionalPartSubstitution
Constructs a FractionalPartSubstitution. This object keeps a flag telling whether it should format by digits or not. In addition, it marks the rule set it calls (if any) as a fraction rule set.
-
-
Method Details
-
doSubstitution
public void doSubstitution(double number, StringBuilder toInsertInto, int position, int recursionCount) If in "by digits" mode, fills in the substitution one decimal digit at a time using the rule set containing this substitution. Otherwise, uses the superclass function.- Overrides:
doSubstitutionin classNFSubstitution- Parameters:
number- The number being formattedtoInsertInto- The string to insert the result of formatting the substitution intoposition- The position of the owning rule's rule text in toInsertInto
-
transformNumber
public long transformNumber(long number) Returns the fractional part of the number, which will always be zero if it's a long.- Specified by:
transformNumberin classNFSubstitution- Parameters:
number- The number being formatted- Returns:
- 0
-
transformNumber
public double transformNumber(double number) Returns the fractional part of the number.- Specified by:
transformNumberin classNFSubstitution- Parameters:
number- The number being formatted.- Returns:
- number - floor(number)
-
doParse
public Number doParse(String text, ParsePosition parsePosition, double baseValue, double upperBound, boolean lenientParse, int nonNumericalExecutedRuleMask) If in "by digits" mode, parses the string as if it were a string of individual digits; otherwise, uses the superclass function.- Overrides:
doParsein classNFSubstitution- Parameters:
text- The string to parseparsePosition- Ignored on entry, but updated on exit to point to the first unmatched characterbaseValue- The partial parse result prior to entering this functionupperBound- Only consider rules with base values lower than this when filling in the substitutionlenientParse- If true, try matching the text as numerals if matching as words doesn't work- Returns:
- If the match was successful, the current partial parse result; otherwise Long.valueOf(0). The result is either a Long or a Double.
-
composeRuleValue
public double composeRuleValue(double newRuleValue, double oldRuleValue) Returns the sum of the two partial parse results.- Specified by:
composeRuleValuein classNFSubstitution- Parameters:
newRuleValue- The result of parsing the substitutionoldRuleValue- The partial parse result prior to calling this function- Returns:
- newRuleValue + oldRuleValue
-
calcUpperBound
public double calcUpperBound(double oldUpperBound) Not used.- Specified by:
calcUpperBoundin classNFSubstitution- Parameters:
oldUpperBound- The current upper-bound setting. The new upper bound can't be any higher.
-
tokenChar
char tokenChar()The token character for a FractionalPartSubstitution is >.- Specified by:
tokenCharin classNFSubstitution- Returns:
- '>'
-