home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / text / Collator.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  3.2 KB  |  128 lines

  1. package java.text;
  2.  
  3. import java.text.resources.LocaleData;
  4. import java.util.Comparator;
  5. import java.util.Locale;
  6. import java.util.MissingResourceException;
  7. import java.util.ResourceBundle;
  8. import sun.misc.SoftCache;
  9.  
  10. public abstract class Collator implements Comparator, Cloneable {
  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 = 0;
  19.    private int decmp = 0;
  20.    private static SoftCache cache = new SoftCache();
  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.          int var3 = 1;
  37.  
  38.          try {
  39.             ResourceBundle var4 = ResourceBundle.getBundle("java.text.resources.LocaleElements", var0);
  40.             var2 = var4.getString("CollationElements");
  41.             var3 = (Integer)var4.getObject("CollationDecomp");
  42.          } catch (MissingResourceException var8) {
  43.          }
  44.  
  45.          try {
  46.             var1 = new RuleBasedCollator(CollationRules.DEFAULTRULES + var2, var3);
  47.          } catch (ParseException var7) {
  48.             try {
  49.                var1 = new RuleBasedCollator(CollationRules.DEFAULTRULES);
  50.             } catch (ParseException var6) {
  51.             }
  52.          }
  53.  
  54.          var1.setDecomposition(0);
  55.          cache.put(var0, var1);
  56.          return (Collator)((RuleBasedCollator)var1).clone();
  57.       }
  58.    }
  59.  
  60.    public abstract int compare(String var1, String var2);
  61.  
  62.    public int compare(Object var1, Object var2) {
  63.       return this.compare((String)var1, (String)var2);
  64.    }
  65.  
  66.    public abstract CollationKey getCollationKey(String var1);
  67.  
  68.    public boolean equals(String var1, String var2) {
  69.       return this.compare(var1, var2) == 0;
  70.    }
  71.  
  72.    public synchronized int getStrength() {
  73.       return this.strength;
  74.    }
  75.  
  76.    public synchronized void setStrength(int var1) {
  77.       if (var1 != 0 && var1 != 1 && var1 != 2 && var1 != 3) {
  78.          throw new IllegalArgumentException("Incorrect comparison level.");
  79.       } else {
  80.          this.strength = var1;
  81.       }
  82.    }
  83.  
  84.    public synchronized int getDecomposition() {
  85.       return this.decmp;
  86.    }
  87.  
  88.    public synchronized void setDecomposition(int var1) {
  89.       if (var1 != 0 && var1 != 1 && var1 != 2) {
  90.          throw new IllegalArgumentException("Wrong decomposition mode.");
  91.       } else {
  92.          this.decmp = var1;
  93.       }
  94.    }
  95.  
  96.    public static synchronized Locale[] getAvailableLocales() {
  97.       return LocaleData.getAvailableLocales("CollationElements");
  98.    }
  99.  
  100.    public Object clone() {
  101.       try {
  102.          return (Collator)super.clone();
  103.       } catch (CloneNotSupportedException var2) {
  104.          throw new InternalError();
  105.       }
  106.    }
  107.  
  108.    public boolean equals(Object var1) {
  109.       if (this == var1) {
  110.          return true;
  111.       } else if (var1 == null) {
  112.          return false;
  113.       } else if (this.getClass() != var1.getClass()) {
  114.          return false;
  115.       } else {
  116.          Collator var2 = (Collator)var1;
  117.          return this.strength == var2.strength && this.decmp == var2.decmp;
  118.       }
  119.    }
  120.  
  121.    public abstract int hashCode();
  122.  
  123.    protected Collator() {
  124.       this.strength = 2;
  125.       this.decmp = 1;
  126.    }
  127. }
  128.