home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / java / text / CompactByteArray.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  2.5 KB  |  227 lines

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