1 // Collator.java - Locale-sensitive string comparison.
3 /* Copyright (C) 1999 Cygnus Solutions
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
13 import java.io.Serializable;
14 import java.util.Locale;
15 import java.util.MissingResourceException;
16 import java.util.ResourceBundle;
19 * @author Tom Tromey <tromey@cygnus.com>
20 * @date March 18, 1999
22 /* Written using "Java Class Libraries", 2nd edition, plus online
23 * API docs for JDK 1.2 from http://www.javasoft.com.
24 * Status: Mostly complete, but parts stubbed out. Look for FIXME.
27 public abstract class Collator implements Cloneable, Serializable
29 public static final int NO_DECOMPOSITION = 0;
30 public static final int CANONCIAL_DECOMPOSITION = 1;
31 public static final int FULL_DECOMPOSITION = 2;
33 public static final int PRIMARY = 0;
34 public static final int SECONDARY = 1;
35 public static final int TERTIARY = 2;
36 public static final int IDENTICAL = 3;
41 decmp = CANONCIAL_DECOMPOSITION;
44 public abstract int compare (String source, String target);
46 public boolean equals (Object obj)
48 if (! (obj instanceof Collator))
50 Collator c = (Collator) obj;
51 return decmp == c.decmp && strength == c.strength;
54 public boolean equals (String source, String target)
56 return compare (source, target) == 0;
59 public static synchronized Locale[] getAvailableLocales ()
65 public abstract CollationKey getCollationKey (String source);
67 public synchronized int getDecomposition ()
72 public static Collator getInstance ()
74 return getInstance (Locale.getDefault());
77 public static Collator getInstance (Locale loc)
83 res = ResourceBundle.getBundle("gnu.gcj.text.LocaleData", loc);
84 pattern = res.getString("collatorRule");
86 catch (MissingResourceException x)
92 return new RuleBasedCollator (pattern);
94 catch (ParseException x)
100 public synchronized int getStrength ()
105 public abstract int hashCode ();
107 public synchronized void setDecomposition (int mode)
109 if (mode != NO_DECOMPOSITION
110 && mode != CANONCIAL_DECOMPOSITION
111 && mode != FULL_DECOMPOSITION)
112 throw new IllegalArgumentException ();
116 public synchronized void setStrength (int strength)
118 if (strength != PRIMARY && strength != SECONDARY
119 && strength != TERTIARY && strength != IDENTICAL)
120 throw new IllegalArgumentException ();
121 this.strength = strength;
124 // Decompose a single character and append results to the buffer.
125 protected native final void decomposeCharacter (char c, StringBuffer buf);
127 // These names are fixed by the serialization spec.
129 protected int strength;