home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / java / text / Collator.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  3.0 KB  |  117 lines

  1. package java.text;
  2.  
  3. import java.io.Serializable;
  4. import java.text.resources.LocaleData;
  5. import java.util.Hashtable;
  6. import java.util.Locale;
  7. import java.util.MissingResourceException;
  8. import java.util.ResourceBundle;
  9.  
  10. public abstract class Collator implements Cloneable, Serializable {
  11.    public static final int PRIMARY = 0;
  12.    public static final int SECONDARY = 1;
  13.    public static final int TERTIARY = 2;
  14.    public static final int IDENTICAL = 3;
  15.    public static final int NO_DECOMPOSITION = 0;
  16.    public static final int CANONICAL_DECOMPOSITION = 1;
  17.    public static final int FULL_DECOMPOSITION = 2;
  18.    private int strength = 2;
  19.    private int decmp = 1;
  20.    private static Hashtable cache = new Hashtable();
  21.    static final int LESS = -1;
  22.    static final int EQUAL = 0;
  23.    static final int GREATER = 1;
  24.  
  25.    public static synchronized Collator getInstance() {
  26.       return getInstance(Locale.getDefault());
  27.    }
  28.  
  29.    public static synchronized Collator getInstance(Locale var0) {
  30.       Collator var1 = null;
  31.       var1 = (RuleBasedCollator)cache.get(var0);
  32.       if (var1 != null) {
  33.          return (Collator)((RuleBasedCollator)var1).clone();
  34.       } else {
  35.          String var2;
  36.          try {
  37.             ResourceBundle var3 = ResourceBundle.getBundle("java.text.resources.LocaleElements", var0);
  38.             var2 = var3.getString("CollationElements");
  39.          } catch (MissingResourceException var6) {
  40.             var2 = "";
  41.          }
  42.  
  43.          try {
  44.             var1 = new RuleBasedCollator(CollationRules.DEFAULTRULES + var2);
  45.          } catch (ParseException var5) {
  46.             try {
  47.                var1 = new RuleBasedCollator(CollationRules.DEFAULTRULES);
  48.             } catch (ParseException var4) {
  49.             }
  50.          }
  51.  
  52.          cache.put(var0, var1);
  53.          return var1;
  54.       }
  55.    }
  56.  
  57.    public abstract int compare(String var1, String var2);
  58.  
  59.    public abstract CollationKey getCollationKey(String var1);
  60.  
  61.    public boolean equals(String var1, String var2) {
  62.       return this.compare(var1, var2) == 0;
  63.    }
  64.  
  65.    public synchronized int getStrength() {
  66.       return this.strength;
  67.    }
  68.  
  69.    public synchronized void setStrength(int var1) {
  70.       if (var1 != 0 && var1 != 1 && var1 != 2) {
  71.          throw new IllegalArgumentException("Incorrect comparison level.");
  72.       } else {
  73.          this.strength = var1;
  74.       }
  75.    }
  76.  
  77.    public synchronized int getDecomposition() {
  78.       return this.decmp;
  79.    }
  80.  
  81.    public synchronized void setDecomposition(int var1) {
  82.       if (var1 != 0 && var1 != 1 && var1 != 2) {
  83.          throw new IllegalArgumentException("Wrong decomposition mode.");
  84.       } else {
  85.          this.decmp = var1;
  86.       }
  87.    }
  88.  
  89.    public static synchronized Locale[] getAvailableLocales() {
  90.       return LocaleData.getAvailableLocales("CollationElements");
  91.    }
  92.  
  93.    public Object clone() {
  94.       try {
  95.          return (Collator)super.clone();
  96.       } catch (CloneNotSupportedException var1) {
  97.          throw new InternalError();
  98.       }
  99.    }
  100.  
  101.    public boolean equals(Object var1) {
  102.       if (this == var1) {
  103.          return true;
  104.       } else if (this.getClass() != var1.getClass()) {
  105.          return false;
  106.       } else {
  107.          Collator var2 = (Collator)var1;
  108.          return this.strength == var2.strength && this.decmp == var2.decmp;
  109.       }
  110.    }
  111.  
  112.    public abstract synchronized int hashCode();
  113.  
  114.    protected Collator() {
  115.    }
  116. }
  117.