summaryrefslogtreecommitdiffstats
path: root/icu/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'icu/src/main/java')
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/Collator.java80
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java17
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java83
3 files changed, 8 insertions, 172 deletions
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/Collator.java b/icu/src/main/java/com/ibm/icu4jni/text/Collator.java
index 7883d30..9eb85ea 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/Collator.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/Collator.java
@@ -13,64 +13,6 @@ package com.ibm.icu4jni.text;
import com.ibm.icu4jni.text.RuleBasedCollator;
import java.util.Locale;
-/**
-* Abstract class handling locale specific collation via JNI and ICU.
-* Subclasses implement specific collation strategies. One subclass,
-* com.ibm.icu4jni.text.RuleBasedCollator, is currently provided and is
-* applicable to a wide set of languages. Other subclasses may be created to
-* handle more specialized needs.
-* You can use the static factory method, getInstance(), to obtain the
-* appropriate Collator object for a given locale.
-*
-* <pre>
-* // Compare two strings in the default locale
-* Collator myCollator = Collator.getInstance();
-* if (myCollator.compare("abc", "ABC") < 0) {
-* System.out.println("abc is less than ABC");
-* }
-* else {
-* System.out.println("abc is greater than or equal to ABC");
-* }
-* </pre>
-*
-* You can set a Collator's strength property to determine the level of
-* difference considered significant in comparisons.
-* Five strengths in CollationAttribute are provided: VALUE_PRIMARY,
-* VALUE_SECONDARY, VALUE_TERTIARY, VALUE_QUATERNARY and VALUE_IDENTICAL.
-* The exact assignment of strengths to language features is locale-dependent.
-* For example, in Czech, "e" and "f" are considered primary differences, while
-* "e" and "?" latin small letter e with circumflex are secondary differences,
-* "e" and "E" are tertiary differences and "e" and "e" are identical.
-*
-* <p>
-* The following shows how both case and accents could be ignored for US
-* English.
-* <pre>
-* //Get the Collator for US English and set its strength to PRIMARY
-* Collator usCollator = Collator.getInstance(Locale.US);
-* usCollator.setStrength(Collator.PRIMARY);
-* if (usCollator.compare("abc", "ABC") == 0) {
-* System.out.println("Strings are equivalent");
-* }
-* </pre>
-* For comparing Strings exactly once, the compare method provides the best
-* performance.
-* When sorting a list of Strings however, it is generally necessary to compare
-* each String multiple times.
-* In this case, com.ibm.icu4jni.text.CollationKey provide better performance.
-* The CollationKey class converts a String to a series of bits that can be
-* compared bitwise against other CollationKeys.
-* A CollationKey is created by a Collator object for a given String.
-* Note: CollationKeys from different Collators can not be compared.
-* </p>
-*
-* Considerations :
-* 1) ErrorCode not returned to user throw exceptions instead
-* 2) Similar API to java.text.Collator
-* @author syn wee quek
-* @stable ICU 2.4
-*/
-
public abstract class Collator implements Cloneable {
/**
* Strongest collator strength value. Typically used to denote differences
@@ -164,28 +106,8 @@ public abstract class Collator implements Cloneable {
*/
public final static int CANONICAL_DECOMPOSITION = CollationAttribute.VALUE_ON;
- public static Collator getInstance() {
- return getInstance(null);
- }
-
- /**
- * Factory method to create an appropriate Collator which uses the given
- * locale's collation rules.<br>
- * Current implementation createInstance() returns a RuleBasedCollator(Locale)
- * instance. The RuleBasedCollator will be created in the following order,
- * <ul>
- * <li> Data from argument locale resource bundle if found, otherwise
- * <li> Data from parent locale resource bundle of given locale if found, otherwise
- * <li> Data from built-in default collation rules if found, other
- * <li> null is returned
- * </ul>
- * @param locale to be used for collation
- * @return an instance of Collator
- * @stable ICU 2.4
- */
public static Collator getInstance(Locale locale) {
- RuleBasedCollator result = new RuleBasedCollator(locale);
- return result;
+ return new RuleBasedCollator(locale);
}
public boolean equals(String source, String target) {
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java b/icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java
index fbdcf93..d481790 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java
@@ -23,14 +23,7 @@ final class NativeCollation
public NativeCollation() {
}
-
- /**
- * Method to create a new C Collator using the default locale rules.
- * @return new c collator
- * @internal ICU 2.4
- */
- static native int openCollator();
-
+
/**
* Method to create a new C Collator using the argument locale rules.
* @param locale locale name
@@ -160,14 +153,6 @@ final class NativeCollation
*/
static native int getCollationElementIterator(int collatoraddress,
String source);
-
- /**
- * Returns a hash of this collation object
- * @param collatoraddress address of C collator
- * @return hash of this collation object
- * @internal ICU 2.4
- */
- static native int hashCode(int collatoraddress);
// collationelementiterator methods -------------------------------------
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java b/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java
index 3135daa..8e048dd 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java
@@ -454,20 +454,6 @@ public final class RuleBasedCollator extends Collator {
return NativeCollation.getAttribute(m_collator_, type);
}
- /**
- * Get the sort key as an CollationKey object from the argument string.
- * To retrieve sort key in terms of byte arrays, use the method as below<br>
- * <br>
- * <code>
- * Collator collator = Collator.getInstance();
- * byte[] array = collator.getSortKey(source);
- * </code><br>
- * Byte array result are zero-terminated and can be compared using
- * java.util.Arrays.equals();
- * @param source string to be processed.
- * @return the sort key
- * @stable ICU 2.4
- */
public CollationKey getCollationKey(String source) {
if (source == null) {
return null;
@@ -480,17 +466,6 @@ public final class RuleBasedCollator extends Collator {
}
/**
- * Get a sort key for the argument string
- * Sort keys may be compared using java.util.Arrays.equals
- * @param source string for key to be generated
- * @return sort key
- * @stable ICU 2.4
- */
- public byte[] getSortKey(String source) {
- return NativeCollation.getSortKey(m_collator_, source);
- }
-
- /**
* Get the collation rules of this Collation object
* The rules will follow the rule syntax.
* @return collation rules.
@@ -529,21 +504,9 @@ public final class RuleBasedCollator extends Collator {
return result.toString();
}
- /**
- * Returns a hash of this collation object
- * Note this method is not complete, it only returns 0 at the moment.
- * @return hash of this collation object
- * @stable ICU 2.4
- */
+ @Override
public int hashCode() {
- // since rules do not change once it is created, we can cache the hash
- if (m_hashcode_ == 0) {
- m_hashcode_ = NativeCollation.hashCode(m_collator_);
- if (m_hashcode_ == 0) {
- m_hashcode_ = 1;
- }
- }
- return m_hashcode_;
+ return 42; // No-one uses RuleBasedCollator as a hash key.
}
/**
@@ -565,50 +528,16 @@ public final class RuleBasedCollator extends Collator {
getDecomposition() == rhs.getDecomposition();
}
- /**
- * RuleBasedCollator default constructor. This constructor takes the default
- * locale. The only caller of this class should be Collator.getInstance().
- * Current implementation createInstance() returns a RuleBasedCollator(Locale)
- * instance. The RuleBasedCollator will be created in the following order,
- * <ul>
- * <li> Data from argument locale resource bundle if found, otherwise
- * <li> Data from parent locale resource bundle of arguemtn locale if found,
- * otherwise
- * <li> Data from built-in default collation rules if found, other
- * <li> null is returned
- * </ul>
- */
- RuleBasedCollator() {
- m_collator_ = NativeCollation.openCollator();
- }
-
- /**
- * RuleBasedCollator constructor. This constructor takes a locale. The
- * only caller of this class should be Collator.createInstance().
- * Current implementation createInstance() returns a RuleBasedCollator(Locale)
- * instance. The RuleBasedCollator will be created in the following order,
- * <ul>
- * <li> Data from argument locale resource bundle if found, otherwise
- * <li> Data from parent locale resource bundle of arguemtn locale if found,
- * otherwise
- * <li> Data from built-in default collation rules if found, other
- * <li> null is returned
- * </ul>
- * @param locale locale used
- */
RuleBasedCollator(Locale locale) {
- if (locale == null) {
- m_collator_ = NativeCollation.openCollator();
- } else {
- m_collator_ = NativeCollation.openCollator(locale.toString());
- }
+ m_collator_ = NativeCollation.openCollator(locale.toString());
}
+ @Override
protected void finalize() {
NativeCollation.closeCollator(m_collator_);
}
- private RuleBasedCollator(int collatoraddress) {
- m_collator_ = collatoraddress;
+ private RuleBasedCollator(int addr) {
+ m_collator_ = addr;
}
}