| java.lang.Object com.ibm.icu.text.NFSubstitution
NFSubstitution | abstract class NFSubstitution (Code) | | An abstract class defining protocol for substitutions. A substitution
is a section of a rule that inserts text into the rule's rule text
based on some part of the number being formatted.
author: Richard Gillam |
Method Summary | |
abstract public double | calcUpperBound(double oldUpperBound) Calculates an upper bound when searching for a rule that matches
this substitution. | abstract public double | composeRuleValue(double newRuleValue, double oldRuleValue) Derives a new value from the two values passed in. | public Number | doParse(String text, ParsePosition parsePosition, double baseValue, double upperBound, boolean lenientParse) Parses a string using the rule set or DecimalFormat belonging
to this substitution. | public void | doSubstitution(long number, StringBuffer toInsertInto, int pos) Performs a mathematical operation on the number, formats it using
either ruleSet or decimalFormat, and inserts the result into
toInsertInto. | public void | doSubstitution(double number, StringBuffer toInsertInto, int pos) Performs a mathematical operation on the number, formats it using
either ruleSet or decimalFormat, and inserts the result into
toInsertInto. | public boolean | equals(Object that) | final public int | getPos() Returns the substitution's position in the rule that owns it. | public boolean | isModulusSubstitution() Returns true if this is a modulus substitution. | public boolean | isNullSubstitution() Returns true if this is a null substitution. | public static NFSubstitution | makeSubstitution(int pos, NFRule rule, NFRule rulePredecessor, NFRuleSet ruleSet, RuleBasedNumberFormat formatter, String description) Parses the description, creates the right kind of substitution,
and initializes it based on the description. | public void | setDivisor(int radix, int exponent) Set's the substitution's divisor. | public String | toString() Returns a textual description of the substitution
A textual description of the substitution. | abstract char | tokenChar() Returns the character used in the textual representation of
substitutions of this type. | abstract public long | transformNumber(long number) Subclasses override this function to perform some kind of
mathematical operation on the number. | abstract public double | transformNumber(double number) Subclasses override this function to perform some kind of
mathematical operation on the number. |
numberFormat | DecimalFormat numberFormat(Code) | | The DecimalFormat this substitution uses to format its result,
or null. (Either this or ruleSet has to be non-null.)
|
pos | int pos(Code) | | The substitution's position in the rule text of the rule that owns it
|
ruleSet | NFRuleSet ruleSet(Code) | | The rule set this substitution uses to format its result, or null.
(Either this or numberFormat has to be non-null.)
|
NFSubstitution | NFSubstitution(int pos, NFRuleSet ruleSet, RuleBasedNumberFormat formatter, String description)(Code) | | Base constructor for substitutions. This constructor sets up the
fields which are common to all substitutions.
Parameters: pos - The substitution's position in the owning rule's ruletext Parameters: ruleSet - The rule set that owns this substitution Parameters: formatter - The RuleBasedNumberFormat that owns this substitution Parameters: description - The substitution descriptor (i.e., the textinside the token characters) |
calcUpperBound | abstract public double calcUpperBound(double oldUpperBound)(Code) | | Calculates an upper bound when searching for a rule that matches
this substitution. Rules with base values greater than or equal
to upperBound are not considered.
Parameters: oldUpperBound - The current upper-bound setting. The newupper bound can't be any higher. |
composeRuleValue | abstract public double composeRuleValue(double newRuleValue, double oldRuleValue)(Code) | | Derives a new value from the two values passed in. The two values
are typically either the base values of two rules (the one containing
the substitution and the one matching the substitution) or partial
parse results derived in some other way. The operation is generally
the inverse of the operation performed by transformNumber().
Parameters: newRuleValue - The value produced by matching this substitution Parameters: oldRuleValue - The value that was passed to the substitutionby the rule that owns it A third value derived from the other two, representing apartial parse result |
doParse | public Number doParse(String text, ParsePosition parsePosition, double baseValue, double upperBound, boolean lenientParse)(Code) | | Parses a string using the rule set or DecimalFormat belonging
to this substitution. If there's a match, a mathematical
operation (the inverse of the one used in formatting) is
performed on the result of the parse and the value passed in
and returned as the result. The parse position is updated to
point to the first unmatched character in the string.
Parameters: text - The string to parse Parameters: parsePosition - On entry, ignored, but assumed to be 0.On exit, this is updated to point to the first unmatchedcharacter (or 0 if the substitution didn't match) Parameters: baseValue - A partial parse result that should becombined with the result of this parse Parameters: upperBound - When searching the rule set for a rulematching the string passed in, only rules with base valueslower than this are considered Parameters: lenientParse - If true and matching against rules fails,the substitution will also try matching the text againstnumerals using a default-costructed NumberFormat. If false,no extra work is done. (This value is false whenever theformatter isn't in lenient-parse mode, but is also falseunder some conditions even when the formatter _is_ inlenient-parse mode.) If there's a match, this is the result of composingbaseValue with whatever was returned from matching thecharacters. This will be either a Long or a Double. If there'sno match this is new Long(0) (not null), and parsePositionis left unchanged. |
doSubstitution | public void doSubstitution(long number, StringBuffer toInsertInto, int pos)(Code) | | Performs a mathematical operation on the number, formats it using
either ruleSet or decimalFormat, and inserts the result into
toInsertInto.
Parameters: number - The number being formatted. Parameters: toInsertInto - The string we insert the result into Parameters: pos - The position in toInsertInto where the owning rule'srule text begins (this value is added to this substitution'sposition to determine exactly where to insert the new text) |
doSubstitution | public void doSubstitution(double number, StringBuffer toInsertInto, int pos)(Code) | | Performs a mathematical operation on the number, formats it using
either ruleSet or decimalFormat, and inserts the result into
toInsertInto.
Parameters: number - The number being formatted. Parameters: toInsertInto - The string we insert the result into Parameters: pos - The position in toInsertInto where the owning rule'srule text begins (this value is added to this substitution'sposition to determine exactly where to insert the new text) |
equals | public boolean equals(Object that)(Code) | | Compares two substitutions for equality
Parameters: The - substitution to compare this one to true if the two substitutions are functionally equivalent |
getPos | final public int getPos()(Code) | | Returns the substitution's position in the rule that owns it.
The substitution's position in the rule that owns it. |
isModulusSubstitution | public boolean isModulusSubstitution()(Code) | | Returns true if this is a modulus substitution. (We didn't do this
with instanceof partially because it causes source files to
proliferate and partially because we have to port this to C++.)
true if this object is an instance of ModulusSubstitution |
isNullSubstitution | public boolean isNullSubstitution()(Code) | | Returns true if this is a null substitution. (We didn't do this
with instanceof partially because it causes source files to
proliferate and partially because we have to port this to C++.)
true if this object is an instance of NullSubstitution |
makeSubstitution | public static NFSubstitution makeSubstitution(int pos, NFRule rule, NFRule rulePredecessor, NFRuleSet ruleSet, RuleBasedNumberFormat formatter, String description)(Code) | | Parses the description, creates the right kind of substitution,
and initializes it based on the description.
Parameters: pos - The substitution's position in the rule text of therule that owns it. Parameters: rule - The rule containing this substitution Parameters: rulePredecessor - The rule preceding the one that containsthis substitution in the rule set's rule list (this is usedonly for >>> substitutions). Parameters: ruleSet - The rule set containing the rule containing thissubstitution Parameters: formatter - The RuleBasedNumberFormat that ultimately ownsthis substitution Parameters: description - The description to parse to build the substitution(this is just the substring of the rule's description containingthe substitution token itself) A new substitution constructed according to the description |
setDivisor | public void setDivisor(int radix, int exponent)(Code) | | Set's the substitution's divisor. Used by NFRule.setBaseValue().
A no-op for all substitutions except multiplier and modulus
substitutions.
Parameters: radix - The radix of the divisor Parameters: exponent - The exponent of the divisor |
toString | public String toString()(Code) | | Returns a textual description of the substitution
A textual description of the substitution. This mightnot be identical to the description it was created from, butit'll produce the same result. |
tokenChar | abstract char tokenChar()(Code) | | Returns the character used in the textual representation of
substitutions of this type. Used by toString().
This substitution's token character. |
transformNumber | abstract public long transformNumber(long number)(Code) | | Subclasses override this function to perform some kind of
mathematical operation on the number. The result of this operation
is formatted using the rule set or DecimalFormat that this
substitution refers to, and the result is inserted into the result
string.
Parameters: The - number being formatted The result of performing the opreration on the number |
transformNumber | abstract public double transformNumber(double number)(Code) | | Subclasses override this function to perform some kind of
mathematical operation on the number. The result of this operation
is formatted using the rule set or DecimalFormat that this
substitution refers to, and the result is inserted into the result
string.
Parameters: The - number being formatted The result of performing the opreration on the number |
|
|