Package net.sf.saxon.expr.number
Class AbstractNumberer
- java.lang.Object
-
- net.sf.saxon.expr.number.AbstractNumberer
-
- All Implemented Interfaces:
Numberer
- Direct Known Subclasses:
ICUNumbererPE
,Numberer_da
,Numberer_de
,Numberer_en
,Numberer_fr
,Numberer_frBE
,Numberer_it
,Numberer_nl
,Numberer_nlBE
,Numberer_sv
,Numberer_tr
public abstract class AbstractNumberer extends java.lang.Object implements Numberer
Class AbstractNumberer is a base implementation of Numberer that provides language-independent default numbering This supports the xsl:number element. Methods and data are declared as protected, and static is avoided, to allow easy subclassing.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
cyrillicLower
protected static java.lang.String
cyrillicUpper
protected static java.lang.String
greekLower
protected static java.lang.String
greekUpper
protected static java.lang.String
hebrew
protected static java.lang.String
hiraganaA
protected static java.lang.String
hiraganaI
protected static java.lang.String
katakanaA
protected static java.lang.String
katakanaI
protected static java.lang.String
latinLower
protected static java.lang.String
latinUpper
static int
LOWER_CASE
static int[]
lowerCaseAlphabet
static int
TITLE_CASE
static int
UPPER_CASE
static int[]
upperCaseAlphabet
protected static int[]
westernDigits
-
Constructor Summary
Constructors Constructor Description AbstractNumberer()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
alphaDefault(long number, char formchar, java.lang.StringBuilder sb)
Default processing with an alphabetic format token: use the contiguous range of Unicode letters starting with that token.static java.lang.String
convertDigitSystem(long number, int[] digits, int requiredLength)
Convert a number to use a given set of digits, to a required length.abstract java.lang.String
dayName(int day, int minWidth, int maxWidth)
Get a day name or abbreviationjava.util.Locale
defaultedLocale()
Whether this numberer has had its locale defaulted, i.e.java.lang.String
format(long number, UnicodeString picture, int groupSize, java.lang.String groupSeparator, java.lang.String letterValue, java.lang.String cardinal, java.lang.String ordinal)
Format a number into a string.java.lang.String
format(long number, UnicodeString picture, NumericGroupFormatter numGroupFormatter, java.lang.String letterValue, java.lang.String cardinal, java.lang.String ordinal)
Format a number into a stringjava.lang.String
getCalendarName(java.lang.String code)
Get the name of a calendarjava.lang.String
getCountry()
Get the country used by this numberer.java.lang.String
getEraName(int year)
Get the name for an era (e.g.java.lang.String
getLanguage()
Get the language used by this numbererjava.lang.String
getOrdinalSuffixForDateTime(java.lang.String component)
Get an ordinal suffix for a particular component of a date/time.java.lang.String
halfDayName(int minutes, int minWidth, int maxWidth)
Get an am/pm indicator.abstract java.lang.String
monthName(int month, int minWidth, int maxWidth)
Get a month name or abbreviationprotected java.lang.String
ordinalSuffix(java.lang.String ordinalParam, long number)
Construct the ordinal suffix for a number, for example "st", "nd", "rd".void
setCountry(java.lang.String country)
Set the country used by this numberer (currently used only for names of timezones)void
setLanguage(java.lang.String language)
Set the language used by this numberer.protected java.lang.String
toAlpha(long number, int min, int max)
Format the number as an alphabetic label using the alphabet consisting of consecutive Unicode characters from min to maxprotected java.lang.String
toAlphaSequence(long number, java.lang.String alphabet)
Convert the number into an alphabetic label using a given alphabet.java.lang.String
toJapanese(long number)
Format the number in Japanese.abstract java.lang.String
toOrdinalWords(java.lang.String ordinalParam, long number, int wordCase)
Show an ordinal number as English words in a requested case (for example, Twentyfirst)static java.lang.String
toRoman(long n)
Generate a Roman numeral (in lower case)abstract java.lang.String
toWords(java.lang.String cardinal, long number)
Show the number as words in title case.java.lang.String
toWords(java.lang.String cardinal, long number, int wordCase)
Format a number as English words with specified case optionsjava.lang.String
zero()
-
-
-
Field Detail
-
UPPER_CASE
public static final int UPPER_CASE
- See Also:
- Constant Field Values
-
LOWER_CASE
public static final int LOWER_CASE
- See Also:
- Constant Field Values
-
TITLE_CASE
public static final int TITLE_CASE
- See Also:
- Constant Field Values
-
lowerCaseAlphabet
public static int[] lowerCaseAlphabet
-
upperCaseAlphabet
public static int[] upperCaseAlphabet
-
westernDigits
protected static final int[] westernDigits
-
latinUpper
protected static final java.lang.String latinUpper
- See Also:
- Constant Field Values
-
latinLower
protected static final java.lang.String latinLower
- See Also:
- Constant Field Values
-
greekUpper
protected static final java.lang.String greekUpper
- See Also:
- Constant Field Values
-
greekLower
protected static final java.lang.String greekLower
- See Also:
- Constant Field Values
-
cyrillicUpper
protected static final java.lang.String cyrillicUpper
- See Also:
- Constant Field Values
-
cyrillicLower
protected static final java.lang.String cyrillicLower
- See Also:
- Constant Field Values
-
hebrew
protected static final java.lang.String hebrew
- See Also:
- Constant Field Values
-
hiraganaA
protected static final java.lang.String hiraganaA
- See Also:
- Constant Field Values
-
katakanaA
protected static final java.lang.String katakanaA
- See Also:
- Constant Field Values
-
hiraganaI
protected static final java.lang.String hiraganaI
- See Also:
- Constant Field Values
-
katakanaI
protected static final java.lang.String katakanaI
- See Also:
- Constant Field Values
-
-
Method Detail
-
defaultedLocale
public java.util.Locale defaultedLocale()
Whether this numberer has had its locale defaulted, i.e. it's not using the language requested This can be used for situations, such as in fn:format-date(), where indication of use of defaults is required. Override for subclasses where this can happen- Specified by:
defaultedLocale
in interfaceNumberer
- Returns:
- the locale used, null if it wasn't defaulted
-
setCountry
public void setCountry(java.lang.String country)
Set the country used by this numberer (currently used only for names of timezones)- Specified by:
setCountry
in interfaceNumberer
- Parameters:
country
- The ISO two-letter country code.
-
setLanguage
public void setLanguage(java.lang.String language)
Set the language used by this numberer. Useful because it can potentially handle variants of English (and subclasses can handle other languages)- Parameters:
language
- the requested language. Note that "en-x-hyphen" is recognized as a request to hyphenate numbers in the range 21-99.
-
getLanguage
public java.lang.String getLanguage()
Get the language used by this numberer- Returns:
- the language used by this numberer
-
getCountry
public java.lang.String getCountry()
Get the country used by this numberer.- Specified by:
getCountry
in interfaceNumberer
- Returns:
- the country used by this numberer, or null if no country has been set
-
format
public final java.lang.String format(long number, UnicodeString picture, int groupSize, java.lang.String groupSeparator, java.lang.String letterValue, java.lang.String cardinal, java.lang.String ordinal)
Format a number into a string. This method is provided for backwards compatibility. It merely calls the other format method after constructing a RegularGroupFormatter. The method is final; localization subclasses should implement the methodNumberer.format(long, UnicodeString, NumericGroupFormatter, String, String, String)
rather than this method.- Specified by:
format
in interfaceNumberer
- Parameters:
number
- The number to be formattedpicture
- The format token. This is a single component of the format attribute of xsl:number, e.g. "1", "01", "i", or "a"groupSize
- number of digits per group (0 implies no grouping)groupSeparator
- string to appear between groups of digitsletterValue
- The letter-value specified to xsl:number: "alphabetic" or "traditional". The value "Xnn" or "xnn" signifies use of a radix other than 10, in the range 2 to 36. Can also be an empty string or null.cardinal
- When called from xsl:number, the value is set to an empty string. When called from format-integer, the value is the value within parentheses after "c", for example "c(%spellout-masculine)" supplies the value "%spellout-masculine".ordinal
- When called from xsl:number, the value of the ordinal attribute ("true" and "1" are normalized to "yes"). When called from format-integer, the value is the value within parentheses after "o", for example "o(%spellout-masculine)" supplies the value "%spellout-masculine".- Returns:
- the formatted number. Note that no errors are reported; if the request is invalid, the number is formatted as if the string() function were used.
-
format
public java.lang.String format(long number, UnicodeString picture, NumericGroupFormatter numGroupFormatter, java.lang.String letterValue, java.lang.String cardinal, java.lang.String ordinal)
Format a number into a string- Specified by:
format
in interfaceNumberer
- Parameters:
number
- The number to be formattedpicture
- The format token. This is a single component of the format attribute of xsl:number, e.g. "1", "01", "i", or "a"numGroupFormatter
- object contains separators to appear between groups of digitsletterValue
- The letter-value specified to xsl:number: "alphabetic" or "traditional". The value "Xnn" or "xnn" signifies use of a radix other than 10, in the range 2 to 36. Can also be an empty string or null.cardinal
- When called from xsl:number, the value is set to an empty string. When called from format-integer, the value is the value within parentheses after "c", for example "c(%spellout-masculine)" supplies the value "%spellout-masculine".ordinal
- When called from xsl:number, the value of the ordinal attribute ("true" and "1" are normalized to "yes"). When called from format-integer, the value is the value within parentheses after "o", for example "o(%spellout-masculine)" supplies the value "%spellout-masculine". * @return the formatted number. Note that no errors are reported; if the request is invalid, the number is formatted as if the string() function were used.- Returns:
- the formatted number. Note that no errors are reported; if the request is invalid, the number is formatted as if the string() function were used.
-
ordinalSuffix
protected java.lang.String ordinalSuffix(java.lang.String ordinalParam, long number)
Construct the ordinal suffix for a number, for example "st", "nd", "rd". The default (language-neutral) implementation returns a zero-length string- Parameters:
ordinalParam
- the value of the ordinal attribute (used in non-English language implementations)number
- the number being formatted- Returns:
- the ordinal suffix to be appended to the formatted number
-
alphaDefault
protected void alphaDefault(long number, char formchar, java.lang.StringBuilder sb)
Default processing with an alphabetic format token: use the contiguous range of Unicode letters starting with that token.- Parameters:
number
- the number to be formattedformchar
- the format character, for example 'A' for the numbering sequence A,B,Csb
- buffer to hold the result of the formatting
-
toAlpha
protected java.lang.String toAlpha(long number, int min, int max)
Format the number as an alphabetic label using the alphabet consisting of consecutive Unicode characters from min to max- Parameters:
number
- the number to be formattedmin
- the start of the Unicode codepoint rangemax
- the end of the Unicode codepoint range- Returns:
- the formatted number
-
toAlphaSequence
protected java.lang.String toAlphaSequence(long number, java.lang.String alphabet)
Convert the number into an alphabetic label using a given alphabet. For example, if the alphabet is "xyz" the sequence is x, y, z, xx, xy, xz, ....- Parameters:
number
- the number to be formattedalphabet
- a string containing the characters to be used, for example "abc...xyz"- Returns:
- the formatted number
-
convertDigitSystem
public static java.lang.String convertDigitSystem(long number, int[] digits, int requiredLength)
Convert a number to use a given set of digits, to a required length. For example, if the digits are "01" the sequence is 1, 10, 11, 100, 101, 110, 111, ... More commonly, the digits will be "0123456789", giving the usual decimal numbering.- Parameters:
number
- the number to be formatteddigits
- the codepoints to be used for the digitsrequiredLength
- the length of the picture that is significant: for example "3" if the picture is "001"- Returns:
- the converted number
-
toRoman
public static java.lang.String toRoman(long n)
Generate a Roman numeral (in lower case)- Parameters:
n
- the number to be formatted- Returns:
- the Roman numeral representation of the number in lower case
-
toJapanese
public java.lang.String toJapanese(long number)
Format the number in Japanese.- Parameters:
number
- the number to be formatted: formatted in Western decimal style unless in the range 1 to 9999- Returns:
- the Japanese Kanji representation of the number if in the range 1-9999
-
toWords
public abstract java.lang.String toWords(java.lang.String cardinal, long number)
Show the number as words in title case. (We choose title case because the result can then be converted algorithmically to lower case or upper case).- Parameters:
cardinal
- the value of the "cardinal" attribute as supplied by the usernumber
- the number to be formatted- Returns:
- the number formatted as English words
-
toWords
public java.lang.String toWords(java.lang.String cardinal, long number, int wordCase)
Format a number as English words with specified case options- Parameters:
cardinal
- the value of the "cardinal" attribute as supplied by the usernumber
- the number to be formattedwordCase
- the required case for exampleUPPER_CASE
,LOWER_CASE
,TITLE_CASE
- Returns:
- the formatted number
-
zero
public java.lang.String zero()
-
toOrdinalWords
public abstract java.lang.String toOrdinalWords(java.lang.String ordinalParam, long number, int wordCase)
Show an ordinal number as English words in a requested case (for example, Twentyfirst)- Parameters:
ordinalParam
- the value of the "ordinal" attribute as supplied by the usernumber
- the number to be formattedwordCase
- the required case for exampleUPPER_CASE
,LOWER_CASE
,TITLE_CASE
- Returns:
- the formatted number
-
monthName
public abstract java.lang.String monthName(int month, int minWidth, int maxWidth)
Get a month name or abbreviation
-
dayName
public abstract java.lang.String dayName(int day, int minWidth, int maxWidth)
Get a day name or abbreviation
-
halfDayName
public java.lang.String halfDayName(int minutes, int minWidth, int maxWidth)
Get an am/pm indicator. Default implementation works for English, on the basis that some other languages might like to copy this (most non-English countries don't actually use the 12-hour clock, so it's irrelevant).- Specified by:
halfDayName
in interfaceNumberer
- Parameters:
minutes
- the minutes within the dayminWidth
- minimum width of outputmaxWidth
- maximum width of output- Returns:
- the AM or PM indicator
-
getOrdinalSuffixForDateTime
public java.lang.String getOrdinalSuffixForDateTime(java.lang.String component)
Get an ordinal suffix for a particular component of a date/time.- Specified by:
getOrdinalSuffixForDateTime
in interfaceNumberer
- Parameters:
component
- the component specifier from a format-dateTime picture, for example "M" for the month or "D" for the day.- Returns:
- a string that is acceptable in the ordinal attribute of xsl:number to achieve the required ordinal representation. For example, "-e" for the day component in German, to have the day represented as "dritte August".
-
getEraName
public java.lang.String getEraName(int year)
Get the name for an era (e.g. "BC" or "AD")- Specified by:
getEraName
in interfaceNumberer
- Parameters:
year
- the proleptic gregorian year, using "0" for the year before 1AD- Returns:
- the name of the era, for example "AD"
-
getCalendarName
public java.lang.String getCalendarName(java.lang.String code)
Get the name of a calendar- Specified by:
getCalendarName
in interfaceNumberer
- Parameters:
code
- The code representing the calendar as in the XSLT 2.0 spec, e.g. AD for the Gregorian calendar- Returns:
- the name of the calendar, for example "AD"
-
-