|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.text.Collator
public abstract class Collator
This class is the abstract superclass of classes which perform
locale dependent String
comparisons. A caller requests
an instance of Collator
for a particular locale using
the getInstance()
static method in this class. That method
will return a locale specific subclass of Collator
which
can be used to perform String
comparisons for that locale.
If a subclass of Collator
cannot be located for a particular
locale, a default instance for the current locale will be returned.
In addition to setting the correct locale, there are two additional
settings that can be adjusted to affect String
comparisons:
strength and decomposition. The strength value determines the level
of signficance of character differences required for them to sort
differently. (For example, whether or not capital letters are considered
different from lower case letters). The decomposition value affects how
variants of the same character are treated for sorting purposes. (For
example, whether or not an accent is signficant or not). These settings
are described in detail in the documentation for the methods and values
that are related to them.
Field Summary | |
---|---|
static int |
CANONICAL_DECOMPOSITION
This constant indicates that only characters which are canonical variants in Unicode 2.0 will be decomposed prior to performing comparisons. |
static int |
FULL_DECOMPOSITION
This constant indicates that both canonical variants and compatibility variants in Unicode 2.0 will be decomposed prior to performing comparisons. |
static int |
IDENTICAL
This constant is a strength value which indicates that any difference at all between character values are considered significant. |
static int |
NO_DECOMPOSITION
This constant indicates that accented characters won't be decomposed when performing comparisons. |
static int |
PRIMARY
This constant is a strength value which indicates that only primary differences between characters will be considered signficant. |
static int |
SECONDARY
This constant is a strength value which indicates that only secondary or primary differences between characters will be considered significant. |
static int |
TERTIARY
This constant is a strength value which indicates that tertiary, secondary, and primary differences will be considered during sorting. |
Constructor Summary | |
---|---|
protected |
Collator()
This method initializes a new instance of Collator to have
the default strength (TERTIARY) and decomposition
(CANONICAL_DECOMPOSITION) settings. |
Method Summary | |
---|---|
Object |
clone()
This method returns a copy of this Collator object. |
int |
compare(Object o1,
Object o2)
This method compares the two Object 's and returns an
integer indicating whether or not the first argument is less than,
equal to, or greater than the second argument. |
abstract int |
compare(String source,
String target)
This method compares the two String 's and returns an
integer indicating whether or not the first argument is less than,
equal to, or greater than the second argument. |
boolean |
equals(Object obj)
This method tests the specified object for equality against this object. |
boolean |
equals(String source,
String target)
This method tests whether the specified String 's are equal
according to the collation rules for the locale of this object and
the current strength and decomposition settings. |
static Locale[] |
getAvailableLocales()
This method returns an array of Locale objects which is
the list of locales for which Collator objects exist. |
abstract CollationKey |
getCollationKey(String source)
This method transforms the specified String into a
CollationKey for faster comparisons. |
int |
getDecomposition()
This method returns the current decomposition setting for this object. |
static Collator |
getInstance()
This method returns an instance of Collator for the
default locale. |
static Collator |
getInstance(Locale loc)
This method returns an instance of Collator for the
specified locale. |
int |
getStrength()
This method returns the current strength setting for this object. |
abstract int |
hashCode()
This method returns a hash code value for this object. |
void |
setDecomposition(int mode)
This method sets the decomposition setting for this object to the specified value. |
void |
setStrength(int strength)
This method sets the strength setting for this object to the specified value. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int PRIMARY
public static final int SECONDARY
public static final int TERTIARY
public static final int IDENTICAL
public static final int NO_DECOMPOSITION
public static final int CANONICAL_DECOMPOSITION
public static final int FULL_DECOMPOSITION
Constructor Detail |
---|
protected Collator()
Collator
to have
the default strength (TERTIARY) and decomposition
(CANONICAL_DECOMPOSITION) settings. This constructor is protected and
is for use by subclasses only. Non-subclass callers should use the
static getInstance()
methods of this class to instantiate
Collation
objects for the desired locale.
Method Detail |
---|
public abstract int compare(String source, String target)
String
's and returns an
integer indicating whether or not the first argument is less than,
equal to, or greater than the second argument. The comparison is
performed according to the rules of the locale for this
Collator
and the strength and decomposition rules in
effect.
source
- The first object to comparetarget
- The second object to compare
public int compare(Object o1, Object o2)
Object
's and returns an
integer indicating whether or not the first argument is less than,
equal to, or greater than the second argument. These two objects
must be String
's or an exception will be thrown.
compare
in interface Comparator<Object>
o1
- The first object to compareo2
- The second object to compare
ClassCastException
- If the arguments are not instances
of String
.public boolean equals(Object obj)
null
.Collator
.
equals
in interface Comparator<Object>
equals
in class Object
obj
- The Object
to test for equality against
this object.
true
if the specified object is equal to
this one, false
otherwise.Object.hashCode()
public boolean equals(String source, String target)
String
's are equal
according to the collation rules for the locale of this object and
the current strength and decomposition settings.
source
- The first String
to comparetarget
- The second String
to compare
true
if the two strings are equal,
false
otherwise.public Object clone()
Collator
object.
clone
in class Object
Cloneable
public static Locale[] getAvailableLocales()
Locale
objects which is
the list of locales for which Collator
objects exist.
Collator
's exist.public abstract CollationKey getCollationKey(String source)
String
into a
CollationKey
for faster comparisons. This is useful when
comparisons against a string might be performed multiple times, such
as during a sort operation.
source
- The String
to convert.
CollationKey
for the specified String
.public int getDecomposition()
public static Collator getInstance()
Collator
for the
default locale.
Collator
for the default locale.public static Collator getInstance(Locale loc)
Collator
for the
specified locale. If no Collator
exists for the desired
locale, the fallback procedure described in
LocaleServiceProvider
is invoked.
loc
- The desired locale to load a Collator
for.
Collator
for the requested localepublic int getStrength()
public abstract int hashCode()
hashCode
in class Object
Object.equals(Object)
,
System.identityHashCode(Object)
public void setDecomposition(int mode)
mode
- The new decomposition setting.
IllegalArgumentException
- If the requested
decomposition setting is not valid.public void setStrength(int strength)
strength
- The new strength setting.
IllegalArgumentException
- If the requested strength
setting value is not valid.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |