org.apache.fop.complexscripts.util

## Class NumberConverter

- java.lang.Object
- - org.apache.fop.complexscripts.util.NumberConverter

-     public class NumberConverter
      extends java.lang.Object

  Implementation of Number to String Conversion algorithm specified by XSL Transformations (XSLT) Version 2.0, W3C Recommendation, 23 January 2007.

  This algorithm differs from that specified in XSLT 1.0 in the following ways:

  - input numbers are greater than or equal to zero rather than greater than zero;
  - introduces format tokens { w, W, Ww };
  - introduces ordinal parameter to generate ordinal numbers;

  Implementation Defaults and Limitations

  - If language parameter is unspecified (null or empty string), then the value of DEFAULT_LANGUAGE is used, which is defined below as "eng" (English).
  - Only English, French, and Spanish word numerals are supported, and only if less than one trillion (1,000,000,000,000).
  - Ordinal word numerals are supported for French and Spanish only when less than or equal to ten (10).

  Implementation Notes

  - In order to handle format tokens outside the Unicode BMP, all processing is done in Unicode Scalar Values represented with Integer and Integer[] types. Without affecting behavior, this may be subsequently optimized to use int and int[] types.
  - In order to communicate various sub-parameters, including ordinalization, a features is employed, which consists of comma separated name and optional value tokens, where name and value are separated by an equals '=' sign.
  - Ordinal numbers are selected by specifying a word based format token in combination with a 'ordinal' feature with no value, in which case the features 'male' and 'female' may be used to specify gender for gender sensitive languages. For example, the feature string "ordinal,female" selects female ordinals.

  This work was originally authored by Glenn Adams (gadams@apache.org).

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `LETTER_VALUE_ALPHABETIC` alphabetical
    `static int` | `LETTER_VALUE_TRADITIONAL` traditional

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NumberConverter(java.lang.String format, int groupingSeparator, int groupingSize, int letterValue, java.lang.String features, java.lang.String language, java.lang.String country)` Construct parameterized number converter.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `convert(java.util.List<java.lang.Long> numbers)` Convert list of numbers to string according to conversion parameters.
    `java.lang.String` | `convert(long number)` Convert a number to string according to conversion parameters.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### LETTER_VALUE_ALPHABETIC

          public static final int LETTER_VALUE_ALPHABETIC

      alphabetical
      See Also:
        Constant Field Values

    - #### LETTER_VALUE_TRADITIONAL

          public static final int LETTER_VALUE_TRADITIONAL

      traditional
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### NumberConverter

          public NumberConverter(java.lang.String format,
                                 int groupingSeparator,
                                 int groupingSize,
                                 int letterValue,
                                 java.lang.String features,
                                 java.lang.String language,
                                 java.lang.String country)
                          throws java.lang.IllegalArgumentException

      Construct parameterized number converter.
      Parameters:
        `format` - format for the page number (may be null or empty, which is treated as null)
        `groupingSeparator` - grouping separator (if zero, then no grouping separator applies)
        `groupingSize` - grouping size (if zero or negative, then no grouping size applies)
        `letterValue` - letter value (must be one of the above letter value enumeration values)
        `features` - features (feature sub-parameters)
        `language` - (may be null or empty, which is treated as null)
        `country` - (may be null or empty, which is treated as null)
      Throws:
        `java.lang.IllegalArgumentException` - if format is not a valid UTF-16 string (e.g., has unpaired surrogate)

  - ### Method Detail

    - #### convert

          public java.lang.String convert(long number)

      Convert a number to string according to conversion parameters.
      Parameters:
        `number` - number to conver
      Returns:
        string representing converted number

    - #### convert

          public java.lang.String convert(java.util.List<java.lang.Long> numbers)

      Convert list of numbers to string according to conversion parameters.
      Parameters:
        `numbers` - list of numbers to convert
      Returns:
        string representing converted list of numbers

Copyright 1999-2021 The Apache Software Foundation. All Rights Reserved.