From 539418d42a4b63ab64a51ab11e808de7edbd4589 Mon Sep 17 00:00:00 2001 From: tromey Date: Wed, 5 Sep 2001 00:00:55 +0000 Subject: * java/text/SimpleDateFormat.java: Re-merged with Classpath. * gnu/gcj/text/LocaleData.java, gnu/gcj/text/LocaleData_en.java, gnu/gcj/text/LocaleData_en_US.java: Removed. * java/text/DateFormatSymbols.java (clone): Use Classpath implementation. (equals): Simplified. (DateFormatSymbols): Look in gnu.java.locale for information. (DateFormatSymbols(DateFormatSymbols)): Removed. (safeGetResource): Removed. (DateFormatSymbols): Throws MissingResourceException. (ampmsDefault, erasDefault, localPatternCharsDefault, monthsDefault, shortMonthsDefault, shortWeekdaysDefault, weekdaysDefault, zoneStringsDefault): Removed. * java/text/Collator.java (getAvailableLocales): Use modified Classpath implementation. (getInstance): Look in gnu.java.locale for information. (clone): Rewrote. * java/text/MessageFormat.java: Reindented. (clone): Rewrote. * java/text/FieldPosition.java: Merged with Classpath. * java/text/ParsePosition.java: Merged with Classpath. * java/text/Format.java: Merged with Classpath. * java/text/StringCharacterIterator.java (StringCharacterIterator(StringCharacterIterator,int,int)): New constructor from Classpath. * java/text/Annotation.java, java/text/AttributedCharacterIterator.java, java/text/AttributedString.java, java/text/AttributedStringIterator.java: New from Classpath. * java/text/CharacterIterator.java: Copied from Classpath. * java/text/ChoiceFormat.java: Reindented. (clone): Removed. * gnu/java/text/BaseBreakIterator.java, gnu/java/text/CharacterBreakIterator.java, gnu/java/text/LineBreakIterator.java, gnu/java/text/LocaleData_en.java, gnu/java/text/LocaleData_en_US.java, gnu/java/text/SentenceBreakIterator.java, gnu/java/text/WordBreakIterator.java: Renamed from gnu/gcj/text/*. * gnu/gcj/text/BaseBreakIterator.java (last): Advance past final character. * java/text/BreakIterator.java (getAvailableLocales): Use Classpath implementation. (getInstance): Look in gnu.java.locale for information. (getCharacterInstance, getLineInstance, getSentenceInstance, getWordInstance): Look in gnu.java.text for implementations. * java/text/DecimalFormatSymbols.java: Reindented (clone): Use Classpath implementation. (DecimalFormatSymbols(DecimalFormatSymbols)): Removed. (DecimalFormatSymbols(Locale)): Look in gnu.java.locale for information. * java/text/DateFormat.java: Merged with Classpath. (getAvailableLocales): Use Classpath implementation. (format(Object,StringBuffer,FieldPosition)): Minor cleanup. (computeInstance): Look in gnu.java.locale for information. * java/text/NumberFormat.java: Reindented. (computeInstance): Look in gnu.java.locale for information. (getAvailableLocales): Use implementation from Classpath. (setMaximumIntegerDigits): Likewise. (setMinimumIntegerDigits): Likewise. (setMaximumFractionDigits): Likewise. (clone): Removed. * java/text/DecimalFormat.java: Reindented. * gnu/java/locale/LocaleInformation_en.java: Copied from Classpath. * gnu/java/locale/LocaleInformation_en_US.java: Copied from Classpath. * Makefile.in: Rebuilt. * Makefile.am (ordinary_java_source_files): Added all new files. (ordinary_java_source_files): Renamed or removed gnu/gcj/text/*. * java/security/spec/AlgorithmParameterSpec.java, java/security/spec/KeySpec.java: Re-merged with Classpath. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@45390 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/java/text/Collator.java | 277 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 260 insertions(+), 17 deletions(-) (limited to 'libjava/java/text/Collator.java') diff --git a/libjava/java/text/Collator.java b/libjava/java/text/Collator.java index 9a356c16541..51a053dcf18 100644 --- a/libjava/java/text/Collator.java +++ b/libjava/java/text/Collator.java @@ -1,12 +1,29 @@ -// Collator.java - Locale-sensitive string comparison. +/* Collator.java -- Perform locale dependent String comparisons. + Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. -/* Copyright (C) 1999, 2000 Free Software Foundation +This file is part of GNU Classpath. - This file is part of libgcj. +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +As a special exception, if you link this library with other files to +produce an executable, this library does not by itself cause the +resulting executable to be covered by the GNU General Public License. +This exception does not however invalidate any other reasons why the +executable file might be covered by the GNU General Public License. */ -This software is copyrighted work licensed under the terms of the -Libgcj License. Please consult the file "LIBGCJ_LICENSE" for -details. */ package java.text; @@ -16,38 +33,157 @@ import java.util.ResourceBundle; import java.util.Comparator; /** + * This class is the abstract superclass of classes which perform + * locale dependent String comparisons. A caller requests + * an instance of Collator for a particular locale using + * the getInstance() static method in this class. That method + * will return a locale specific subclass of Collator which + * can be used to perform String comparisons for that locale. + * If a subclass of Collator cannot be located for a particular + * locale, a default instance for the current locale will be returned. + * + * In addition to setting the correct locale, there are two additional + * settings that can be adjusted to affect String comparisons: + * strength and decomposition. The strength value determines the level + * of signficance of character differences required for them to sort + * differently. (For example, whether or not capital letters are considered + * different from lower case letters). The decomposition value affects how + * variants of the same character are treated for sorting purposes. (For + * example, whether or not an accent is signficant or not). These settings + * are described in detail in the documentation for the methods and values + * that are related to them. + * * @author Tom Tromey + * @author Aaron M. Renn (arenn@urbanophile.com) * @date March 18, 1999 */ /* Written using "Java Class Libraries", 2nd edition, plus online * API docs for JDK 1.2 from http://www.javasoft.com. * Status: Mostly complete, but parts stubbed out. Look for FIXME. */ - public abstract class Collator implements Comparator, Cloneable { - public static final int NO_DECOMPOSITION = 0; - public static final int CANONICAL_DECOMPOSITION = 1; - public static final int FULL_DECOMPOSITION = 2; - + /** + * This constant is a strength value which indicates that only primary + * differences between characters will be considered signficant. As an + * example, two completely different English letters such as 'a' and 'b' + * are considered to have a primary difference. + */ public static final int PRIMARY = 0; + + /** + * This constant is a strength value which indicates that only secondary + * or primary differences between characters will be considered + * significant. An example of a secondary difference between characters + * are instances of the same letter with different accented forms. + */ public static final int SECONDARY = 1; + + /** + * This constant is a strength value which indicates that tertiary, + * secondary, and primary differences will be considered during sorting. + * An example of a tertiary difference is capitalization of a given letter. + * This is the default value for the strength setting. + */ public static final int TERTIARY = 2; + + /** + * This constant is a strength value which indicates that any difference + * at all between character values are considered significant. + */ public static final int IDENTICAL = 3; + + /** + * This constant indicates that accented characters won't be decomposed + * when performing comparisons. This will yield the fastest results, but + * will only work correctly in call cases for languages which do not + * use accents such as English. + */ + public static final int NO_DECOMPOSITION = 0; + + /** + * This constant indicates that only characters which are canonical variants + * in Unicode 2.0 will be decomposed prior to performing comparisons. This + * will cause accented languages to be sorted correctly. This is the + * default decomposition value. + */ + public static final int CANONICAL_DECOMPOSITION = 1; + + /** + * This constant indicates that both canonical variants and compatibility + * variants in Unicode 2.0 will be decomposed prior to performing + * comparisons. This is the slowest mode, but is required to get the + * correct sorting for certain languages with certain special formats. + */ + public static final int FULL_DECOMPOSITION = 2; + /** + * This method initializes a new instance of Collator to have + * the default strength (TERTIARY) and decomposition + * (CANONICAL_DECOMPOSITION) settings. This constructor is protected and + * is for use by subclasses only. Non-subclass callers should use the + * static getInstance() methods of this class to instantiate + * Collation objects for the desired locale. + */ protected Collator () { strength = TERTIARY; decmp = CANONICAL_DECOMPOSITION; } + /** + * This method compares the two String's and returns an + * integer indicating whether or not the first argument is less than, + * equal to, or greater than the second argument. The comparison is + * performed according to the rules of the locale for this + * Collator and the strength and decomposition rules in + * effect. + * + * @param str1 The first object to compare + * @param str2 The second object to compare + * + * @return A negative integer if str1 < str2, 0 if str1 == str2, or + * a positive integer if str1 > str2. + */ public abstract int compare (String source, String target); + /** + * This method compares the two Object's and returns an + * integer indicating whether or not the first argument is less than, + * equal to, or greater than the second argument. These two objects + * must be String's or an exception will be thrown. + * + * @param obj1 The first object to compare + * @param obj2 The second object to compare + * + * @return A negative integer if obj1 < obj2, 0 if obj1 == obj2, or + * a positive integer if obj1 > obj2. + * + * @exception ClassCastException If the arguments are not instances + * of String. + */ public int compare (Object o1, Object o2) { return compare ((String) o1, (String) o2); } + /** + * This method tests the specified object for equality against this + * object. This will be true if and only if the following conditions are + * met: + * + * + * @param obj The Object to test for equality against + * this object. + * + * @return true if the specified object is equal to + * this one, false otherwise. + */ public boolean equals (Object obj) { if (! (obj instanceof Collator)) @@ -56,42 +192,108 @@ public abstract class Collator implements Comparator, Cloneable return decmp == c.decmp && strength == c.strength; } + /** + * This method tests whether the specified String's are equal + * according to the collation rules for the locale of this object and + * the current strength and decomposition settings. + * + * @param str1 The first String to compare + * @param str2 The second String to compare + * + * @return true if the two strings are equal, + * false otherwise. + */ public boolean equals (String source, String target) { return compare (source, target) == 0; } + /** + * This method returns a copy of this Collator object. + * + * @return A duplicate of this object. + */ public Object clone () { - return super.clone (); + try + { + return super.clone (); + } + catch (CloneNotSupportedException _) + { + return null; + } } + /** + * This method returns an array of Locale objects which is + * the list of locales for which Collator objects exist. + * + * @return The list of locales for which Collator's exist. + */ public static synchronized Locale[] getAvailableLocales () { - // FIXME. - return null; + // FIXME + Locale[] l = new Locale[1]; + l[0] = Locale.US; + return l; } + /** + * This method transforms the specified String into a + * CollationKey for faster comparisons. This is useful when + * comparisons against a string might be performed multiple times, such + * as during a sort operation. + * + * @param str The String to convert. + * + * @return A CollationKey for the specified String. + */ public abstract CollationKey getCollationKey (String source); + /** + * This method returns the current decomposition setting for this + * object. This * will be one of NO_DECOMPOSITION, + * CANONICAL_DECOMPOSITION, or * FULL_DECOMPOSITION. See the + * documentation for those constants for an * explanation of this + * setting. + * + * @return The current decomposition setting. + */ public synchronized int getDecomposition () { return decmp; } + /** + * This method returns an instance of Collator for the + * default locale. + * + * @return A Collator for the default locale. + */ public static Collator getInstance () { return getInstance (Locale.getDefault()); } + /** + * This method returns an instance of Collator for the + * specified locale. If no Collator exists for the desired + * locale, a Collator for the default locale will be returned. + * + * @param locale The desired localed to load a Collator for. + * + * @return A Collator for the requested locale + */ public static Collator getInstance (Locale loc) { ResourceBundle res; String pattern; try { - res = ResourceBundle.getBundle("gnu.gcj.text.LocaleData", loc); - pattern = res.getString("collatorRule"); + res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", + loc); + pattern = res.getString("collation_rules"); } catch (MissingResourceException x) { @@ -107,13 +309,37 @@ public abstract class Collator implements Comparator, Cloneable } } + /** + * This method returns the current strength setting for this object. This + * will be one of PRIMARY, SECONDARY, TERTIARY, or IDENTICAL. See the + * documentation for those constants for an explanation of this setting. + * + * @return The current strength setting. + */ public synchronized int getStrength () { return strength; } + /** + * This method returns a hash code value for this object. + * + * @return A hash value for this object. + */ public abstract int hashCode (); + /** + * This method sets the decomposition setting for this object to the + * specified value. This must be one of NO_DECOMPOSITION, + * CANONICAL_DECOMPOSITION, or FULL_DECOMPOSITION. Otherwise an + * exception will be thrown. See the documentation for those + * contants for an explanation of this setting. + * + * @param decmp The new decomposition setting. + * + * @exception IllegalArgumentException If the requested + * decomposition setting is not valid. + */ public synchronized void setDecomposition (int mode) { if (mode != NO_DECOMPOSITION @@ -123,6 +349,17 @@ public abstract class Collator implements Comparator, Cloneable decmp = mode; } + /** + * This method sets the strength setting for this object to the specified + * value. This must be one of PRIMARY, SECONDARY, TERTIARY, or IDENTICAL. + * Otherwise an exception is thrown. See the documentation for these + * constants for an explanation of this setting. + * + * @param strength The new strength setting. + * + * @exception IllegalArgumentException If the requested strength + * setting value is not valid. + */ public synchronized void setStrength (int strength) { if (strength != PRIMARY && strength != SECONDARY @@ -134,7 +371,13 @@ public abstract class Collator implements Comparator, Cloneable // Decompose a single character and append results to the buffer. native final void decomposeCharacter (char c, StringBuffer buf); - // These names are fixed by the serialization spec. + /** + * This is the current collation decomposition setting. + */ int decmp; + + /** + * This is the current collation strength setting. + */ int strength; } -- cgit v1.2.1