Top Description Fields Constructors Methods
com.ibm.icu.text

pack-priv abstract Class NFSubstitution

Additional top-level classes in compilation unit: SameValueSubstitution, MultiplierSubstitution, ModulusSubstitution, IntegralPartSubstitution, FractionalPartSubstitution, AbsoluteValueSubstitution, NumeratorSubstitution.

extends Object
Class Inheritance
Known Direct Subclasses
com.ibm.icu.text.SameValueSubstitution, com.ibm.icu.text.MultiplierSubstitution, com.ibm.icu.text.ModulusSubstitution, com.ibm.icu.text.IntegralPartSubstitution, com.ibm.icu.text.FractionalPartSubstitution, com.ibm.icu.text.AbsoluteValueSubstitution, com.ibm.icu.text.NumeratorSubstitution
Imports
java.text.ParsePosition, com.ibm.icu.impl.number.DecimalQuantity_DualStorageBCD

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

Field Summary

Modifier and TypeField and Description
private static final long
pack-priv final DecimalFormat
numberFormat

The DecimalFormat this substitution uses to format its result, or null.

pack-priv final int
pos

The substitution's position in the rule text of the rule that owns it

pack-priv final NFRuleSet
ruleSet

The rule set this substitution uses to format its result, or null.

Constructor Summary

AccessConstructor and Description
pack-priv
NFSubstitution(int
The substitution's position in the owning rule's rule text
pos
,
NFRuleSet
The rule set that owns this substitution
ruleSet
,
String
The substitution descriptor (i.e., the text inside the token characters)
description
)

Base constructor for substitutions.

Method Summary

Modifier and TypeMethod and Description
public abstract double
calcUpperBound(double
The current upper-bound setting. The new upper bound can't be any higher.
oldUpperBound
)

Calculates an upper bound when searching for a rule that matches this substitution.

public abstract double

Returns:

A third value derived from the other two, representing a partial parse result
composeRuleValue
(double
The value produced by matching this substitution
newRuleValue
,
double
The value that was passed to the substitution by the rule that owns it
oldRuleValue
)

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.

public Number

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.
doParse
(String
The string to parse
text
,
ParsePosition
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)
parsePosition
,
double
A partial parse result that should be combined with the result of this parse
baseValue
,
double
When searching the rule set for a rule matching the string passed in, only rules with base values lower than this are considered
upperBound
,
boolean
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.)
lenientParse
,
int nonNumericalExecutedRuleMask)

Parses a string using the rule set or DecimalFormat belonging to this substitution.

public void
doSubstitution(long
The number being formatted.
number
,
StringBuilder
The string we insert the result into
toInsertInto
,
int
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)
position
,
int recursionCount)

Performs a mathematical operation on the number, formats it using either ruleSet or decimalFormat, and inserts the result into toInsertInto.

public void
doSubstitution(double
The number being formatted.
number
,
StringBuilder
The string we insert the result into
toInsertInto
,
int
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)
position
,
int recursionCount)

Performs a mathematical operation on the number, formats it using either ruleSet or decimalFormat, and inserts the result into toInsertInto.

public boolean

Returns:

true if the two substitutions are functionally equivalent
equals
(Object
The substitution to compare this one to
that
)

Overrides java.lang.Object.equals.

Compares two substitutions for equality
public final int

Returns:

The substitution's position in the rule that owns it.
getPos
()

Returns the substitution's position in the rule that owns it.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean

Returns:

true if this object is an instance of ModulusSubstitution
isModulusSubstitution
()

Returns true if this is a modulus substitution.

public static NFSubstitution

Returns:

A new substitution constructed according to the description
makeSubstitution
(int
The substitution's position in the rule text of the rule that owns it.
pos
,
NFRule
The rule containing this substitution
rule
,
NFRule
The rule preceding the one that contains this substitution in the rule set's rule list (this is used only for >>> substitutions).
rulePredecessor
,
NFRuleSet
The rule set containing the rule containing this substitution
ruleSet
,
RuleBasedNumberFormat
The RuleBasedNumberFormat that ultimately owns this substitution
formatter
,
String
The description to parse to build the substitution (this is just the substring of the rule's description containing the substitution token itself)
description
)

Parses the description, creates the right kind of substitution, and initializes it based on the description.

public void
public void
setDivisor(int
The radix of the divisor
radix
,
short
The exponent of the divisor
exponent
)

Set's the substitution's divisor.

pack-priv abstract char

Returns:

This substitution's token character.
tokenChar
()

Returns the character used in the textual representation of substitutions of this type.

public String

Returns:

A textual description of the substitution. This might not be identical to the description it was created from, but it'll produce the same result.
toString
()

Overrides java.lang.Object.toString.

Returns a textual description of the substitution
public abstract long

Returns:

The result of performing the opreration on the number
transformNumber
(long
The number being formatted
number
)

Subclasses override this function to perform some kind of mathematical operation on the number.

public abstract double

Returns:

The result of performing the opreration on the number
transformNumber
(double
The number being formatted
number
)

Subclasses override this function to perform some kind of mathematical operation on the number.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

MAX_INT64_IN_DOUBLEback to summary
private static final long MAX_INT64_IN_DOUBLE
numberFormatback to summary
pack-priv final DecimalFormat numberFormat

The DecimalFormat this substitution uses to format its result, or null. (Either this or ruleSet has to be non-null.)

posback to summary
pack-priv final int pos

The substitution's position in the rule text of the rule that owns it

ruleSetback to summary
pack-priv final NFRuleSet ruleSet

The rule set this substitution uses to format its result, or null. (Either this or numberFormat has to be non-null.)

Constructor Detail

NFSubstitutionback to summary
pack-priv NFSubstitution(int pos, NFRuleSet ruleSet, String description)

Base constructor for substitutions. This constructor sets up the fields which are common to all substitutions.

Parameters
pos:int

The substitution's position in the owning rule's rule text

ruleSet:NFRuleSet

The rule set that owns this substitution

description:String

The substitution descriptor (i.e., the text inside the token characters)

Method Detail

calcUpperBoundback to summary
public abstract double calcUpperBound(double oldUpperBound)

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:double

The current upper-bound setting. The new upper bound can't be any higher.

composeRuleValueback to summary
public abstract double composeRuleValue(double newRuleValue, double oldRuleValue)

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:double

The value produced by matching this substitution

oldRuleValue:double

The value that was passed to the substitution by the rule that owns it

Returns:double

A third value derived from the other two, representing a partial parse result

doParseback to summary
public Number doParse(String text, ParsePosition parsePosition, double baseValue, double upperBound, boolean lenientParse, int nonNumericalExecutedRuleMask)

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:String

The string to parse

parsePosition:ParsePosition

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:double

A partial parse result that should be combined with the result of this parse

upperBound:double

When searching the rule set for a rule matching the string passed in, only rules with base values lower than this are considered

lenientParse:boolean

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:Number

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.

doSubstitutionback to summary
public void doSubstitution(long 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.

Parameters
number:long

The number being formatted.

toInsertInto:StringBuilder

The string we insert the result into

position:int

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)

doSubstitutionback to summary
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.

Parameters
number:double

The number being formatted.

toInsertInto:StringBuilder

The string we insert the result into

position:int

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)

equalsback to summary
public boolean equals(Object that)

Overrides java.lang.Object.equals.

Compares two substitutions for equality

Parameters
that:Object

The substitution to compare this one to

Returns:boolean

true if the two substitutions are functionally equivalent

Annotations
@Override
getPosback to summary
public final int getPos()

Returns the substitution's position in the rule that owns it.

Returns:int

The substitution's position in the rule that owns it.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
isModulusSubstitutionback to summary
public boolean isModulusSubstitution()

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++.)

Returns:boolean

true if this object is an instance of ModulusSubstitution

makeSubstitutionback to summary
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.

Parameters
pos:int

The substitution's position in the rule text of the rule that owns it.

rule:NFRule

The rule containing this substitution

rulePredecessor:NFRule

The rule preceding the one that contains this substitution in the rule set's rule list (this is used only for >>> substitutions).

ruleSet:NFRuleSet

The rule set containing the rule containing this substitution

formatter:RuleBasedNumberFormat

The RuleBasedNumberFormat that ultimately owns this substitution

description:String

The description to parse to build the substitution (this is just the substring of the rule's description containing the substitution token itself)

Returns:NFSubstitution

A new substitution constructed according to the description

setDecimalFormatSymbolsback to summary
public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols)
setDivisorback to summary
public void setDivisor(int radix, short exponent)

Set's the substitution's divisor. Used by NFRule.setBaseValue(). A no-op for all substitutions except multiplier and modulus substitutions.

Parameters
radix:int

The radix of the divisor

exponent:short

The exponent of the divisor

tokenCharback to summary
pack-priv abstract char tokenChar()

Returns the character used in the textual representation of substitutions of this type. Used by toString().

Returns:char

This substitution's token character.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a textual description of the substitution

Returns:String

A textual description of the substitution. This might not be identical to the description it was created from, but it'll produce the same result.

Annotations
@Override
transformNumberback to summary
public abstract long transformNumber(long number)

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
number:long

The number being formatted

Returns:long

The result of performing the opreration on the number

transformNumberback to summary
public abstract double transformNumber(double number)

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
number:double

The number being formatted

Returns:double

The result of performing the opreration on the number