16. The java.text Package
Contents:
The package java.text is new as of Java 1.1. It contains classes that support the internationalization of Java programs. The internationalization classes can be grouped as follows:
Many of the classes in java.text rely upon a java.util.Locale object to provide information about the locale that is in use. The Format class is the superclass of all of the classes that generate and parse string representations of various types of data. The DateFormat class formats and parses dates and times according to the customs and language of a particular locale. Similarly, the NumberFormat class formats and parses numbers, including currency values, in a locale-dependent manner. The MessageFormat class can create a textual message from a pattern string, while ChoiceFormat maps numerical ranges to strings. By themselves, these classes do not provide different results for different locales. However, they can be used in conjunction with java.util.ResourceBundle objects that generate locale-specific pattern strings. The Collator class handles collating strings according to the rules of a particular locale. Different languages have different characters and different rules for sorting those characters; Collator and its subclass, RuleBasedCollator, are designed to take those differences into account when collating strings. In addition, the CollationKey class can be used to optimize the sorting of a large collection of strings. The BreakIterator class finds various boundaries, such as word boundaries and line boundaries, in textual data. Again, BreakIterator locates these boundaries according to the rules of a particular locale. Figure 16.1 shows the class hierarchy for the java.text package. BreakIteratorNameBreakIteratorSynopsis
DescriptionThe BreakIterator class is an abstract class that defines methods that find the locations of boundaries in text, such as word boundaries and sentence boundaries. A BreakIterator operates on the object passed to its setText() method; that object must implement the CharacterIterator interface or be a String object. When a String is passed to setText(), the BreakIterator creates an internal StringCharacterIterator to iterate over the String. When you use a BreakIterator, you call first() to get the location of the first boundary and then repeatedly call next() to iterate through the subsequent boundaries. The BreakIterator class defines four static factory methods that return instances of BreakIterator that locate various kinds of boundaries. Each of these factory methods selects a concrete subclass of BreakIterator based either on the default locale or a specified locale. You must create a separate instance of BreakIterator to handle each kind of boundary you are trying to locate:
Class Summary
public abstract class java.util.BreakIterator extends java.lang.Object implements java.lang.Cloneable, java.io.Serializable { // Constants public final static int DONE; // Constructors protected BreakIterator(); // Class Methods public static synchronized Locale[] getAvailableLocales(); public static BreakIterator getCharacterInstance(); public static BreakIterator getCharacterInstance(Locale where); public static BreakIterator getLineInstance(); public static BreakIterator getLineInstance(Locale where); public static BreakIterator getSentenceInstance(); public static BreakIterator getSentenceInstance(Locale where); public static BreakIterator getWordInstance(); public static BreakIterator getWordInstance(Locale where); // Instance Methods public Object clone(); public abstract int current(); public abstract int first(); public abstract int following(int offset); public abstract CharacterIterator getText(); public abstract int last(); public abstract int next(); public abstract int next(int n) public abstract int previous(); public abstract void setText(CharacterIterator newText); public void setText(String newText); } ConstantsDONEpublic final static int DONE
ConstructorsBreakIteratorprotected BreakIterator()
Class MethodsgetAvailableLocalespublic static synchronized Locale[] getAvailableLocales()
getCharacterInstancepublic static BreakIterator getCharacterInstance()
public static BreakIterator getCharacterInstance(Locale where)
getLineInstancepublic static BreakIterator getLineInstance()
public static BreakIterator getLineInstance(Locale where)
getSentenceInstancepublic static BreakIterator getSentenceInstance()
public static BreakIterator getSentenceInstance(Locale where)
getWordInstancepublic static BreakIterator getWordInstance()
public static BreakIterator getWordInstance(Locale where)
Instance Methodsclonepublic Object clone()
currentpublic abstract int current()
firstpublic abstract int first()
followingpublic abstract int following(int offset)
getTextpublic abstract CharacterIterator getText()
lastpublic abstract int last()
nextpublic abstract int next()
public abstract int next(int n)
previouspublic abstract int previous()
setTextpublic abstract void setText(CharacterIterator newText)
public void setText(String newText)
Inherited Methods
See AlsoCharacterIterator, Locale, String, StringCharacterIterator | ||||||||||||||||||||||||
|