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

pack-priv final Class NFRuleSet

extends Object
Class Inheritance
Imports
java.text.ParsePosition, java.util.ArrayList, .LinkedList, .List, .Objects, com.ibm.icu.impl.PatternProps

A collection of rules used by a RuleBasedNumberFormat to format and parse numbers. It is the responsibility of a RuleSet to select an appropriate rule for formatting a particular number and dispatch control to it, and to arbitrate between different rules when parsing a number.

Field Summary

Modifier and TypeField and Description
pack-priv static final int
pack-priv LinkedList<NFRule>
fractionRules

These are a pile of fraction rules in declared order.

pack-priv static final int
pack-priv static final int
private boolean
isFractionRuleSet

True if the rule set is a fraction rule set.

private final boolean
isParseable

True if the rule set is parseable.

private final String
name

The rule set's name

pack-priv static final int
pack-priv static final int
pack-priv final NFRule[]
nonNumericalRules

The rule set's non-numerical rules like negative, fractions, infinity and NaN

pack-priv final RuleBasedNumberFormat
owner

The RuleBasedNumberFormat that owns this rule

pack-priv static final int
private static final int
RECURSION_LIMIT

Limit of recursion.

private NFRule[]
rules

The rule set's regular rules

Constructor Summary

AccessConstructor and Description
public
NFRuleSet(RuleBasedNumberFormat
The formatter that owns this rule set
owner
,
String[]
An array of Strings representing rule set descriptions. On exit, this rule set's entry in the array will have been stripped of its rule set name and any trailing whitespace.
descriptions
,
int
The index into "descriptions" of the description for the rule to be constructed
index
)

Constructs a rule set.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the two rule sets are functionally equivalent.
equals
(Object
The other rule set
that
)

Overrides java.lang.Object.equals.

Compares two rule sets for equality.
private NFRule

Returns:

The rule to use to format this number
findFractionRuleSetRule
(double
The number being formatted (which will always be a number between 0 and 1)
number
)

If this rule is a fraction rule set, this function is used by findRule() to select the most appropriate rule for formatting the number.

private NFRule

Returns:

The rule to use to format this number
findNormalRule
(long
The number being formatted
number
)

If the value passed to findRule() is a positive integer, findRule() uses this function to select the appropriate rule.

pack-priv NFRule

Returns:

The rule that should be used to format it
findRule
(double
The number being formatted.
number
)

Selects an appropriate rule for formatting the number.

public void
format(long
The number being formatted
number
,
StringBuilder
The string where the result is to be placed
toInsertInto
,
int
The position in toInsertInto where the result of this operation is to be inserted
pos
,
int recursionCount)

Formats a long.

public void
format(double
The number being formatted
number
,
StringBuilder
The string where the result is to be placed
toInsertInto
,
int
The position in toInsertInto where the result of this operation is to be inserted
pos
,
int recursionCount)

Formats a double.

public String

Returns:

The rule set's name
getName
()

Returns the rule set's name

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean

Returns:

true if this rule is a fraction rule set; false if it isn't
isFractionSet
()

Says whether this rule set is a fraction rule set.

public boolean

Returns:

true if the rule set can be used for parsing.
isParseable
()

Return true if the rule set can be used for parsing.

public boolean

Returns:

true if the rule set is public
isPublic
()

Return true if the rule set is public.

private static long
lcm(long x, long y)

Calculates the least common multiple of x and y.

public void
makeIntoFractionRuleSet()

Flags this rule set as a fraction rule set.

public Number

Returns:

The numerical result of parsing this string. This will be the matching rule's base value, composed appropriately with the results of matching any of its substitutions. The object will be an instance of Long if it's an integral value; otherwise, it will be an instance of Double. This function always returns a valid object: If nothing matched the input string at all, this function returns new Long(0), and the parse position is left unchanged.
parse
(String
The string to parse
text
,
ParsePosition
The initial position is ignored and assumed to be 0. On exit, this object has been updated to point to the first character position this rule set didn't consume.
parsePosition
,
double
Limits the rules that can be allowed to match. Only rules whose base values are strictly less than upperBound are considered.
upperBound
,
int nonNumericalExecutedRuleMask)

Parses a string.

public void
parseRules(String
The textual description of this rule set
description
)

Construct the subordinate data structures used by this object.

private void
setBestFractionRule(int
The index into nonNumericalRules
originalIndex
,
NFRule
The new rule to consider
newRule
,
boolean
Should the new rule be added to fractionRules.
rememberRule
)

Determine the best fraction rule to use.

public void
pack-priv void
setNonNumericalRule(NFRule
The rule to set.
rule
)

Set one of the non-numerical rules.

public String

Returns:

A textual representation of a rule set. This won't necessarily be the same description that the rule set was constructed with, but it will produce the same results.
toString
()

Overrides java.lang.Object.toString.

Builds a textual representation of a rule set.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

DEFAULT_RULE_INDEXback to summary
pack-priv static final int DEFAULT_RULE_INDEX

x.0

fractionRulesback to summary
pack-priv LinkedList<NFRule> fractionRules

These are a pile of fraction rules in declared order. They may have alternate ways to represent fractions.

IMPROPER_FRACTION_RULE_INDEXback to summary
pack-priv static final int IMPROPER_FRACTION_RULE_INDEX

x.x

INFINITY_RULE_INDEXback to summary
pack-priv static final int INFINITY_RULE_INDEX

Inf

isFractionRuleSetback to summary
private boolean isFractionRuleSet

True if the rule set is a fraction rule set. A fraction rule set is a rule set that is used to format the fractional part of a number. It is called from a >> substitution in another rule set's fraction rule, and is only called upon to format values between 0 and 1. A fraction rule set has different rule-selection behavior than a regular rule set.

isParseableback to summary
private final boolean isParseable

True if the rule set is parseable.

nameback to summary
private final String name

The rule set's name

NAN_RULE_INDEXback to summary
pack-priv static final int NAN_RULE_INDEX

NaN

NEGATIVE_RULE_INDEXback to summary
pack-priv static final int NEGATIVE_RULE_INDEX

-x

nonNumericalRulesback to summary
pack-priv final NFRule[] nonNumericalRules

The rule set's non-numerical rules like negative, fractions, infinity and NaN

ownerback to summary
pack-priv final RuleBasedNumberFormat owner

The RuleBasedNumberFormat that owns this rule

PROPER_FRACTION_RULE_INDEXback to summary
pack-priv static final int PROPER_FRACTION_RULE_INDEX

0.x

RECURSION_LIMITback to summary
private static final int RECURSION_LIMIT

Limit of recursion. It's about a 64 bit number formatted in base 2.

rulesback to summary
private NFRule[] rules

The rule set's regular rules

Constructor Detail

NFRuleSetback to summary
public NFRuleSet(RuleBasedNumberFormat owner, String[] descriptions, int index) throws IllegalArgumentException

Constructs a rule set.

Parameters
owner:RuleBasedNumberFormat

The formatter that owns this rule set

descriptions:String[]

An array of Strings representing rule set descriptions. On exit, this rule set's entry in the array will have been stripped of its rule set name and any trailing whitespace.

index:int

The index into "descriptions" of the description for the rule to be constructed

Method Detail

equalsback to summary
public boolean equals(Object that)

Overrides java.lang.Object.equals.

Compares two rule sets for equality.

Parameters
that:Object

The other rule set

Returns:boolean

true if the two rule sets are functionally equivalent.

Annotations
@Override
findFractionRuleSetRuleback to summary
private NFRule findFractionRuleSetRule(double number)

If this rule is a fraction rule set, this function is used by findRule() to select the most appropriate rule for formatting the number. Basically, the base value of each rule in the rule set is treated as the denominator of a fraction. Whichever denominator can produce the fraction closest in value to the number passed in is the result. If there's a tie, the earlier one in the list wins. (If there are two rules in a row with the same base value, the first one is used when the numerator of the fraction would be 1, and the second rule is used the rest of the time.

Parameters
number:double

The number being formatted (which will always be a number between 0 and 1)

Returns:NFRule

The rule to use to format this number

findNormalRuleback to summary
private NFRule findNormalRule(long number)

If the value passed to findRule() is a positive integer, findRule() uses this function to select the appropriate rule. The result will generally be the rule with the highest base value less than or equal to the number. There is one exception to this: If that rule has two substitutions and a base value that is not an even multiple of its divisor, and the number itself IS an even multiple of the rule's divisor, then the result will be the rule that preceded the original result in the rule list. (This behavior is known as the "rollback rule", and is used to handle optional text: a rule with optional text is represented internally as two rules, and the rollback rule selects appropriate between them. This avoids things like "two hundred zero".)

Parameters
number:long

The number being formatted

Returns:NFRule

The rule to use to format this number

findRuleback to summary
pack-priv NFRule findRule(double number)

Selects an appropriate rule for formatting the number.

Parameters
number:double

The number being formatted.

Returns:NFRule

The rule that should be used to format it

formatback to summary
public void format(long number, StringBuilder toInsertInto, int pos, int recursionCount)

Formats a long. Selects an appropriate rule and dispatches control to it.

Parameters
number:long

The number being formatted

toInsertInto:StringBuilder

The string where the result is to be placed

pos:int

The position in toInsertInto where the result of this operation is to be inserted

formatback to summary
public void format(double number, StringBuilder toInsertInto, int pos, int recursionCount)

Formats a double. Selects an appropriate rule and dispatches control to it.

Parameters
number:double

The number being formatted

toInsertInto:StringBuilder

The string where the result is to be placed

pos:int

The position in toInsertInto where the result of this operation is to be inserted

getNameback to summary
public String getName()

Returns the rule set's name

Returns:String

The rule set's name

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
isFractionSetback to summary
public boolean isFractionSet()

Says whether this rule set is a fraction rule set.

Returns:boolean

true if this rule is a fraction rule set; false if it isn't

isParseableback to summary
public boolean isParseable()

Return true if the rule set can be used for parsing.

Returns:boolean

true if the rule set can be used for parsing.

isPublicback to summary
public boolean isPublic()

Return true if the rule set is public.

Returns:boolean

true if the rule set is public

lcmback to summary
private static long lcm(long x, long y)

Calculates the least common multiple of x and y.

makeIntoFractionRuleSetback to summary
public void makeIntoFractionRuleSet()

Flags this rule set as a fraction rule set. This function is called during the construction process once we know this rule set is a fraction rule set. We don't know a rule set is a fraction rule set until we see it used somewhere. This function is not ad must not be called at any time other than during construction of a RuleBasedNumberFormat.

parseback to summary
public Number parse(String text, ParsePosition parsePosition, double upperBound, int nonNumericalExecutedRuleMask)

Parses a string. Matches the string to be parsed against each of its rules (with a base value less than upperBound) and returns the value produced by the rule that matched the most characters in the source string.

Parameters
text:String

The string to parse

parsePosition:ParsePosition

The initial position is ignored and assumed to be 0. On exit, this object has been updated to point to the first character position this rule set didn't consume.

upperBound:double

Limits the rules that can be allowed to match. Only rules whose base values are strictly less than upperBound are considered.

Returns:Number

The numerical result of parsing this string. This will be the matching rule's base value, composed appropriately with the results of matching any of its substitutions. The object will be an instance of Long if it's an integral value; otherwise, it will be an instance of Double. This function always returns a valid object: If nothing matched the input string at all, this function returns new Long(0), and the parse position is left unchanged.

parseRulesback to summary
public void parseRules(String description)

Construct the subordinate data structures used by this object. This function is called by the RuleBasedNumberFormat constructor after all the rule sets have been created to actually parse the description and build rules from it. Since any rule set can refer to any other rule set, we have to have created all of them before we can create anything else.

Parameters
description:String

The textual description of this rule set

setBestFractionRuleback to summary
private void setBestFractionRule(int originalIndex, NFRule newRule, boolean rememberRule)

Determine the best fraction rule to use. Rules matching the decimal point from DecimalFormatSymbols become the main set of rules to use.

Parameters
originalIndex:int

The index into nonNumericalRules

newRule:NFRule

The new rule to consider

rememberRule:boolean

Should the new rule be added to fractionRules.

setDecimalFormatSymbolsback to summary
public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols)
setNonNumericalRuleback to summary
pack-priv void setNonNumericalRule(NFRule rule)

Set one of the non-numerical rules.

Parameters
rule:NFRule

The rule to set.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Builds a textual representation of a rule set.

Returns:String

A textual representation of a rule set. This won't necessarily be the same description that the rule set was constructed with, but it will produce the same results.

Annotations
@Override