下面列出了java.text.Collator#setDecomposition ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* @tests java.text.Collator#setDecomposition(int)
*/
//FIXME This test fails on Harmony ClassLibrary
public void failing_test_setDecompositionI() {
Collator c = Collator.getInstance(Locale.FRENCH);
c.setStrength(Collator.IDENTICAL);
c.setDecomposition(Collator.NO_DECOMPOSITION);
assertTrue("Collator should not be using decomposition", !c.equals(
"\u212B", "\u00C5")); // "ANGSTROM SIGN" and "LATIN CAPITAL
// LETTER A WITH RING ABOVE"
c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
assertTrue("Collator should be using decomposition", c.equals("\u212B",
"\u00C5")); // "ANGSTROM SIGN" and "LATIN CAPITAL LETTER A WITH
// RING ABOVE"
assertTrue("Should not be equal under canonical decomposition", !c
.equals("\u2163", "IV")); // roman number "IV"
c.setDecomposition(Collator.FULL_DECOMPOSITION);
assertTrue("Should be equal under full decomposition", c.equals(
"\u2163", "IV")); // roman number "IV"
}
/**
* ECMA 15.5.4.9 String.prototype.localeCompare (that)
* @param self self reference
* @param that comparison object
* @return result of locale sensitive comparison operation between {@code self} and {@code that}
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static double localeCompare(final Object self, final Object that) {
final String str = checkObjectToString(self);
final Collator collator = Collator.getInstance(Global.getEnv()._locale);
collator.setStrength(Collator.IDENTICAL);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
return collator.compare(str, JSType.toString(that));
}
/**
* ECMA 15.5.4.9 String.prototype.localeCompare (that)
* @param self self reference
* @param that comparison object
* @return result of locale sensitive comparison operation between {@code self} and {@code that}
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static double localeCompare(final Object self, final Object that) {
final String str = checkObjectToString(self);
final Collator collator = Collator.getInstance(Global.getEnv()._locale);
collator.setStrength(Collator.IDENTICAL);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
return collator.compare(str, JSType.toString(that));
}
/**
* This doesn't output the string, but actually the collator byte stream
* which should be used as the uniqueness key. See ForBenefitOfUtilTest for examples
* of things that should or should not match each other.
*/
public static ByteString normalize(String input)
{
String n1 = Normalizer.normalize(input, Normalizer.Form.NFC);
// Not trying to be US-English centric, but have to pick some Locale
// so that this section will behave consistently for all nodes
Collator collator = Collator.getInstance(Locale.US);
collator.setStrength(Collator.PRIMARY);
collator.setDecomposition(Collator.FULL_DECOMPOSITION);
return ByteString.copyFrom(collator.getCollationKey(n1).toByteArray());
}
/**
* ECMA 15.5.4.9 String.prototype.localeCompare (that)
* @param self self reference
* @param that comparison object
* @return result of locale sensitive comparison operation between {@code self} and {@code that}
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static double localeCompare(final Object self, final Object that) {
final String str = checkObjectToString(self);
final Collator collator = Collator.getInstance(Global.getEnv()._locale);
collator.setStrength(Collator.IDENTICAL);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
return collator.compare(str, JSType.toString(that));
}
/**
* ECMA 15.5.4.9 String.prototype.localeCompare (that)
* @param self self reference
* @param that comparison object
* @return result of locale sensitive comparison operation between {@code self} and {@code that}
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static double localeCompare(final Object self, final Object that) {
final String str = checkObjectToString(self);
final Collator collator = Collator.getInstance(Global.getEnv()._locale);
collator.setStrength(Collator.IDENTICAL);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
return collator.compare(str, JSType.toString(that));
}
/**
* ECMA 15.5.4.9 String.prototype.localeCompare (that)
* @param self self reference
* @param that comparison object
* @return result of locale sensitive comparison operation between {@code self} and {@code that}
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static double localeCompare(final Object self, final Object that) {
final String str = checkObjectToString(self);
final Collator collator = Collator.getInstance(Global.getEnv()._locale);
collator.setStrength(Collator.IDENTICAL);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
return collator.compare(str, JSType.toString(that));
}
/**
* ECMA 15.5.4.9 String.prototype.localeCompare (that)
* @param self self reference
* @param that comparison object
* @return result of locale sensitive comparison operation between {@code self} and {@code that}
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static double localeCompare(final Object self, final Object that) {
final String str = checkObjectToString(self);
final Collator collator = Collator.getInstance(Global.getEnv()._locale);
collator.setStrength(Collator.IDENTICAL);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
return collator.compare(str, JSType.toString(that));
}
/**
* ECMA 15.5.4.9 String.prototype.localeCompare (that)
* @param self self reference
* @param that comparison object
* @return result of locale sensitive comparison operation between {@code self} and {@code that}
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object localeCompare(final Object self, final Object that) {
final String str = checkObjectToString(self);
final Collator collator = Collator.getInstance(Global.getEnv()._locale);
collator.setStrength(Collator.IDENTICAL);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
return (double)collator.compare(str, JSType.toString(that));
}
/**
* ECMA 15.5.4.9 String.prototype.localeCompare (that)
* @param self self reference
* @param that comparison object
* @return result of locale sensitive comparison operation between {@code self} and {@code that}
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object localeCompare(final Object self, final Object that) {
final String str = checkObjectToString(self);
final Collator collator = Collator.getInstance(Global.getEnv()._locale);
collator.setStrength(Collator.IDENTICAL);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
return (double)collator.compare(str, JSType.toString(that));
}
/**
* ECMA 15.5.4.9 String.prototype.localeCompare (that)
* @param self self reference
* @param that comparison object
* @return result of locale sensitive comparison operation between {@code self} and {@code that}
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static double localeCompare(final Object self, final Object that) {
final String str = checkObjectToString(self);
final Collator collator = Collator.getInstance(Global.getEnv()._locale);
collator.setStrength(Collator.IDENTICAL);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
return collator.compare(str, JSType.toString(that));
}
/**
* ECMA 15.5.4.9 String.prototype.localeCompare (that)
* @param self self reference
* @param that comparison object
* @return result of locale sensitive comparison operation between {@code self} and {@code that}
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object localeCompare(final Object self, final Object that) {
final String str = checkObjectToString(self);
final Collator collator = Collator.getInstance(Global.getEnv()._locale);
collator.setStrength(Collator.IDENTICAL);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
return (double)collator.compare(str, JSType.toString(that));
}
/**
* Returns a {@link Collator} for this realm's locale
*
* @deprecated No longer used
* @return the locale specific collator
*/
@Deprecated
public Collator getCollator() {
Collator collator = Collator.getInstance(getLocale());
// Use Normalized Form D for comparison (cf. 21.1.3.10, Note 2)
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
// `"\u0001".localeCompare("\u0002") == -1` should yield true
collator.setStrength(Collator.IDENTICAL);
return collator;
}
public final void TestProperty( )
{
Collator col = null;
try {
col = Collator.getInstance(Locale.ROOT);
logln("The property tests begin : ");
logln("Test ctors : ");
doAssert(col.compare("ab", "abc") < 0, "ab < abc comparison failed");
doAssert(col.compare("ab", "AB") < 0, "ab < AB comparison failed");
doAssert(col.compare("black-bird", "blackbird") > 0, "black-bird > blackbird comparison failed");
doAssert(col.compare("black bird", "black-bird") < 0, "black bird < black-bird comparison failed");
doAssert(col.compare("Hello", "hello") > 0, "Hello > hello comparison failed");
logln("Test ctors ends.");
logln("testing Collator.getStrength() method ...");
doAssert(col.getStrength() == Collator.TERTIARY, "collation object has the wrong strength");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
logln("testing Collator.setStrength() method ...");
col.setStrength(Collator.SECONDARY);
doAssert(col.getStrength() != Collator.TERTIARY, "collation object's strength is secondary difference");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
doAssert(col.getStrength() == Collator.SECONDARY, "collation object has the wrong strength");
logln("testing Collator.setDecomposition() method ...");
col.setDecomposition(Collator.NO_DECOMPOSITION);
doAssert(col.getDecomposition() != Collator.FULL_DECOMPOSITION, "collation object's strength is secondary difference");
doAssert(col.getDecomposition() != Collator.CANONICAL_DECOMPOSITION, "collation object's strength is primary difference");
doAssert(col.getDecomposition() == Collator.NO_DECOMPOSITION, "collation object has the wrong strength");
} catch (Exception foo) {
errln("Error : " + foo.getMessage());
errln("Default Collator creation failed.");
}
logln("Default collation property test ended.");
logln("Collator.getRules() testing ...");
doAssert(((RuleBasedCollator)col).getRules().length() != 0, "getRules() result incorrect" );
logln("getRules tests end.");
try {
col = Collator.getInstance(Locale.FRENCH);
col.setStrength(Collator.PRIMARY);
logln("testing Collator.getStrength() method again ...");
doAssert(col.getStrength() != Collator.TERTIARY, "collation object has the wrong strength");
doAssert(col.getStrength() == Collator.PRIMARY, "collation object's strength is not primary difference");
logln("testing French Collator.setStrength() method ...");
col.setStrength(Collator.TERTIARY);
doAssert(col.getStrength() == Collator.TERTIARY, "collation object's strength is not tertiary difference");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
doAssert(col.getStrength() != Collator.SECONDARY, "collation object's strength is secondary difference");
} catch (Exception bar) {
errln("Error : " + bar.getMessage());
errln("Creating French collation failed.");
}
logln("Create junk collation: ");
Locale abcd = new Locale("ab", "CD", "");
Collator junk = null;
try {
junk = Collator.getInstance(abcd);
} catch (Exception err) {
errln("Error : " + err.getMessage());
errln("Junk collation creation failed, should at least return the collator for the base bundle.");
}
try {
col = Collator.getInstance(Locale.ROOT);
doAssert(col.equals(junk), "The base bundle's collation should be returned.");
} catch (Exception exc) {
errln("Error : " + exc.getMessage());
errln("Default collation comparison, caching not working.");
}
logln("Collator property test ended.");
}
public final void TestProperty( )
{
Collator col = null;
try {
col = Collator.getInstance(Locale.ROOT);
logln("The property tests begin : ");
logln("Test ctors : ");
doAssert(col.compare("ab", "abc") < 0, "ab < abc comparison failed");
doAssert(col.compare("ab", "AB") < 0, "ab < AB comparison failed");
doAssert(col.compare("black-bird", "blackbird") > 0, "black-bird > blackbird comparison failed");
doAssert(col.compare("black bird", "black-bird") < 0, "black bird < black-bird comparison failed");
doAssert(col.compare("Hello", "hello") > 0, "Hello > hello comparison failed");
logln("Test ctors ends.");
logln("testing Collator.getStrength() method ...");
doAssert(col.getStrength() == Collator.TERTIARY, "collation object has the wrong strength");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
logln("testing Collator.setStrength() method ...");
col.setStrength(Collator.SECONDARY);
doAssert(col.getStrength() != Collator.TERTIARY, "collation object's strength is secondary difference");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
doAssert(col.getStrength() == Collator.SECONDARY, "collation object has the wrong strength");
logln("testing Collator.setDecomposition() method ...");
col.setDecomposition(Collator.NO_DECOMPOSITION);
doAssert(col.getDecomposition() != Collator.FULL_DECOMPOSITION, "collation object's strength is secondary difference");
doAssert(col.getDecomposition() != Collator.CANONICAL_DECOMPOSITION, "collation object's strength is primary difference");
doAssert(col.getDecomposition() == Collator.NO_DECOMPOSITION, "collation object has the wrong strength");
} catch (Exception foo) {
errln("Error : " + foo.getMessage());
errln("Default Collator creation failed.");
}
logln("Default collation property test ended.");
logln("Collator.getRules() testing ...");
doAssert(((RuleBasedCollator)col).getRules().length() != 0, "getRules() result incorrect" );
logln("getRules tests end.");
try {
col = Collator.getInstance(Locale.FRENCH);
col.setStrength(Collator.PRIMARY);
logln("testing Collator.getStrength() method again ...");
doAssert(col.getStrength() != Collator.TERTIARY, "collation object has the wrong strength");
doAssert(col.getStrength() == Collator.PRIMARY, "collation object's strength is not primary difference");
logln("testing French Collator.setStrength() method ...");
col.setStrength(Collator.TERTIARY);
doAssert(col.getStrength() == Collator.TERTIARY, "collation object's strength is not tertiary difference");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
doAssert(col.getStrength() != Collator.SECONDARY, "collation object's strength is secondary difference");
} catch (Exception bar) {
errln("Error : " + bar.getMessage());
errln("Creating French collation failed.");
}
logln("Create junk collation: ");
Locale abcd = new Locale("ab", "CD", "");
Collator junk = null;
try {
junk = Collator.getInstance(abcd);
} catch (Exception err) {
errln("Error : " + err.getMessage());
errln("Junk collation creation failed, should at least return the collator for the base bundle.");
}
try {
col = Collator.getInstance(Locale.ROOT);
doAssert(col.equals(junk), "The base bundle's collation should be returned.");
} catch (Exception exc) {
errln("Error : " + exc.getMessage());
errln("Default collation comparison, caching not working.");
}
logln("Collator property test ended.");
}
public final void TestProperty( )
{
Collator col = null;
try {
col = Collator.getInstance(Locale.ROOT);
logln("The property tests begin : ");
logln("Test ctors : ");
doAssert(col.compare("ab", "abc") < 0, "ab < abc comparison failed");
doAssert(col.compare("ab", "AB") < 0, "ab < AB comparison failed");
doAssert(col.compare("black-bird", "blackbird") > 0, "black-bird > blackbird comparison failed");
doAssert(col.compare("black bird", "black-bird") < 0, "black bird < black-bird comparison failed");
doAssert(col.compare("Hello", "hello") > 0, "Hello > hello comparison failed");
logln("Test ctors ends.");
logln("testing Collator.getStrength() method ...");
doAssert(col.getStrength() == Collator.TERTIARY, "collation object has the wrong strength");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
logln("testing Collator.setStrength() method ...");
col.setStrength(Collator.SECONDARY);
doAssert(col.getStrength() != Collator.TERTIARY, "collation object's strength is secondary difference");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
doAssert(col.getStrength() == Collator.SECONDARY, "collation object has the wrong strength");
logln("testing Collator.setDecomposition() method ...");
col.setDecomposition(Collator.NO_DECOMPOSITION);
doAssert(col.getDecomposition() != Collator.FULL_DECOMPOSITION, "collation object's strength is secondary difference");
doAssert(col.getDecomposition() != Collator.CANONICAL_DECOMPOSITION, "collation object's strength is primary difference");
doAssert(col.getDecomposition() == Collator.NO_DECOMPOSITION, "collation object has the wrong strength");
} catch (Exception foo) {
errln("Error : " + foo.getMessage());
errln("Default Collator creation failed.");
}
logln("Default collation property test ended.");
logln("Collator.getRules() testing ...");
doAssert(((RuleBasedCollator)col).getRules().length() != 0, "getRules() result incorrect" );
logln("getRules tests end.");
try {
col = Collator.getInstance(Locale.FRENCH);
col.setStrength(Collator.PRIMARY);
logln("testing Collator.getStrength() method again ...");
doAssert(col.getStrength() != Collator.TERTIARY, "collation object has the wrong strength");
doAssert(col.getStrength() == Collator.PRIMARY, "collation object's strength is not primary difference");
logln("testing French Collator.setStrength() method ...");
col.setStrength(Collator.TERTIARY);
doAssert(col.getStrength() == Collator.TERTIARY, "collation object's strength is not tertiary difference");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
doAssert(col.getStrength() != Collator.SECONDARY, "collation object's strength is secondary difference");
} catch (Exception bar) {
errln("Error : " + bar.getMessage());
errln("Creating French collation failed.");
}
logln("Create junk collation: ");
Locale abcd = new Locale("ab", "CD", "");
Collator junk = null;
try {
junk = Collator.getInstance(abcd);
} catch (Exception err) {
errln("Error : " + err.getMessage());
errln("Junk collation creation failed, should at least return the collator for the base bundle.");
}
try {
col = Collator.getInstance(Locale.ROOT);
doAssert(col.equals(junk), "The base bundle's collation should be returned.");
} catch (Exception exc) {
errln("Error : " + exc.getMessage());
errln("Default collation comparison, caching not working.");
}
logln("Collator property test ended.");
}
public final void TestProperty( )
{
Collator col = null;
try {
col = Collator.getInstance(Locale.ROOT);
logln("The property tests begin : ");
logln("Test ctors : ");
doAssert(col.compare("ab", "abc") < 0, "ab < abc comparison failed");
doAssert(col.compare("ab", "AB") < 0, "ab < AB comparison failed");
doAssert(col.compare("black-bird", "blackbird") > 0, "black-bird > blackbird comparison failed");
doAssert(col.compare("black bird", "black-bird") < 0, "black bird < black-bird comparison failed");
doAssert(col.compare("Hello", "hello") > 0, "Hello > hello comparison failed");
logln("Test ctors ends.");
logln("testing Collator.getStrength() method ...");
doAssert(col.getStrength() == Collator.TERTIARY, "collation object has the wrong strength");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
logln("testing Collator.setStrength() method ...");
col.setStrength(Collator.SECONDARY);
doAssert(col.getStrength() != Collator.TERTIARY, "collation object's strength is secondary difference");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
doAssert(col.getStrength() == Collator.SECONDARY, "collation object has the wrong strength");
logln("testing Collator.setDecomposition() method ...");
col.setDecomposition(Collator.NO_DECOMPOSITION);
doAssert(col.getDecomposition() != Collator.FULL_DECOMPOSITION, "collation object's strength is secondary difference");
doAssert(col.getDecomposition() != Collator.CANONICAL_DECOMPOSITION, "collation object's strength is primary difference");
doAssert(col.getDecomposition() == Collator.NO_DECOMPOSITION, "collation object has the wrong strength");
} catch (Exception foo) {
errln("Error : " + foo.getMessage());
errln("Default Collator creation failed.");
}
logln("Default collation property test ended.");
logln("Collator.getRules() testing ...");
doAssert(((RuleBasedCollator)col).getRules().length() != 0, "getRules() result incorrect" );
logln("getRules tests end.");
try {
col = Collator.getInstance(Locale.FRENCH);
col.setStrength(Collator.PRIMARY);
logln("testing Collator.getStrength() method again ...");
doAssert(col.getStrength() != Collator.TERTIARY, "collation object has the wrong strength");
doAssert(col.getStrength() == Collator.PRIMARY, "collation object's strength is not primary difference");
logln("testing French Collator.setStrength() method ...");
col.setStrength(Collator.TERTIARY);
doAssert(col.getStrength() == Collator.TERTIARY, "collation object's strength is not tertiary difference");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
doAssert(col.getStrength() != Collator.SECONDARY, "collation object's strength is secondary difference");
} catch (Exception bar) {
errln("Error : " + bar.getMessage());
errln("Creating French collation failed.");
}
logln("Create junk collation: ");
Locale abcd = new Locale("ab", "CD", "");
Collator junk = null;
try {
junk = Collator.getInstance(abcd);
} catch (Exception err) {
errln("Error : " + err.getMessage());
errln("Junk collation creation failed, should at least return the collator for the base bundle.");
}
try {
col = Collator.getInstance(Locale.ROOT);
doAssert(col.equals(junk), "The base bundle's collation should be returned.");
} catch (Exception exc) {
errln("Error : " + exc.getMessage());
errln("Default collation comparison, caching not working.");
}
logln("Collator property test ended.");
}
/**
* Setup the field according to the provided parameters
*/
private void setup(ResourceLoader loader, Map<String,String> args) {
String custom = args.remove("custom");
String language = args.remove("language");
String country = args.remove("country");
String variant = args.remove("variant");
String strength = args.remove("strength");
String decomposition = args.remove("decomposition");
final Collator collator;
if (custom == null && language == null)
throw new SolrException(ErrorCode.SERVER_ERROR, "Either custom or language is required.");
if (custom != null &&
(language != null || country != null || variant != null))
throw new SolrException(ErrorCode.SERVER_ERROR, "Cannot specify both language and custom. "
+ "To tailor rules for a built-in language, see the javadocs for RuleBasedCollator. "
+ "Then save the entire customized ruleset to a file, and use with the custom parameter");
if (language != null) {
// create from a system collator, based on Locale.
collator = createFromLocale(language, country, variant);
} else {
// create from a custom ruleset
collator = createFromRules(custom, loader);
}
// set the strength flag, otherwise it will be the default.
if (strength != null) {
if (strength.equalsIgnoreCase("primary"))
collator.setStrength(Collator.PRIMARY);
else if (strength.equalsIgnoreCase("secondary"))
collator.setStrength(Collator.SECONDARY);
else if (strength.equalsIgnoreCase("tertiary"))
collator.setStrength(Collator.TERTIARY);
else if (strength.equalsIgnoreCase("identical"))
collator.setStrength(Collator.IDENTICAL);
else
throw new SolrException(ErrorCode.SERVER_ERROR, "Invalid strength: " + strength);
}
// set the decomposition flag, otherwise it will be the default.
if (decomposition != null) {
if (decomposition.equalsIgnoreCase("no"))
collator.setDecomposition(Collator.NO_DECOMPOSITION);
else if (decomposition.equalsIgnoreCase("canonical"))
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
else if (decomposition.equalsIgnoreCase("full"))
collator.setDecomposition(Collator.FULL_DECOMPOSITION);
else
throw new SolrException(ErrorCode.SERVER_ERROR, "Invalid decomposition: " + decomposition);
}
analyzer = new CollationKeyAnalyzer(collator);
}
public final void TestProperty( )
{
Collator col = null;
try {
col = Collator.getInstance(Locale.ROOT);
logln("The property tests begin : ");
logln("Test ctors : ");
doAssert(col.compare("ab", "abc") < 0, "ab < abc comparison failed");
doAssert(col.compare("ab", "AB") < 0, "ab < AB comparison failed");
doAssert(col.compare("black-bird", "blackbird") > 0, "black-bird > blackbird comparison failed");
doAssert(col.compare("black bird", "black-bird") < 0, "black bird < black-bird comparison failed");
doAssert(col.compare("Hello", "hello") > 0, "Hello > hello comparison failed");
logln("Test ctors ends.");
logln("testing Collator.getStrength() method ...");
doAssert(col.getStrength() == Collator.TERTIARY, "collation object has the wrong strength");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
logln("testing Collator.setStrength() method ...");
col.setStrength(Collator.SECONDARY);
doAssert(col.getStrength() != Collator.TERTIARY, "collation object's strength is secondary difference");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
doAssert(col.getStrength() == Collator.SECONDARY, "collation object has the wrong strength");
logln("testing Collator.setDecomposition() method ...");
col.setDecomposition(Collator.NO_DECOMPOSITION);
doAssert(col.getDecomposition() != Collator.FULL_DECOMPOSITION, "collation object's strength is secondary difference");
doAssert(col.getDecomposition() != Collator.CANONICAL_DECOMPOSITION, "collation object's strength is primary difference");
doAssert(col.getDecomposition() == Collator.NO_DECOMPOSITION, "collation object has the wrong strength");
} catch (Exception foo) {
errln("Error : " + foo.getMessage());
errln("Default Collator creation failed.");
}
logln("Default collation property test ended.");
logln("Collator.getRules() testing ...");
doAssert(((RuleBasedCollator)col).getRules().length() != 0, "getRules() result incorrect" );
logln("getRules tests end.");
try {
col = Collator.getInstance(Locale.FRENCH);
col.setStrength(Collator.PRIMARY);
logln("testing Collator.getStrength() method again ...");
doAssert(col.getStrength() != Collator.TERTIARY, "collation object has the wrong strength");
doAssert(col.getStrength() == Collator.PRIMARY, "collation object's strength is not primary difference");
logln("testing French Collator.setStrength() method ...");
col.setStrength(Collator.TERTIARY);
doAssert(col.getStrength() == Collator.TERTIARY, "collation object's strength is not tertiary difference");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
doAssert(col.getStrength() != Collator.SECONDARY, "collation object's strength is secondary difference");
} catch (Exception bar) {
errln("Error : " + bar.getMessage());
errln("Creating French collation failed.");
}
logln("Create junk collation: ");
Locale abcd = new Locale("ab", "CD", "");
Collator junk = null;
try {
junk = Collator.getInstance(abcd);
} catch (Exception err) {
errln("Error : " + err.getMessage());
errln("Junk collation creation failed, should at least return the collator for the base bundle.");
}
try {
col = Collator.getInstance(Locale.ROOT);
doAssert(col.equals(junk), "The base bundle's collation should be returned.");
} catch (Exception exc) {
errln("Error : " + exc.getMessage());
errln("Default collation comparison, caching not working.");
}
logln("Collator property test ended.");
}