StringComparatorImplpublic class StringComparatorImpl extends Object implements CommonStringComparatorThis class realizes string comparison methods of
{@link javax.microedition.global.StringComparator}. Specifically, these are:
- {@link #compare(String, String)}
- {@link #equals(String, String)}
This realization of StringComparator is intended to be based on
native string comparison functions. Regarding this,
StringComparatorImpl uses locale index that points to its locale
instead of working with explicit locale code. |
Fields Summary |
---|
private int | levelCurrent StringComparatorImpl level of comparison.
Possible values are:
- javax.microedition.global.StringComparator#LEVEL1
- javax.microedition.global.StringComparator#LEVEL2
- javax.microedition.global.StringComparator#LEVEL3
- javax.microedition.global.StringComparator#IDENTICAL
| private int | locale_indexCurrent StringComparatorImpl locale index in the list of
supported locales. |
Constructors Summary |
---|
public StringComparatorImpl(String locale, int level)Constructs an instance using the specified locale and collation level.
If the specified locale is null or the empty string, this
class uses the generic collation algorithm.
this.level = level;
locale_index = CollationAbstractionLayerImpl.getCollationLocaleIndex(locale);
if (locale_index == -1) {
throw new UnsupportedLocaleException("Locale \""
+ locale +
"\" unsupported.");
}
|
Methods Summary |
---|
public int | compare(java.lang.String s1, java.lang.String s2)Compares the two strings using the rules specific to the associated
locale of this instance. Use the equals method to more
conveniently test for equality.
if (s1 == null || s2 == null) {
throw new NullPointerException("Cannot compare null strings");
}
return compare0(locale_index, s1, s2, level);
| private static native int | compare0(int locale_index, java.lang.String s1, java.lang.String s2, int level)Compare two strings using locale- and level-specific rules.
| public boolean | equals(java.lang.String s1, java.lang.String s2)Tests if the two strings are equal according to the rules specific to
the associated locale of this instance.
return compare(s1, s2) == 0;
|
|