1 // Collator.java - Locale-sensitive string comparison.
3 /* Copyright (C) 1999, 2000 Free Software Foundation
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
.util
.Locale
;
14 import java
.util
.MissingResourceException
;
15 import java
.util
.ResourceBundle
;
16 import java
.util
.Comparator
;
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 Comparator
, Cloneable
29 public static final int NO_DECOMPOSITION
= 0;
30 public static final int CANONICAL_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
= CANONICAL_DECOMPOSITION
;
44 public abstract int compare (String source
, String target
);
46 public int compare (Object o1
, Object o2
)
48 return compare ((String
) o1
, (String
) o2
);
51 public boolean equals (Object obj
)
53 if (! (obj
instanceof Collator
))
55 Collator c
= (Collator
) obj
;
56 return decmp
== c
.decmp
&& strength
== c
.strength
;
59 public boolean equals (String source
, String target
)
61 return compare (source
, target
) == 0;
64 public Object
clone ()
66 return super.clone ();
69 public static synchronized Locale
[] getAvailableLocales ()
75 public abstract CollationKey
getCollationKey (String source
);
77 public synchronized int getDecomposition ()
82 public static Collator
getInstance ()
84 return getInstance (Locale
.getDefault());
87 public static Collator
getInstance (Locale loc
)
93 res
= ResourceBundle
.getBundle("gnu.gcj.text.LocaleData", loc
);
94 pattern
= res
.getString("collatorRule");
96 catch (MissingResourceException x
)
102 return new RuleBasedCollator (pattern
);
104 catch (ParseException x
)
110 public synchronized int getStrength ()
115 public abstract int hashCode ();
117 public synchronized void setDecomposition (int mode
)
119 if (mode
!= NO_DECOMPOSITION
120 && mode
!= CANONICAL_DECOMPOSITION
121 && mode
!= FULL_DECOMPOSITION
)
122 throw new IllegalArgumentException ();
126 public synchronized void setStrength (int strength
)
128 if (strength
!= PRIMARY
&& strength
!= SECONDARY
129 && strength
!= TERTIARY
&& strength
!= IDENTICAL
)
130 throw new IllegalArgumentException ();
131 this.strength
= strength
;
134 // Decompose a single character and append results to the buffer.
135 native final void decomposeCharacter (char c
, StringBuffer buf
);
137 // These names are fixed by the serialization spec.