Class NumeratorSubstitution

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

class NumeratorSubstitution extends NFSubstitution
A substitution that multiplies the number being formatted (which is between 0 and 1) by the base value of the rule that owns it and formats the result. It is represented by << in the rules in a fraction rule set.
  • Field Details

    • denominator

      private final double denominator
      The denominator of the fraction we're finding the numerator for. (The base value of the rule that owns this substitution.)
    • withZeros

      private final boolean withZeros
      True if we format leading zeros (this is a hack for Hebrew spellout)
  • Constructor Details

    • NumeratorSubstitution

      NumeratorSubstitution(int pos, double denominator, NFRuleSet ruleSet, String description)
      Constructs a NumeratorSubstitution. In addition to the inherited fields, a NumeratorSubstitution keeps track of a denominator, which is merely the base value of the rule that owns it.
  • Method Details

    • fixdesc

      static String fixdesc(String description)
    • equals

      public boolean equals(Object that)
      Tests two NumeratorSubstitutions for equality
      Overrides:
      equals in class NFSubstitution
      Parameters:
      that - The other NumeratorSubstitution
      Returns:
      true if the two objects are functionally equivalent
    • doSubstitution

      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.
      Overrides:
      doSubstitution in class NFSubstitution
      Parameters:
      number - The number being formatted.
      toInsertInto - The string we insert the result into
      position - 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)
    • transformNumber

      public long transformNumber(long number)
      Returns the number being formatted times the denominator.
      Specified by:
      transformNumber in class NFSubstitution
      Parameters:
      number - The number being formatted
      Returns:
      number * denominator
    • transformNumber

      public double transformNumber(double number)
      Returns the number being formatted times the denominator.
      Specified by:
      transformNumber in class NFSubstitution
      Parameters:
      number - The number being formatted
      Returns:
      number * denominator
    • doParse

      public Number doParse(String text, ParsePosition parsePosition, double baseValue, double upperBound, boolean lenientParse, int nonNumericalExecutedRuleMask)
      Dispatches to the inherited version of this function, but makes sure that lenientParse is off.
      Overrides:
      doParse in class NFSubstitution
      Parameters:
      text - The string to parse
      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 - A partial parse result that should be combined with the result of this parse
      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 Long.valueOf(0) (not null), and parsePosition is left unchanged.
    • composeRuleValue

      public double composeRuleValue(double newRuleValue, double oldRuleValue)
      Divides the result of parsing the substitution by the partial parse result.
      Specified by:
      composeRuleValue in class NFSubstitution
      Parameters:
      newRuleValue - The result of parsing the substitution
      oldRuleValue - The owning rule's base value
      Returns:
      newRuleValue / oldRuleValue
    • calcUpperBound

      public double calcUpperBound(double oldUpperBound)
      Sets the upper bound down to this rule's base value
      Specified by:
      calcUpperBound in class NFSubstitution
      Parameters:
      oldUpperBound - Ignored
      Returns:
      The base value of the rule owning this substitution
    • tokenChar

      char tokenChar()
      The token character for a NumeratorSubstitution is <
      Specified by:
      tokenChar in class NFSubstitution
      Returns:
      '<'