Class FractionalPartSubstitution


  • class FractionalPartSubstitution
    extends NFSubstitution
    A substitution that formats the fractional part of a number. This is represented by >> in a fraction rule.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean byDigits
      true if this substitution should have the default "by digits" behavior, false otherwise
      private boolean useSpaces
      true if we automatically insert spaces to separate names of digits set to false by '>>>' in fraction rules, used by Thai.
    • Constructor Summary

      Constructors 
      Constructor Description
      FractionalPartSubstitution​(int pos, NFRuleSet ruleSet, java.lang.String description)
      Constructs a FractionalPartSubstitution.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double calcUpperBound​(double oldUpperBound)
      Not used.
      double composeRuleValue​(double newRuleValue, double oldRuleValue)
      Returns the sum of the two partial parse results.
      java.lang.Number doParse​(java.lang.String text, java.text.ParsePosition parsePosition, double baseValue, double upperBound, boolean lenientParse, int nonNumericalExecutedRuleMask, int recursionCount)
      If in "by digits" mode, parses the string as if it were a string of individual digits; otherwise, uses the superclass function.
      void doSubstitution​(double number, java.lang.StringBuilder toInsertInto, int position, int recursionCount)
      If in "by digits" mode, fills in the substitution one decimal digit at a time using the rule set containing this substitution.
      (package private) char tokenChar()
      The token character for a FractionalPartSubstitution is >.
      double transformNumber​(double number)
      Returns the fractional part of the number.
      long transformNumber​(long number)
      Returns the fractional part of the number, which will always be zero if it's a long.
      • Methods inherited from class java.lang.Object

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

      • byDigits

        private final boolean byDigits
        true if this substitution should have the default "by digits" behavior, false otherwise
      • useSpaces

        private final boolean useSpaces
        true if we automatically insert spaces to separate names of digits set to false by '>>>' in fraction rules, used by Thai.
    • Constructor Detail

      • FractionalPartSubstitution

        FractionalPartSubstitution​(int pos,
                                   NFRuleSet ruleSet,
                                   java.lang.String description)
        Constructs a FractionalPartSubstitution. This object keeps a flag telling whether it should format by digits or not. In addition, it marks the rule set it calls (if any) as a fraction rule set.
    • Method Detail

      • doSubstitution

        public void doSubstitution​(double number,
                                   java.lang.StringBuilder toInsertInto,
                                   int position,
                                   int recursionCount)
        If in "by digits" mode, fills in the substitution one decimal digit at a time using the rule set containing this substitution. Otherwise, uses the superclass function.
        Overrides:
        doSubstitution in class NFSubstitution
        Parameters:
        number - The number being formatted
        toInsertInto - The string to insert the result of formatting the substitution into
        position - The position of the owning rule's rule text in toInsertInto
      • transformNumber

        public long transformNumber​(long number)
        Returns the fractional part of the number, which will always be zero if it's a long.
        Specified by:
        transformNumber in class NFSubstitution
        Parameters:
        number - The number being formatted
        Returns:
        0
      • transformNumber

        public double transformNumber​(double number)
        Returns the fractional part of the number.
        Specified by:
        transformNumber in class NFSubstitution
        Parameters:
        number - The number being formatted.
        Returns:
        number - floor(number)
      • doParse

        public java.lang.Number doParse​(java.lang.String text,
                                        java.text.ParsePosition parsePosition,
                                        double baseValue,
                                        double upperBound,
                                        boolean lenientParse,
                                        int nonNumericalExecutedRuleMask,
                                        int recursionCount)
        If in "by digits" mode, parses the string as if it were a string of individual digits; otherwise, uses the superclass function.
        Overrides:
        doParse in class NFSubstitution
        Parameters:
        text - The string to parse
        parsePosition - Ignored on entry, but updated on exit to point to the first unmatched character
        baseValue - The partial parse result prior to entering this function
        upperBound - Only consider rules with base values lower than this when filling in the substitution
        lenientParse - If true, try matching the text as numerals if matching as words doesn't work
        Returns:
        If the match was successful, the current partial parse result; otherwise Long.valueOf(0). The result is either a Long or a Double.
      • composeRuleValue

        public double composeRuleValue​(double newRuleValue,
                                       double oldRuleValue)
        Returns the sum of the two partial parse results.
        Specified by:
        composeRuleValue in class NFSubstitution
        Parameters:
        newRuleValue - The result of parsing the substitution
        oldRuleValue - The partial parse result prior to calling this function
        Returns:
        newRuleValue + oldRuleValue
      • calcUpperBound

        public double calcUpperBound​(double oldUpperBound)
        Not used.
        Specified by:
        calcUpperBound in class NFSubstitution
        Parameters:
        oldUpperBound - The current upper-bound setting. The new upper bound can't be any higher.
      • tokenChar

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