OSDN Git Service

* java/util/GregorianCalendar.java (setDefaultTime): New method.
[pf3gnuchains/gcc-fork.git] / libjava / java / text / Collator.java
1 // Collator.java - Locale-sensitive string comparison.
2
3 /* Copyright (C) 1999  Cygnus Solutions
4
5    This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10
11 package java.text;
12
13 import java.io.Serializable;
14 import java.util.Locale;
15 import java.util.MissingResourceException;
16 import java.util.ResourceBundle;
17
18 /**
19  * @author Tom Tromey <tromey@cygnus.com>
20  * @date March 18, 1999
21  */
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.
25  */
26
27 public abstract class Collator implements Cloneable, Serializable
28 {
29   public static final int NO_DECOMPOSITION = 0;
30   public static final int CANONCIAL_DECOMPOSITION = 1;
31   public static final int FULL_DECOMPOSITION = 2;
32
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;
37
38   protected Collator ()
39   {
40     strength = TERTIARY;
41     decmp = CANONCIAL_DECOMPOSITION;
42   }
43
44   public abstract int compare (String source, String target);
45
46   public boolean equals (Object obj)
47   {
48     if (! (obj instanceof Collator))
49       return false;
50     Collator c = (Collator) obj;
51     return decmp == c.decmp && strength == c.strength;
52   }
53
54   public boolean equals (String source, String target)
55   {
56     return compare (source, target) == 0;
57   }
58
59   public static synchronized Locale[] getAvailableLocales ()
60   {
61     // FIXME.
62     return null;
63   }
64
65   public abstract CollationKey getCollationKey (String source);
66
67   public synchronized int getDecomposition ()
68   {
69     return decmp;
70   }
71
72   public static Collator getInstance ()
73   {
74     return getInstance (Locale.getDefault());
75   }
76
77   public static Collator getInstance (Locale loc)
78   {
79     ResourceBundle res;
80     String pattern;
81     try
82       {
83         res = ResourceBundle.getBundle("gnu.gcj.text.LocaleData", loc);
84         pattern = res.getString("collatorRule");
85       }
86     catch (MissingResourceException x)
87       {
88         return null;
89       }
90     try
91       {
92         return new RuleBasedCollator (pattern);
93       }
94     catch (ParseException x)
95       {
96         return null;
97       }
98   }
99
100   public synchronized int getStrength ()
101   {
102     return strength;
103   }
104
105   public abstract int hashCode ();
106
107   public synchronized void setDecomposition (int mode)
108   {
109     if (mode != NO_DECOMPOSITION
110         && mode != CANONCIAL_DECOMPOSITION
111         && mode != FULL_DECOMPOSITION)
112       throw new IllegalArgumentException ();
113     decmp = mode;
114   }
115
116   public synchronized void setStrength (int strength)
117   {
118     if (strength != PRIMARY && strength != SECONDARY
119         && strength != TERTIARY && strength != IDENTICAL)
120       throw new IllegalArgumentException ();
121     this.strength = strength;
122   }
123
124   // Decompose a single character and append results to the buffer.
125   protected native final void decomposeCharacter (char c, StringBuffer buf);
126
127   // These names are fixed by the serialization spec.
128   protected int decmp;
129   protected int strength;
130 }