Class ModulusSubstitution

java.lang.Object
com.ibm.icu.text.NFSubstitution
com.ibm.icu.text.ModulusSubstitution

class ModulusSubstitution extends NFSubstitution
A substitution that divides the number being formatted by the its rule's divisor and formats the remainder. Represented by ">>" in a regular rule.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) long
    The divisor of the rule owning this substitution
    private final NFRule
    If this is a >>> substitution, the rule to use to format the substitution value.

    Fields inherited from class com.ibm.icu.text.NFSubstitution

    numberFormat, pos, ruleSet
  • Constructor Summary

    Constructors
    Constructor
    Description
    ModulusSubstitution(int pos, NFRule rule, NFRule rulePredecessor, NFRuleSet ruleSet, String description)
    Constructs a ModulusSubstitution.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    calcUpperBound(double oldUpperBound)
    Sets the upper bound down to the owning rule's divisor
    double
    composeRuleValue(double newRuleValue, double oldRuleValue)
    Returns the highest multiple of the rule's divisor that its less than or equal to oldRuleValue, plus newRuleValue.
    doParse(String text, ParsePosition parsePosition, double baseValue, double upperBound, boolean lenientParse, int nonNumericalExecutedRuleMask)
    If this is a >>> substitution, match only against ruleToUse.
    void
    doSubstitution(double number, StringBuilder toInsertInto, int position, int recursionCount)
    If this is a >>> substitution, use ruleToUse to fill in the substitution.
    void
    doSubstitution(long number, StringBuilder toInsertInto, int position, int recursionCount)
    If this is a >>> substitution, use ruleToUse to fill in the substitution.
    boolean
    equals(Object that)
    Augments the inherited equals() function by comparing divisors and ruleToUse.
    boolean
    Returns true.
    void
    setDivisor(int radix, short exponent)
    Makes the substitution's divisor conform to that of the rule that owns it.
    (package private) char
    The token character of a ModulusSubstitution is >.
    double
    transformNumber(double number)
    Divides the number being formatted by the rule's divisor and returns the remainder.
    long
    transformNumber(long number)
    Divides the number being formatted by the rule's divisor and returns the remainder.

    Methods inherited from class com.ibm.icu.text.NFSubstitution

    getPos, hashCode, makeSubstitution, setDecimalFormatSymbols, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • divisor

      long divisor
      The divisor of the rule owning this substitution
    • ruleToUse

      private final NFRule ruleToUse
      If this is a >>> substitution, the rule to use to format the substitution value. Otherwise, null.
  • Constructor Details

    • ModulusSubstitution

      ModulusSubstitution(int pos, NFRule rule, NFRule rulePredecessor, NFRuleSet ruleSet, String description)
      Constructs a ModulusSubstitution. In addition to the inherited members, a ModulusSubstitution keeps track of the divisor of the rule that owns it, and may also keep a reference to the rule that precedes the rule containing this substitution in the rule set's rule list.
      Parameters:
      pos - The substitution's position in its rule's rule text
      rule - The rule that owns this substitution
      rulePredecessor - The rule that precedes this substitution's rule in its rule set's rule list
      description - The description for this substitution
  • Method Details

    • setDivisor

      public void setDivisor(int radix, short exponent)
      Makes the substitution's divisor conform to that of the rule that owns it. Used when the divisor is determined after creation.
      Overrides:
      setDivisor in class NFSubstitution
      Parameters:
      radix - The radix of the divisor.
      exponent - The exponent of the divisor.
    • equals

      public boolean equals(Object that)
      Augments the inherited equals() function by comparing divisors and ruleToUse.
      Overrides:
      equals in class NFSubstitution
      Parameters:
      that - The other substitution
      Returns:
      true if the two substitutions are functionally equivalent
    • doSubstitution

      public void doSubstitution(long number, StringBuilder toInsertInto, int position, int recursionCount)
      If this is a >>> substitution, use ruleToUse to fill in the substitution. Otherwise, just use the superclass function.
      Overrides:
      doSubstitution in class NFSubstitution
      Parameters:
      number - The number being formatted
      toInsertInto - The string to insert the result of this substitution into
      position - The position of the rule text in toInsertInto
    • doSubstitution

      public void doSubstitution(double number, StringBuilder toInsertInto, int position, int recursionCount)
      If this is a >>> substitution, use ruleToUse to fill in the substitution. Otherwise, just use the superclass function.
      Overrides:
      doSubstitution in class NFSubstitution
      Parameters:
      number - The number being formatted
      toInsertInto - The string to insert the result of this substitution into
      position - The position of the rule text in toInsertInto
    • transformNumber

      public long transformNumber(long number)
      Divides the number being formatted by the rule's divisor and returns the remainder.
      Specified by:
      transformNumber in class NFSubstitution
      Parameters:
      number - The number being formatted
      Returns:
      "number" mod divisor
    • transformNumber

      public double transformNumber(double number)
      Divides the number being formatted by the rule's divisor and returns the remainder.
      Specified by:
      transformNumber in class NFSubstitution
      Parameters:
      number - The number being formatted
      Returns:
      "number" mod divisor
    • doParse

      public Number doParse(String text, ParsePosition parsePosition, double baseValue, double upperBound, boolean lenientParse, int nonNumericalExecutedRuleMask)
      If this is a >>> substitution, match only against ruleToUse. Otherwise, use the superclass function.
      Overrides:
      doParse in class NFSubstitution
      Parameters:
      text - The string to parse
      parsePosition - Ignored on entry, updated on exit to point to the first unmatched character.
      baseValue - The partial parse result prior to calling this routine.
      upperBound - When searching the rule set for a rule matching the string passed in, only rules with base values lower than this are considered
      lenientParse - 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)
      Returns the highest multiple of the rule's divisor that its less than or equal to oldRuleValue, plus newRuleValue. (The result is the sum of the result of parsing the substitution plus the base value of the rule containing the substitution, but if the owning rule's base value isn't an even multiple of its divisor, we have to round it down to a multiple of the divisor, or we get unwanted digits in the result.)
      Specified by:
      composeRuleValue in class NFSubstitution
      Parameters:
      newRuleValue - The result of parsing the substitution
      oldRuleValue - The base value of the rule containing the substitution
      Returns:
      A third value derived from the other two, representing a partial parse result
    • calcUpperBound

      public double calcUpperBound(double oldUpperBound)
      Sets the upper bound down to the owning rule's divisor
      Specified by:
      calcUpperBound in class NFSubstitution
      Parameters:
      oldUpperBound - Ignored
      Returns:
      The owning rule's divisor
    • isModulusSubstitution

      public boolean isModulusSubstitution()
      Returns true. This _is_ a ModulusSubstitution.
      Overrides:
      isModulusSubstitution in class NFSubstitution
      Returns:
      true
    • tokenChar

      char tokenChar()
      The token character of a ModulusSubstitution is >.
      Specified by:
      tokenChar in class NFSubstitution
      Returns:
      '>'