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 / CompactShortArray.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  2.8 KB  |  227 lines

  1. package java.text;
  2.  
  3. final class CompactShortArray implements Cloneable {
  4.    public static final int UNICODECOUNT = 65536;
  5.    static final int BLOCKSHIFT = 7;
  6.    static final int BLOCKCOUNT = 128;
  7.    static final int INDEXSHIFT = 9;
  8.    static final int INDEXCOUNT = 512;
  9.    static final int BLOCKMASK = 127;
  10.    private short[] values;
  11.    private short[] indices;
  12.    private int[] hashes;
  13.    private boolean isCompact;
  14.    short defaultValue;
  15.  
  16.    public CompactShortArray() {
  17.       this((short)0);
  18.    }
  19.  
  20.    public CompactShortArray(short var1) {
  21.       this.values = new short[65536];
  22.       this.indices = new short[512];
  23.       this.hashes = new int[512];
  24.  
  25.       for(int var2 = 0; var2 < 65536; ++var2) {
  26.          this.values[var2] = var1;
  27.       }
  28.  
  29.       for(int var3 = 0; var3 < 512; ++var3) {
  30.          this.indices[var3] = (short)(var3 << 7);
  31.          this.hashes[var3] = 0;
  32.       }
  33.  
  34.       this.isCompact = false;
  35.       this.defaultValue = var1;
  36.    }
  37.  
  38.    public CompactShortArray(short[] var1, short[] var2, short var3) {
  39.       if (var1.length != 512) {
  40.          throw new IllegalArgumentException("Index out of bounds.");
  41.       } else {
  42.          for(int var4 = 0; var4 < 512; ++var4) {
  43.             short var5 = var1[var4];
  44.             if (var5 < 0 || var5 >= var2.length + 128) {
  45.                throw new IllegalArgumentException("Index out of bounds.");
  46.             }
  47.          }
  48.  
  49.          this.indices = var1;
  50.          this.values = var2;
  51.          this.isCompact = true;
  52.          this.defaultValue = var3;
  53.       }
  54.    }
  55.  
  56.    public short elementAt(char var1) {
  57.       return this.values[(this.indices[var1 >> 7] & '\uffff') + (var1 & 127)];
  58.    }
  59.  
  60.    public void setElementAt(char var1, short var2) {
  61.       if (this.isCompact) {
  62.          this.expand();
  63.       }
  64.  
  65.       this.values[var1] = var2;
  66.       this.touchBlock(var1 >> 7, var2);
  67.    }
  68.  
  69.    public void setElementAt(char var1, char var2, short var3) {
  70.       if (this.isCompact) {
  71.          this.expand();
  72.       }
  73.  
  74.       for(int var4 = var1; var4 <= var2; ++var4) {
  75.          this.values[var4] = var3;
  76.          this.touchBlock(var4 >> 7, var3);
  77.       }
  78.  
  79.    }
  80.  
  81.    public void compact() {
  82.       if (!this.isCompact) {
  83.          int var1 = 0;
  84.          int var2 = 0;
  85.          short var3 = -1;
  86.  
  87.          for(int var4 = 0; var4 < this.indices.length; var2 += 128) {
  88.             this.indices[var4] = -1;
  89.             boolean var5 = this.blockTouched(var4);
  90.             if (!var5 && var3 != -1) {
  91.                this.indices[var4] = var3;
  92.             } else {
  93.                int var6 = 0;
  94.                int var7 = 0;
  95.  
  96.                for(var7 = 0; var7 < var1; var6 += 128) {
  97.                   if (this.hashes[var4] == this.hashes[var7] && arrayRegionMatches(this.values, var2, this.values, var6, 128)) {
  98.                      this.indices[var4] = (short)var6;
  99.                   }
  100.  
  101.                   ++var7;
  102.                }
  103.  
  104.                if (this.indices[var4] == -1) {
  105.                   System.arraycopy(this.values, var2, this.values, var6, 128);
  106.                   this.indices[var4] = (short)var6;
  107.                   this.hashes[var7] = this.hashes[var4];
  108.                   ++var1;
  109.                   if (!var5) {
  110.                      var3 = (short)var6;
  111.                   }
  112.                }
  113.             }
  114.  
  115.             ++var4;
  116.          }
  117.  
  118.          int var8 = var1 * 128;
  119.          short[] var9 = new short[var8];
  120.          System.arraycopy(this.values, 0, var9, 0, var8);
  121.          this.values = var9;
  122.          this.isCompact = true;
  123.          this.hashes = null;
  124.       }
  125.  
  126.    }
  127.  
  128.    static final boolean arrayRegionMatches(short[] var0, int var1, short[] var2, int var3, int var4) {
  129.       int var5 = var1 + var4;
  130.       int var6 = var3 - var1;
  131.  
  132.       for(int var7 = var1; var7 < var5; ++var7) {
  133.          if (var0[var7] != var2[var7 + var6]) {
  134.             return false;
  135.          }
  136.       }
  137.  
  138.       return true;
  139.    }
  140.  
  141.    private final void touchBlock(int var1, int var2) {
  142.       this.hashes[var1] = this.hashes[var1] + (var2 << 1) | 1;
  143.    }
  144.  
  145.    private final boolean blockTouched(int var1) {
  146.       return this.hashes[var1] != 0;
  147.    }
  148.  
  149.    public short[] getIndexArray() {
  150.       return this.indices;
  151.    }
  152.  
  153.    public short[] getStringArray() {
  154.       return this.values;
  155.    }
  156.  
  157.    public Object clone() {
  158.       try {
  159.          CompactShortArray var1 = (CompactShortArray)super.clone();
  160.          var1.values = (short[])this.values.clone();
  161.          var1.indices = (short[])this.indices.clone();
  162.          return var1;
  163.       } catch (CloneNotSupportedException var2) {
  164.          throw new InternalError();
  165.       }
  166.    }
  167.  
  168.    public boolean equals(Object var1) {
  169.       if (var1 == null) {
  170.          return false;
  171.       } else if (this == var1) {
  172.          return true;
  173.       } else if (this.getClass() != var1.getClass()) {
  174.          return false;
  175.       } else {
  176.          CompactShortArray var2 = (CompactShortArray)var1;
  177.  
  178.          for(int var3 = 0; var3 < 65536; ++var3) {
  179.             if (this.elementAt((char)var3) != var2.elementAt((char)var3)) {
  180.                return false;
  181.             }
  182.          }
  183.  
  184.          return true;
  185.       }
  186.    }
  187.  
  188.    public int hashCode() {
  189.       int var1 = 0;
  190.       int var2 = Math.min(3, this.values.length / 16);
  191.  
  192.       for(int var3 = 0; var3 < this.values.length; var3 += var2) {
  193.          var1 = var1 * 37 + this.values[var3];
  194.       }
  195.  
  196.       return var1;
  197.    }
  198.  
  199.    public Iterator getIterator() {
  200.       return new Iterator(this);
  201.    }
  202.  
  203.    private void expand() {
  204.       if (this.isCompact) {
  205.          short[] var2 = new short[65536];
  206.  
  207.          for(int var1 = 0; var1 < 65536; ++var1) {
  208.             var2[var1] = this.elementAt((char)var1);
  209.          }
  210.  
  211.          for(int var3 = 0; var3 < 512; ++var3) {
  212.             this.indices[var3] = (short)(var3 << 7);
  213.          }
  214.  
  215.          this.values = null;
  216.          this.values = var2;
  217.          this.isCompact = false;
  218.       }
  219.  
  220.    }
  221.  
  222.    // $FF: synthetic method
  223.    static short[] access$000(CompactShortArray var0) {
  224.       return var0.indices;
  225.    }
  226. }
  227.