home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / sun / text / CompactByteArray.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  2.5 KB  |  223 lines

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