home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / text / Collator.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  3.4 KB  |  120 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.    static final long serialVersionUID = -7718728969026499504L;
  25.  
  26.    public static synchronized Collator getInstance() {
  27.       return getInstance(Locale.getDefault());
  28.    }
  29.  
  30.    public static synchronized Collator getInstance(Locale var0) {
  31.       Collator var1 = null;
  32.       var1 = (RuleBasedCollator)cache.get(var0);
  33.       if (var1 != null) {
  34.          return (Collator)((RuleBasedCollator)var1).clone();
  35.       } else {
  36.          String var2;
  37.          try {
  38.             ResourceBundle var3 = ResourceBundle.getBundle("java.text.resources.LocaleElements", var0);
  39.             var2 = var3.getString("CollationElements");
  40.          } catch (MissingResourceException var6) {
  41.             var2 = "";
  42.          }
  43.  
  44.          try {
  45.             var1 = new RuleBasedCollator(CollationRules.DEFAULTRULES + var2);
  46.          } catch (ParseException var5) {
  47.             try {
  48.                var1 = new RuleBasedCollator(CollationRules.DEFAULTRULES);
  49.             } catch (ParseException var4) {
  50.             }
  51.          }
  52.  
  53.          cache.put(var0, var1);
  54.          return var1;
  55.       }
  56.    }
  57.  
  58.    public abstract int compare(String var1, String var2);
  59.  
  60.    public abstract CollationKey getCollationKey(String var1);
  61.  
  62.    public boolean equals(String var1, String var2) {
  63.       return this.compare(var1, var2) == 0;
  64.    }
  65.  
  66.    public synchronized int getStrength() {
  67.       return this.strength;
  68.    }
  69.  
  70.    public synchronized void setStrength(int var1) {
  71.       if (var1 != 0 && var1 != 1 && var1 != 2 && var1 != 3) {
  72.          throw new IllegalArgumentException("Incorrect comparison level.");
  73.       } else {
  74.          this.strength = var1;
  75.       }
  76.    }
  77.  
  78.    public synchronized int getDecomposition() {
  79.       return this.decmp;
  80.    }
  81.  
  82.    public synchronized void setDecomposition(int var1) {
  83.       if (var1 != 0 && var1 != 1 && var1 != 2) {
  84.          throw new IllegalArgumentException("Wrong decomposition mode.");
  85.       } else {
  86.          this.decmp = var1;
  87.       }
  88.    }
  89.  
  90.    public static synchronized Locale[] getAvailableLocales() {
  91.       return LocaleData.getAvailableLocales("CollationElements");
  92.    }
  93.  
  94.    public Object clone() {
  95.       try {
  96.          return (Collator)super.clone();
  97.       } catch (CloneNotSupportedException var1) {
  98.          throw new InternalError();
  99.       }
  100.    }
  101.  
  102.    public boolean equals(Object var1) {
  103.       if (this == var1) {
  104.          return true;
  105.       } else if (var1 == null) {
  106.          return false;
  107.       } else if (this.getClass() != var1.getClass()) {
  108.          return false;
  109.       } else {
  110.          Collator var2 = (Collator)var1;
  111.          return this.strength == var2.strength && this.decmp == var2.decmp;
  112.       }
  113.    }
  114.  
  115.    public abstract int hashCode();
  116.  
  117.    protected Collator() {
  118.    }
  119. }
  120.