/** * Constructs a new {@code Collator} instance. */ protected Collator() { icuColl = new RuleBasedCollatorICU(Locale.getDefault()); }
public CollationElementIteratorICU getCollationElementIterator(CharacterIterator it) { // We only implement the String-based API, so build a string from the iterator. return getCollationElementIterator(characterIteratorToString(it)); }
/** * Returns a new collator with the same decomposition mode and * strength value as this collator. * * @return a shallow copy of this collator. * @see java.lang.Cloneable */ @Override public Object clone() { try { Collator clone = (Collator) super.clone(); clone.icuColl = (RuleBasedCollatorICU) icuColl.clone(); return clone; } catch (CloneNotSupportedException e) { throw new AssertionError(e); } }
@Override public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof RuleBasedCollatorICU)) { return false; } RuleBasedCollatorICU rhs = (RuleBasedCollatorICU) object; return getRules().equals(rhs.getRules()) && getStrength() == rhs.getStrength() && getDecomposition() == rhs.getDecomposition(); }
public boolean equals(String source, String target) { return (compare(source, target) == 0); }
/** * Obtains a {@code CollationElementIterator} for the given string. * * @param source * the source string. * @return the {@code CollationElementIterator} for {@code source}. */ public CollationElementIterator getCollationElementIterator(String source) { if (source == null) { throw new NullPointerException("source == null"); } return new CollationElementIterator(icuColl.getCollationElementIterator(source)); }
/** * Returns the collation rules of this collator. These {@code rules} can be * fed into the {@code RuleBasedCollator(String)} constructor. * <p> * Note that the {@code rules} are actually interpreted as a delta to the * standard Unicode Collation Algorithm (UCA). Hence, an empty {@code rules} * string results in the default UCA rules being applied. This differs * slightly from other implementations which work with full {@code rules} * specifications and may result in different behavior. * * @return the collation rules. */ public String getRules() { return icuColl.getRules(); }
/** * Returns the decomposition rule for this collator. * * @return the decomposition rule, either {@code NO_DECOMPOSITION} or * {@code CANONICAL_DECOMPOSITION}. {@code FULL_DECOMPOSITION} is * not supported. */ public int getDecomposition() { return decompositionMode_ICU_Java(icuColl.getDecomposition()); }
/** * Returns the strength value for this collator. * * @return the strength value, either PRIMARY, SECONDARY, TERTIARY or * IDENTICAL. */ public int getStrength() { return strength_ICU_Java(icuColl.getStrength()); }
/** * Returns the {@code CollationKey} for the given source text. * * @param source * the specified source text. * @return the {@code CollationKey} for the given source text. */ @Override public CollationKey getCollationKey(String source) { return icuColl.getCollationKey(source); }
/** * Compares this collator with the specified object and indicates if they * are equal. * * @param object * the object to compare with this object. * @return {@code true} if {@code object} is a {@code Collator} object and * it has the same strength and decomposition values as this * collator; {@code false} otherwise. * @see #hashCode */ @Override public boolean equals(Object object) { if (!(object instanceof Collator)) { return false; } Collator collator = (Collator) object; return icuColl == null ? collator.icuColl == null : icuColl.equals(collator.icuColl); }
@Override public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof RuleBasedCollatorICU)) { return false; } RuleBasedCollatorICU rhs = (RuleBasedCollatorICU) object; return getRules().equals(rhs.getRules()) && getStrength() == rhs.getStrength() && getDecomposition() == rhs.getDecomposition(); }
/** * Compares the {@code source} text to the {@code target} text according to * the collation rules, strength and decomposition mode for this * {@code RuleBasedCollator}. See the {@code Collator} class description * for an example of use. * <p> * General recommendation: If comparisons are to be done with the same strings * multiple times, it is more efficient to generate {@code CollationKey} * objects for the strings and use * {@code CollationKey.compareTo(CollationKey)} for the comparisons. If each * string is compared to only once, using * {@code RuleBasedCollator.compare(String, String)} has better performance. * * @param source * the source text. * @param target * the target text. * @return an integer which may be a negative value, zero, or else a * positive value depending on whether {@code source} is less than, * equivalent to, or greater than {@code target}. */ @Override public int compare(String source, String target) { if (source == null) { throw new NullPointerException("source == null"); } else if (target == null) { throw new NullPointerException("target == null"); } return icuColl.compare(source, target); }
/** * Obtains a {@code CollationElementIterator} for the given * {@code CharacterIterator}. The source iterator's integrity will be * preserved since a new copy will be created for use. * * @param source * the source character iterator. * @return a {@code CollationElementIterator} for {@code source}. */ public CollationElementIterator getCollationElementIterator(CharacterIterator source) { if (source == null) { throw new NullPointerException("source == null"); } return new CollationElementIterator(icuColl.getCollationElementIterator(source)); }
@Override public int hashCode() { return icuColl.getRules().hashCode(); }
/** * Returns the decomposition rule for this collator. * * @return the decomposition rule, either {@code NO_DECOMPOSITION} or * {@code CANONICAL_DECOMPOSITION}. {@code FULL_DECOMPOSITION} is * not supported. */ public int getDecomposition() { return decompositionMode_ICU_Java(icuColl.getDecomposition()); }
/** * Returns the strength value for this collator. * * @return the strength value, either PRIMARY, SECONDARY, TERTIARY or * IDENTICAL. */ public int getStrength() { return strength_ICU_Java(icuColl.getStrength()); }
/** * Returns the {@code CollationKey} for the given source text. * * @param source * the specified source text. * @return the {@code CollationKey} for the given source text. */ @Override public CollationKey getCollationKey(String source) { return icuColl.getCollationKey(source); }
/** * Compares this collator with the specified object and indicates if they * are equal. * * @param object * the object to compare with this object. * @return {@code true} if {@code object} is a {@code Collator} object and * it has the same strength and decomposition values as this * collator; {@code false} otherwise. * @see #hashCode */ @Override public boolean equals(Object object) { if (!(object instanceof Collator)) { return false; } Collator collator = (Collator) object; return icuColl == null ? collator.icuColl == null : icuColl.equals(collator.icuColl); }
@Override public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof RuleBasedCollatorICU)) { return false; } RuleBasedCollatorICU rhs = (RuleBasedCollatorICU) object; return getRules().equals(rhs.getRules()) && getStrength() == rhs.getStrength() && getDecomposition() == rhs.getDecomposition(); }