Java Doc for RuleBasedNumberFormat.java in  » Internationalization-Localization » icu4j » com » ibm » icu » text » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Internationalization Localization » icu4j » com.ibm.icu.text 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


com.ibm.icu.text.UFormat
   com.ibm.icu.text.NumberFormat
      com.ibm.icu.text.RuleBasedNumberFormat

RuleBasedNumberFormat
public class RuleBasedNumberFormat extends NumberFormat (Code)

A class that formats numbers according to a set of rules. This number formatter is typically used for spelling out numeric values in words (e.g., 25,3476 as "twenty-five thousand three hundred seventy-six" or "vingt-cinq mille trois cents soixante-seize" or "funfundzwanzigtausenddreihundertsechsundsiebzig"), but can also be used for other complicated formatting tasks, such as formatting a number of seconds as hours, minutes and seconds (e.g., 3,730 as "1:02:10").

The resources contain three predefined formatters for each locale: spellout, which spells out a value in words (123 is "one hundred twenty-three"); ordinal, which appends an ordinal suffix to the end of a numeral (123 is "123rd"); and duration, which shows a duration in seconds as hours, minutes, and seconds (123 is "2:03").  The client can also define more specialized RuleBasedNumberFormats by supplying programmer-defined rule sets.

The behavior of a RuleBasedNumberFormat is specified by a textual description that is either passed to the constructor as a String or loaded from a resource bundle. In its simplest form, the description consists of a semicolon-delimited list of rules. Each rule has a string of output text and a value or range of values it is applicable to. In a typical spellout rule set, the first twenty rules are the words for the numbers from 0 to 19:

zero; one; two; three; four; five; six; seven; eight; nine;
 ten; eleven; twelve; thirteen; fourteen; fifteen; sixteen; seventeen; eighteen; nineteen;

For larger numbers, we can use the preceding set of rules to format the ones place, and we only have to supply the words for the multiples of 10:

20: twenty[->>];
 30: thirty{->>];
 40: forty[->>];
 50: fifty[->>];
 60: sixty[->>];
 70: seventy[->>];
 80: eighty[->>];
 90: ninety[->>];

In these rules, the base value is spelled out explicitly and set off from the rule's output text with a colon. The rules are in a sorted list, and a rule is applicable to all numbers from its own base value to one less than the next rule's base value. The ">>" token is called a substitution and tells the fomatter to isolate the number's ones digit, format it using this same set of rules, and place the result at the position of the ">>" token. Text in brackets is omitted if the number being formatted is an even multiple of 10 (the hyphen is a literal hyphen; 24 is "twenty-four," not "twenty four").

For even larger numbers, we can actually look up several parts of the number in the list:

100: << hundred[ >>];

The "<<" represents a new kind of substitution. The << isolates the hundreds digit (and any digits to its left), formats it using this same rule set, and places the result where the "<<" was. Notice also that the meaning of >> has changed: it now refers to both the tens and the ones digits. The meaning of both substitutions depends on the rule's base value. The base value determines the rule's divisor, which is the highest power of 10 that is less than or equal to the base value (the user can change this). To fill in the substitutions, the formatter divides the number being formatted by the divisor. The integral quotient is used to fill in the << substitution, and the remainder is used to fill in the >> substitution. The meaning of the brackets changes similarly: text in brackets is omitted if the value being formatted is an even multiple of the rule's divisor. The rules are applied recursively, so if a substitution is filled in with text that includes another substitution, that substitution is also filled in.

This rule covers values up to 999, at which point we add another rule:

1000: << thousand[ >>];

Again, the meanings of the brackets and substitution tokens shift because the rule's base value is a higher power of 10, changing the rule's divisor. This rule can actually be used all the way up to 999,999. This allows us to finish out the rules as follows:

1,000,000: << million[ >>];
 1,000,000,000: << billion[ >>];
 1,000,000,000,000: << trillion[ >>];
 1,000,000,000,000,000: OUT OF RANGE!;

Commas, periods, and spaces can be used in the base values to improve legibility and are ignored by the rule parser. The last rule in the list is customarily treated as an "overflow rule," applying to everything from its base value on up, and often (as in this example) being used to print out an error message or default representation. Notice also that the size of the major groupings in large numbers is controlled by the spacing of the rules: because in English we group numbers by thousand, the higher rules are separated from each other by a factor of 1,000.

To see how these rules actually work in practice, consider the following example: Formatting 25,430 with this rule set would work like this:

<< thousand >> [the rule whose base value is 1,000 is applicable to 25,340]
twenty->> thousand >> [25,340 over 1,000 is 25. The rule for 20 applies.]
twenty-five thousand >> [25 mod 10 is 5. The rule for 5 is "five."
twenty-five thousand << hundred >> [25,340 mod 1,000 is 340. The rule for 100 applies.]
twenty-five thousand three hundred >> [340 over 100 is 3. The rule for 3 is "three."]
twenty-five thousand three hundred forty [340 mod 100 is 40. The rule for 40 applies. Since 40 divides evenly by 10, the hyphen and substitution in the brackets are omitted.]

The above syntax suffices only to format positive integers. To format negative numbers, we add a special rule:

-x: minus >>;

This is called a negative-number rule, and is identified by "-x" where the base value would be. This rule is used to format all negative numbers. the >> token here means "find the number's absolute value, format it with these rules, and put the result here."

We also add a special rule called a fraction rule for numbers with fractional parts:

x.x: << point >>;

This rule is used for all positive non-integers (negative non-integers pass through the negative-number rule first and then through this rule). Here, the << token refers to the number's integral part, and the >> to the number's fractional part. The fractional part is formatted as a series of single-digit numbers (e.g., 123.456 would be formatted as "one hundred twenty-three point four five six").

To see how this rule syntax is applied to various languages, examine the resource data.

There is actually much more flexibility built into the rule language than the description above shows. A formatter may own multiple rule sets, which can be selected by the caller, and which can use each other to fill in their substitutions. Substitutions can also be filled in with digits, using a DecimalFormat object. There is syntax that can be used to alter a rule's divisor in various ways. And there is provision for much more flexible fraction handling. A complete description of the rule syntax follows:


The description of a RuleBasedNumberFormat's behavior consists of one or more rule sets. Each rule set consists of a name, a colon, and a list of rules. A rule set name must begin with a % sign. Rule sets with names that begin with a single % sign are public: the caller can specify that they be used to format and parse numbers. Rule sets with names that begin with %% are private: they exist only for the use of other rule sets. If a formatter only has one rule set, the name may be omitted.

The user can also specify a special "rule set" named %%lenient-parse. The body of %%lenient-parse isn't a set of number-formatting rules, but a RuleBasedCollator description which is used to define equivalences for lenient parsing. For more information on the syntax, see RuleBasedCollator. For more information on lenient parsing, see setLenientParse(). Note: symbols that have syntactic meaning in collation rules, such as '&', have no particular meaning when appearing outside of the lenient-parse rule set.

The body of a rule set consists of an ordered, semicolon-delimited list of rules. Internally, every rule has a base value, a divisor, rule text, and zero, one, or two substitutions. These parameters are controlled by the description syntax, which consists of a rule descriptor, a colon, and a rule body.

A rule descriptor can take one of the following forms (text in italics is the name of a token):

bv: bv specifies the rule's base value. bv is a decimal number expressed using ASCII digits. bv may contain spaces, period, and commas, which are irgnored. The rule's divisor is the highest power of 10 less than or equal to the base value.
bv/rad: bv specifies the rule's base value. The rule's divisor is the highest power of rad less than or equal to the base value.
bv>: bv specifies the rule's base value. To calculate the divisor, let the radix be 10, and the exponent be the highest exponent of the radix that yields a result less than or equal to the base value. Every > character after the base value decreases the exponent by 1. If the exponent is positive or 0, the divisor is the radix raised to the power of the exponent; otherwise, the divisor is 1.
bv/rad>: bv specifies the rule's base value. To calculate the divisor, let the radix be rad, and the exponent be the highest exponent of the radix that yields a result less than or equal to the base value. Every > character after the radix decreases the exponent by 1. If the exponent is positive or 0, the divisor is the radix raised to the power of the exponent; otherwise, the divisor is 1.
-x: The rule is a negative-number rule.
x.x: The rule is an improper fraction rule.
0.x: The rule is a proper fraction rule.
x.0: The rule is a master rule.
nothing If the rule's rule descriptor is left out, the base value is one plus the preceding rule's base value (or zero if this is the first rule in the list) in a normal rule set.  In a fraction rule set, the base value is the same as the preceding rule's base value.

A rule set may be either a regular rule set or a fraction rule set, depending on whether it is used to format a number's integral part (or the whole number) or a number's fractional part. Using a rule set to format a rule's fractional part makes it a fraction rule set.

Which rule is used to format a number is defined according to one of the following algorithms: If the rule set is a regular rule set, do the following:

  • If the rule set includes a master rule (and the number was passed in as a double), use the master rule.  (If the number being formatted was passed in as a long, the master rule is ignored.)
  • If the number is negative, use the negative-number rule.
  • If the number has a fractional part and is greater than 1, use the improper fraction rule.
  • If the number has a fractional part and is between 0 and 1, use the proper fraction rule.
  • Binary-search the rule list for the rule with the highest base value less than or equal to the number. If that rule has two substitutions, its base value is not an even multiple of its divisor, and the number is an even multiple of the rule's divisor, use the rule that precedes it in the rule list. Otherwise, use the rule itself.

If the rule set is a fraction rule set, do the following:

  • Ignore negative-number and fraction rules.
  • For each rule in the list, multiply the number being formatted (which will always be between 0 and 1) by the rule's base value. Keep track of the distance between the result the nearest integer.
  • Use the rule that produced the result closest to zero in the above calculation. In the event of a tie or a direct hit, use the first matching rule encountered. (The idea here is to try each rule's base value as a possible denominator of a fraction. Whichever denominator produces the fraction closest in value to the number being formatted wins.) If the rule following the matching rule has the same base value, use it if the numerator of the fraction is anything other than 1; if the numerator is 1, use the original matching rule. (This is to allow singular and plural forms of the rule text without a lot of extra hassle.)

A rule's body consists of a string of characters terminated by a semicolon. The rule may include zero, one, or two substitution tokens, and a range of text in brackets. The brackets denote optional text (and may also include one or both substitutions). The exact meanings of the substitution tokens, and under what conditions optional text is omitted, depend on the syntax of the substitution token and the context. The rest of the text in a rule body is literal text that is output when the rule matches the number being formatted.

A substitution token begins and ends with a token character. The token character and the context together specify a mathematical operation to be performed on the number being formatted. An optional substitution descriptor specifies how the value resulting from that operation is used to fill in the substitution. The position of the substitution token in the rule body specifies the location of the resultant text in the original rule text.

The meanings of the substitution token characters are as follows:

>> in normal rule Divide the number by the rule's divisor and format the remainder
in negative-number rule Find the absolute value of the number and format the result
in fraction or master rule Isolate the number's fractional part and format it.
in rule in fraction rule set Not allowed.
>>> in normal rule Divide the number by the rule's divisor and format the remainder, but bypass the normal rule-selection process and just use the rule that precedes this one in this rule list.
in all other rules Not allowed.
<< in normal rule Divide the number by the rule's divisor and format the quotient
in negative-number rule Not allowed.
in fraction or master rule Isolate the number's integral part and format it.
in rule in fraction rule set Multiply the number by the rule's base value and format the result.
== in all rule sets Format the number unchanged
[] in normal rule Omit the optional text if the number is an even multiple of the rule's divisor
in negative-number rule Not allowed.
in improper-fraction rule Omit the optional text if the number is between 0 and 1 (same as specifying both an x.x rule and a 0.x rule)
in master rule Omit the optional text if the number is an integer (same as specifying both an x.x rule and an x.0 rule)
in proper-fraction rule Not allowed.
in rule in fraction rule set Omit the optional text if multiplying the number by the rule's base value yields 1.

The substitution descriptor (i.e., the text between the token characters) may take one of three forms:

a rule set name Perform the mathematical operation on the number, and format the result using the named rule set.
a DecimalFormat pattern Perform the mathematical operation on the number, and format the result using a DecimalFormat with the specified pattern.  The pattern must begin with 0 or #.
nothing Perform the mathematical operation on the number, and format the result using the rule set containing the current rule, except:
  • You can't have an empty substitution descriptor with a == substitution.
  • If you omit the substitution descriptor in a >> substitution in a fraction rule, format the result one digit at a time using the rule set containing the current rule.
  • If you omit the substitution descriptor in a << substitution in a rule in a fraction rule set, format the result using the default rule set for this formatter.

Whitespace is ignored between a rule set name and a rule set body, between a rule descriptor and a rule body, or between rules. If a rule body begins with an apostrophe, the apostrophe is ignored, but all text after it becomes significant (this is how you can have a rule's rule text begin with whitespace). There is no escape function: the semicolon is not allowed in rule set names or in rule text, and the colon is not allowed in rule set names. The characters beginning a substitution token are always treated as the beginning of a substitution token.

See the resource data and the demo program for annotated examples of real rule sets using these features.


author:
   Richard Gillam
See Also:   NumberFormat
See Also:   DecimalFormat


Field Summary
final public static  intDURATION
    
final public static  intORDINAL
    
final public static  intSPELLOUT
    
final static  longserialVersionUID
    

Constructor Summary
public  RuleBasedNumberFormat(String description)
     Creates a RuleBasedNumberFormat that behaves according to the description passed in.
public  RuleBasedNumberFormat(String description, String[][] localizations)
     Creates a RuleBasedNumberFormat that behaves according to the description passed in.
public  RuleBasedNumberFormat(String description, Locale locale)
     Creates a RuleBasedNumberFormat that behaves according to the description passed in.
public  RuleBasedNumberFormat(String description, ULocale locale)
     Creates a RuleBasedNumberFormat that behaves according to the description passed in.
public  RuleBasedNumberFormat(String description, String[][] localizations, ULocale locale)
     Creates a RuleBasedNumberFormat that behaves according to the description passed in.
public  RuleBasedNumberFormat(Locale locale, int format)
     Creates a RuleBasedNumberFormat from a predefined description.
public  RuleBasedNumberFormat(ULocale locale, int format)
     Creates a RuleBasedNumberFormat from a predefined description.
public  RuleBasedNumberFormat(int format)
     Creates a RuleBasedNumberFormat from a predefined description.

Method Summary
public  Objectclone()
     Duplicates this formatter.
public  booleanequals(Object that)
     Tests two RuleBasedNumberFormats for equality.
Parameters:
  that - The formatter to compare against this one.
 NFRuleSetfindRuleSet(String name)
     Returns the named rule set.
public  Stringformat(double number, String ruleSet)
     Formats the specified number according to the specified rule set.
Parameters:
  number - The number to format.
Parameters:
  ruleSet - The name of the rule set to format the number with.This must be the name of a valid public rule set for this formatter.
public  Stringformat(long number, String ruleSet)
     Formats the specified number according to the specified rule set. (If the specified rule set specifies a master ["x.0"] rule, this function ignores it.
public  StringBufferformat(double number, StringBuffer toAppendTo, FieldPosition ignore)
     Formats the specified number using the formatter's default rule set. (The default rule set is the last public rule set defined in the description.)
Parameters:
  number - The number to format.
Parameters:
  toAppendTo - A StringBuffer that the result should be appended to.
Parameters:
  ignore - This function doesn't examine or update the field position.
public  StringBufferformat(long number, StringBuffer toAppendTo, FieldPosition ignore)
     Formats the specified number using the formatter's default rule set. (The default rule set is the last public rule set defined in the description.) (If the specified rule set specifies a master ["x.0"] rule, this function ignores it.
public  StringBufferformat(BigInteger number, StringBuffer toAppendTo, FieldPosition pos)
     NEW Implement com.ibm.icu.text.NumberFormat: Format a BigInteger.
public  StringBufferformat(java.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)
     NEW Implement com.ibm.icu.text.NumberFormat: Format a BigDecimal.
public  StringBufferformat(com.ibm.icu.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)
     NEW Implement com.ibm.icu.text.NumberFormat: Format a BigDecimal.
 CollatorgetCollator()
     Returns the collator to use for lenient parsing.
 DecimalFormatSymbolsgetDecimalFormatSymbols()
     Returns the DecimalFormatSymbols object that should be used by all DecimalFormat instances owned by this formatter.
 NFRuleSetgetDefaultRuleSet()
     Returns a reference to the formatter's default rule set.
public  StringgetDefaultRuleSetName()
     Return the name of the current default rule set.
public  StringgetRuleSetDisplayName(String ruleSetName, ULocale locale)
     Return the rule set display name for the provided rule set and locale. The locale is matched against the locales for which there is display name data, using normal fallback rules.
public  StringgetRuleSetDisplayName(String ruleSetName)
     Return the rule set display name for the provided rule set in the current default locale.
public  ULocale[]getRuleSetDisplayNameLocales()
     Return a list of locales for which there are locale-specific display names for the rule sets in this formatter.
public  String[]getRuleSetDisplayNames(ULocale locale)
     Return the rule set display names for the provided locale.
public  String[]getRuleSetDisplayNames()
     Return the rule set display names for the current default locale.
public  String[]getRuleSetNames()
     Returns a list of the names of all of this formatter's public rule sets.
public  booleanlenientParseEnabled()
     Returns true if lenient-parse mode is turned on.
public  Numberparse(String text, ParsePosition parsePosition)
     Parses the specfied string, beginning at the specified position, according to this formatter's rules.
public  voidsetDefaultRuleSet(String ruleSetName)
     Override the default rule set to use.
public  voidsetLenientParseMode(boolean enabled)
     Turns lenient parse mode on and off. When in lenient parse mode, the formatter uses a Collator for parsing the text. Only primary differences are treated as significant.
public  StringtoString()
     Generates a textual description of this formatter. a String containing a rule set that will produce a RuleBasedNumberFormatwith identical behavior to this one.

Field Detail
DURATION
final public static int DURATION(Code)
Selector code that tells the constructor to create a duration formatter



ORDINAL
final public static int ORDINAL(Code)
Selector code that tells the constructor to create an ordinal formatter



SPELLOUT
final public static int SPELLOUT(Code)
Selector code that tells the constructor to create a spellout formatter



serialVersionUID
final static long serialVersionUID(Code)




Constructor Detail
RuleBasedNumberFormat
public RuleBasedNumberFormat(String description)(Code)
Creates a RuleBasedNumberFormat that behaves according to the description passed in. The formatter uses the default locale.
Parameters:
  description - A description of the formatter's desired behavior.See the class documentation for a complete explanation of the descriptionsyntax.



RuleBasedNumberFormat
public RuleBasedNumberFormat(String description, String[][] localizations)(Code)
Creates a RuleBasedNumberFormat that behaves according to the description passed in. The formatter uses the default locale.

The localizations data provides information about the public rule sets and their localized display names for different locales. The first element in the list is an array of the names of the public rule sets. The first element in this array is the initial default ruleset. The remaining elements in the list are arrays of localizations of the names of the public rule sets. Each of these is one longer than the initial array, with the first String being the ULocale ID, and the remaining Strings being the localizations of the rule set names, in the same order as the initial array.
Parameters:
  description - A description of the formatter's desired behavior.See the class documentation for a complete explanation of the descriptionsyntax.
Parameters:
  localizations - a list of localizations for the rule setnames in the description.




RuleBasedNumberFormat
public RuleBasedNumberFormat(String description, Locale locale)(Code)
Creates a RuleBasedNumberFormat that behaves according to the description passed in. The formatter uses the specified locale to determine the characters to use when formatting in numerals, and to define equivalences for lenient parsing.
Parameters:
  description - A description of the formatter's desired behavior.See the class documentation for a complete explanation of the descriptionsyntax.
Parameters:
  locale - A locale, which governs which characters are used forformatting values in numerals, and which characters are equivalent inlenient parsing.



RuleBasedNumberFormat
public RuleBasedNumberFormat(String description, ULocale locale)(Code)
Creates a RuleBasedNumberFormat that behaves according to the description passed in. The formatter uses the specified locale to determine the characters to use when formatting in numerals, and to define equivalences for lenient parsing.
Parameters:
  description - A description of the formatter's desired behavior.See the class documentation for a complete explanation of the descriptionsyntax.
Parameters:
  locale - A locale, which governs which characters are used forformatting values in numerals, and which characters are equivalent inlenient parsing.



RuleBasedNumberFormat
public RuleBasedNumberFormat(String description, String[][] localizations, ULocale locale)(Code)
Creates a RuleBasedNumberFormat that behaves according to the description passed in. The formatter uses the specified locale to determine the characters to use when formatting in numerals, and to define equivalences for lenient parsing.

The localizations data provides information about the public rule sets and their localized display names for different locales. The first element in the list is an array of the names of the public rule sets. The first element in this array is the initial default ruleset. The remaining elements in the list are arrays of localizations of the names of the public rule sets. Each of these is one longer than the initial array, with the first String being the ULocale ID, and the remaining Strings being the localizations of the rule set names, in the same order as the initial array.
Parameters:
  description - A description of the formatter's desired behavior.See the class documentation for a complete explanation of the descriptionsyntax.
Parameters:
  localizations - a list of localizations for the rule set names in the description.
Parameters:
  locale - A ulocale that governs which characters are used forformatting values in numerals, and determines which characters are equivalent inlenient parsing.




RuleBasedNumberFormat
public RuleBasedNumberFormat(Locale locale, int format)(Code)
Creates a RuleBasedNumberFormat from a predefined description. The selector code choosed among three possible predefined formats: spellout, ordinal, and duration.
Parameters:
  locale - The locale for the formatter.
Parameters:
  format - A selector code specifying which kind of formatter to create for thatlocale. There are three legal values: SPELLOUT, which creates a formatter thatspells out a value in words in the desired language, ORDINAL, which attachesan ordinal suffix from the desired language to the end of a number (e.g. "123rd"),and DURATION, which formats a duration in seconds as hours, minutes, and seconds.



RuleBasedNumberFormat
public RuleBasedNumberFormat(ULocale locale, int format)(Code)
Creates a RuleBasedNumberFormat from a predefined description. The selector code choosed among three possible predefined formats: spellout, ordinal, and duration.
Parameters:
  locale - The locale for the formatter.
Parameters:
  format - A selector code specifying which kind of formatter to create for thatlocale. There are three legal values: SPELLOUT, which creates a formatter thatspells out a value in words in the desired language, ORDINAL, which attachesan ordinal suffix from the desired language to the end of a number (e.g. "123rd"),and DURATION, which formats a duration in seconds as hours, minutes, and seconds.



RuleBasedNumberFormat
public RuleBasedNumberFormat(int format)(Code)
Creates a RuleBasedNumberFormat from a predefined description. Uses the default locale.
Parameters:
  format - A selector code specifying which kind of formatter to create.There are three legal values: SPELLOUT, which creates a formatter that spellsout a value in words in the default locale's langyage, ORDINAL, which attachesan ordinal suffix from the default locale's language to a numeral, andDURATION, which formats a duration in seconds as hours, minutes, and seconds.




Method Detail
clone
public Object clone()(Code)
Duplicates this formatter. A RuleBasedNumberFormat that is equal to this one.



equals
public boolean equals(Object that)(Code)
Tests two RuleBasedNumberFormats for equality.
Parameters:
  that - The formatter to compare against this one. true if the two formatters have identical behavior.



findRuleSet
NFRuleSet findRuleSet(String name) throws IllegalArgumentException(Code)
Returns the named rule set. Throws an IllegalArgumentException if this formatter doesn't have a rule set with that name.
Parameters:
  name - The name of the desired rule set The rule set with that name



format
public String format(double number, String ruleSet) throws IllegalArgumentException(Code)
Formats the specified number according to the specified rule set.
Parameters:
  number - The number to format.
Parameters:
  ruleSet - The name of the rule set to format the number with.This must be the name of a valid public rule set for this formatter. A textual representation of the number.



format
public String format(long number, String ruleSet) throws IllegalArgumentException(Code)
Formats the specified number according to the specified rule set. (If the specified rule set specifies a master ["x.0"] rule, this function ignores it. Convert the number to a double first if you ned it.) This function preserves all the precision in the long-- it doesn't convert it to a double.
Parameters:
  number - The number to format.
Parameters:
  ruleSet - The name of the rule set to format the number with.This must be the name of a valid public rule set for this formatter. A textual representation of the number.



format
public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition ignore)(Code)
Formats the specified number using the formatter's default rule set. (The default rule set is the last public rule set defined in the description.)
Parameters:
  number - The number to format.
Parameters:
  toAppendTo - A StringBuffer that the result should be appended to.
Parameters:
  ignore - This function doesn't examine or update the field position. toAppendTo



format
public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition ignore)(Code)
Formats the specified number using the formatter's default rule set. (The default rule set is the last public rule set defined in the description.) (If the specified rule set specifies a master ["x.0"] rule, this function ignores it. Convert the number to a double first if you ned it.) This function preserves all the precision in the long-- it doesn't convert it to a double.
Parameters:
  number - The number to format.
Parameters:
  toAppendTo - A StringBuffer that the result should be appended to.
Parameters:
  ignore - This function doesn't examine or update the field position. toAppendTo



format
public StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos)(Code)
NEW Implement com.ibm.icu.text.NumberFormat: Format a BigInteger.



format
public StringBuffer format(java.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)(Code)
NEW Implement com.ibm.icu.text.NumberFormat: Format a BigDecimal.



format
public StringBuffer format(com.ibm.icu.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)(Code)
NEW Implement com.ibm.icu.text.NumberFormat: Format a BigDecimal.



getCollator
Collator getCollator()(Code)
Returns the collator to use for lenient parsing. The collator is lazily created: this function creates it the first time it's called. The collator to use for lenient parsing, or null if lenient parsingis turned off.



getDecimalFormatSymbols
DecimalFormatSymbols getDecimalFormatSymbols()(Code)
Returns the DecimalFormatSymbols object that should be used by all DecimalFormat instances owned by this formatter. This object is lazily created: this function creates it the first time it's called. The DecimalFormatSymbols object that should be used by all DecimalFormatinstances owned by this formatter.



getDefaultRuleSet
NFRuleSet getDefaultRuleSet()(Code)
Returns a reference to the formatter's default rule set. The default rule set is the last public rule set in the description, or the one most recently set by setDefaultRuleSet. The formatter's default rule set.



getDefaultRuleSetName
public String getDefaultRuleSetName()(Code)
Return the name of the current default rule set. the name of the current default rule set, if it is public, else the empty string.



getRuleSetDisplayName
public String getRuleSetDisplayName(String ruleSetName, ULocale locale)(Code)
Return the rule set display name for the provided rule set and locale. The locale is matched against the locales for which there is display name data, using normal fallback rules. If no locale matches, the default display name is returned. the display name for the rule set
See Also:   RuleBasedNumberFormat.getRuleSetDisplayNames
throws:
  IllegalArgumentException - if ruleSetName is not a valid rule set name for this format



getRuleSetDisplayName
public String getRuleSetDisplayName(String ruleSetName)(Code)
Return the rule set display name for the provided rule set in the current default locale. the display name for the rule set
See Also:   RuleBasedNumberFormat.getRuleSetDisplayName(String,ULocale)



getRuleSetDisplayNameLocales
public ULocale[] getRuleSetDisplayNameLocales()(Code)
Return a list of locales for which there are locale-specific display names for the rule sets in this formatter. If there are no localized display names, return null. an array of the ulocales for which there is rule set display name information



getRuleSetDisplayNames
public String[] getRuleSetDisplayNames(ULocale locale)(Code)
Return the rule set display names for the provided locale. These are in the same order as those returned by getRuleSetNames. The locale is matched against the locales for which there is display name data, using normal fallback rules. If no locale matches, the default display names are returned. (These are the internal rule set names minus the leading '%'.) an array of the locales that have display name information
See Also:   RuleBasedNumberFormat.getRuleSetNames



getRuleSetDisplayNames
public String[] getRuleSetDisplayNames()(Code)
Return the rule set display names for the current default locale. an array of the display names
See Also:   RuleBasedNumberFormat.getRuleSetDisplayNames(ULocale)



getRuleSetNames
public String[] getRuleSetNames()(Code)
Returns a list of the names of all of this formatter's public rule sets. A list of the names of all of this formatter's public rule sets.



lenientParseEnabled
public boolean lenientParseEnabled()(Code)
Returns true if lenient-parse mode is turned on. Lenient parsing is off by default. true if lenient-parse mode is turned on.
See Also:   RuleBasedNumberFormat.setLenientParseMode



parse
public Number parse(String text, ParsePosition parsePosition)(Code)
Parses the specfied string, beginning at the specified position, according to this formatter's rules. This will match the string against all of the formatter's public rule sets and return the value corresponding to the longest parseable substring. This function's behavior is affected by the lenient parse mode.
Parameters:
  text - The string to parse
Parameters:
  parsePosition - On entry, contains the position of the first characterin "text" to examine. On exit, has been updated to contain the positionof the first character in "text" that wasn't consumed by the parse. The number that corresponds to the parsed text. This will be aninstance of either Long or Double, depending on whether the result has afractional part.
See Also:   RuleBasedNumberFormat.setLenientParseMode



setDefaultRuleSet
public void setDefaultRuleSet(String ruleSetName)(Code)
Override the default rule set to use. If ruleSetName is null, reset to the initial default rule set.
Parameters:
  ruleSetName - the name of the rule set, or null to reset the initial default.
throws:
  IllegalArgumentException - if ruleSetName is not the name of a public ruleset.



setLenientParseMode
public void setLenientParseMode(boolean enabled)(Code)
Turns lenient parse mode on and off. When in lenient parse mode, the formatter uses a Collator for parsing the text. Only primary differences are treated as significant. This means that case differences, accent differences, alternate spellings of the same letter (e.g., ae and a-umlaut in German), ignorable characters, etc. are ignored in matching the text. In many cases, numerals will be accepted in place of words or phrases as well. For example, all of the following will correctly parse as 255 in English in lenient-parse mode:
"two hundred fifty-five"
"two hundred fifty five"
"TWO HUNDRED FIFTY-FIVE"
"twohundredfiftyfive"
"2 hundred fifty-5" The Collator used is determined by the locale that was passed to this object on construction. The description passed to this object on construction may supply additional collation rules that are appended to the end of the default collator for the locale, enabling additional equivalences (such as adding more ignorable characters or permitting spelled-out version of symbols; see the demo program for examples). It's important to emphasize that even strict parsing is relatively lenient: it will accept some text that it won't produce as output. In English, for example, it will correctly parse "two hundred zero" and "fifteen hundred".
Parameters:
  enabled - If true, turns lenient-parse mode on; if false, turns it off.
See Also:   RuleBasedCollator



toString
public String toString()(Code)
Generates a textual description of this formatter. a String containing a rule set that will produce a RuleBasedNumberFormatwith identical behavior to this one. This won't necessarily be identicalto the rule set description that was originally passed in, but will producethe same result.



Fields inherited from com.ibm.icu.text.NumberFormat
final public static int FRACTION_FIELD(Code)(Java Doc)
final public static int INTEGER_FIELD(Code)(Java Doc)
final static int currentSerialVersion(Code)(Java Doc)

Methods inherited from com.ibm.icu.text.NumberFormat
public Object clone()(Code)(Java Doc)
static NumberFormat createInstance(ULocale desiredLocale, int choice)(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
public StringBuffer format(Object number, StringBuffer toAppendTo, FieldPosition pos)(Code)(Java Doc)
final public String format(double number)(Code)(Java Doc)
final public String format(long number)(Code)(Java Doc)
final public String format(BigInteger number)(Code)(Java Doc)
final public String format(java.math.BigDecimal number)(Code)(Java Doc)
final public String format(com.ibm.icu.math.BigDecimal number)(Code)(Java Doc)
final public String format(CurrencyAmount currAmt)(Code)(Java Doc)
abstract public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos)(Code)(Java Doc)
abstract public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos)(Code)(Java Doc)
abstract public StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos)(Code)(Java Doc)
abstract public StringBuffer format(java.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)(Code)(Java Doc)
abstract public StringBuffer format(com.ibm.icu.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)(Code)(Java Doc)
public StringBuffer format(CurrencyAmount currAmt, StringBuffer toAppendTo, FieldPosition pos)(Code)(Java Doc)
public static Locale[] getAvailableLocales()(Code)(Java Doc)
public static ULocale[] getAvailableULocales()(Code)(Java Doc)
public Currency getCurrency()(Code)(Java Doc)
final public static NumberFormat getCurrencyInstance()(Code)(Java Doc)
public static NumberFormat getCurrencyInstance(Locale inLocale)(Code)(Java Doc)
public static NumberFormat getCurrencyInstance(ULocale inLocale)(Code)(Java Doc)
protected Currency getEffectiveCurrency()(Code)(Java Doc)
final public static NumberFormat getInstance()(Code)(Java Doc)
public static NumberFormat getInstance(Locale inLocale)(Code)(Java Doc)
public static NumberFormat getInstance(ULocale inLocale)(Code)(Java Doc)
final public static NumberFormat getIntegerInstance()(Code)(Java Doc)
public static NumberFormat getIntegerInstance(Locale inLocale)(Code)(Java Doc)
public static NumberFormat getIntegerInstance(ULocale inLocale)(Code)(Java Doc)
public int getMaximumFractionDigits()(Code)(Java Doc)
public int getMaximumIntegerDigits()(Code)(Java Doc)
public int getMinimumFractionDigits()(Code)(Java Doc)
public int getMinimumIntegerDigits()(Code)(Java Doc)
final public static NumberFormat getNumberInstance()(Code)(Java Doc)
public static NumberFormat getNumberInstance(Locale inLocale)(Code)(Java Doc)
public static NumberFormat getNumberInstance(ULocale inLocale)(Code)(Java Doc)
protected static String getPattern(Locale forLocale, int choice)(Code)(Java Doc)
protected static String getPattern(ULocale forLocale, int choice)(Code)(Java Doc)
final public static NumberFormat getPercentInstance()(Code)(Java Doc)
public static NumberFormat getPercentInstance(Locale inLocale)(Code)(Java Doc)
public static NumberFormat getPercentInstance(ULocale inLocale)(Code)(Java Doc)
final public static NumberFormat getScientificInstance()(Code)(Java Doc)
public static NumberFormat getScientificInstance(Locale inLocale)(Code)(Java Doc)
public static NumberFormat getScientificInstance(ULocale inLocale)(Code)(Java Doc)
public int hashCode()(Code)(Java Doc)
public boolean isGroupingUsed()(Code)(Java Doc)
public boolean isParseIntegerOnly()(Code)(Java Doc)
public boolean isParseStrict()(Code)(Java Doc)
abstract public Number parse(String text, ParsePosition parsePosition)(Code)(Java Doc)
public Number parse(String text) throws ParseException(Code)(Java Doc)
CurrencyAmount parseCurrency(String text, ParsePosition pos)(Code)(Java Doc)
final public Object parseObject(String source, ParsePosition parsePosition)(Code)(Java Doc)
public static Object registerFactory(NumberFormatFactory factory)(Code)(Java Doc)
public void setCurrency(Currency theCurrency)(Code)(Java Doc)
public void setGroupingUsed(boolean newValue)(Code)(Java Doc)
public void setMaximumFractionDigits(int newValue)(Code)(Java Doc)
public void setMaximumIntegerDigits(int newValue)(Code)(Java Doc)
public void setMinimumFractionDigits(int newValue)(Code)(Java Doc)
public void setMinimumIntegerDigits(int newValue)(Code)(Java Doc)
public void setParseIntegerOnly(boolean value)(Code)(Java Doc)
public void setParseStrict(boolean value)(Code)(Java Doc)
public static boolean unregister(Object registryKey)(Code)(Java Doc)

Methods inherited from com.ibm.icu.text.UFormat
final public ULocale getLocale(ULocale.Type type)(Code)(Java Doc)
final void setLocale(ULocale valid, ULocale actual)(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.