diff options
author | bvosburgh | 2011-02-22 17:59:44 +0000 |
---|---|---|
committer | bvosburgh | 2011-02-22 17:59:44 +0000 |
commit | 08e26173336c0fab5a65ddb19ccd194a4e673640 (patch) | |
tree | 6b54c962be78cb662910164379cd4a3b46b2b070 | |
parent | 4474ea01ede95c0535192b30de682db077186635 (diff) | |
download | webtools.dali-08e26173336c0fab5a65ddb19ccd194a4e673640.tar.gz webtools.dali-08e26173336c0fab5a65ddb19ccd194a4e673640.tar.xz webtools.dali-08e26173336c0fab5a65ddb19ccd194a4e673640.zip |
add StringCollator
-rw-r--r-- | common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringCollator.java | 58 |
1 files changed, 58 insertions, 0 deletions
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 new file mode 100644 index 0000000000..2949b78748 --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringCollator.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * 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.utility.internal; + +import java.io.Serializable; +import java.text.Collator; +import java.util.Comparator; + +/** + * This collator simply wraps the default Java 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() + */ +public class StringCollator + implements Comparator<String>, Serializable +{ + // singleton + private static final StringCollator INSTANCE = new StringCollator(); + + /** + * Return the singleton. + */ + public static Comparator<String> instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private StringCollator() { + super(); + } + + public int compare(String string1, String string2) { + return Collator.getInstance().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; + } +} |