Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbvosburgh2011-03-02 18:38:04 -0500
committerbvosburgh2011-03-02 18:38:04 -0500
commitc33940b79c906fdb2f20a4ffa99e15f96039d719 (patch)
tree9a0901ed883578c08f088a78ed1218fc474919e8 /common/plugins
parentde24ef1f7fb732f140326d9cb6cedb427d5877b6 (diff)
downloadwebtools.dali-c33940b79c906fdb2f20a4ffa99e15f96039d719.tar.gz
webtools.dali-c33940b79c906fdb2f20a4ffa99e15f96039d719.tar.xz
webtools.dali-c33940b79c906fdb2f20a4ffa99e15f96039d719.zip
add ICUStringCollator
Diffstat (limited to 'common/plugins')
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/ICUStringCollator.java63
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringCollator.java42
2 files changed, 86 insertions, 19 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/ICUStringCollator.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/ICUStringCollator.java
new file mode 100644
index 0000000000..555fa43caf
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/ICUStringCollator.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.internal.utility;
+
+import java.util.Comparator;
+import java.util.Locale;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import com.ibm.icu.text.Collator;
+
+/**
+ * This collator simply wraps an ICU4J collator and implements a
+ * {@link String} {@link Comparator} (instead of an {@link Object}
+ * {@link Comparator}, which is what {@link Collator} does, mimicking the
+ * JDK(?)).
+ *
+ * @see Collator
+ */
+public class ICUStringCollator
+ implements Comparator<String>
+{
+ private final Collator collator;
+
+
+ /**
+ * Wrap the default collator.
+ * @see Collator#getInstance()
+ */
+ public ICUStringCollator() {
+ this(Collator.getInstance());
+ }
+
+ /**
+ * Wrap the collator for the specified locale.
+ * @see Collator#getInstance(Locale)
+ */
+ public ICUStringCollator(Locale locale) {
+ this(Collator.getInstance(locale));
+ }
+
+ /**
+ * Wrap the specified collator.
+ */
+ public ICUStringCollator(Collator collator) {
+ super();
+ this.collator = collator;
+ }
+
+ public int compare(String string1, String string2) {
+ return this.collator.compare(string1, string2);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.collator);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringCollator.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringCollator.java
index 2949b78748..eefb0b0a33 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringCollator.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringCollator.java
@@ -9,50 +9,54 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.internal;
-import java.io.Serializable;
import java.text.Collator;
import java.util.Comparator;
+import java.util.Locale;
/**
- * This collator simply wraps the default Java collator and implements a
+ * This collator simply wraps a Java text collator and implements a
* {@link String} {@link Comparator} (instead of an {@link Object}
* {@link Comparator}, which is what {@link Collator} does, possibly for
* backward-compatibility reasons(?)).
*
- * @see Collator#getInstance()
+ * @see Collator
*/
public class StringCollator
- implements Comparator<String>, Serializable
+ implements Comparator<String>
{
- // singleton
- private static final StringCollator INSTANCE = new StringCollator();
+ private final Collator collator;
+
/**
- * Return the singleton.
+ * Wrap the default collator.
+ * @see Collator#getInstance()
*/
- public static Comparator<String> instance() {
- return INSTANCE;
+ public StringCollator() {
+ this(Collator.getInstance());
}
/**
- * Ensure single instance.
+ * Wrap the collator for the specified locale.
+ * @see Collator#getInstance(Locale)
*/
- private StringCollator() {
+ public StringCollator(Locale locale) {
+ this(Collator.getInstance(locale));
+ }
+
+ /**
+ * Wrap the specified collator.
+ */
+ public StringCollator(Collator collator) {
super();
+ this.collator = collator;
}
public int compare(String string1, String string2) {
- return Collator.getInstance().compare(string1, string2);
+ return this.collator.compare(string1, string2);
}
@Override
public String toString() {
- return this.getClass().getSimpleName();
- }
-
- private static final long serialVersionUID = 1L;
- private Object readResolve() {
- // replace this object with the singleton
- return INSTANCE;
+ return StringTools.buildToStringFor(this, this.collator);
}
}

Back to the top