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

  1. package java.text;
  2.  
  3. final class CompactCharArray 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 char[] values;
  11.    private short[] indices;
  12.    private int[] hashes;
  13.    private boolean isCompact;
  14.  
  15.    public CompactCharArray() {
  16.       this('\u0000');
  17.    }
  18.  
  19.    public CompactCharArray(char var1) {
  20.       this.values = new char[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 CompactCharArray(short[] var1, char[] 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 char elementAt(char var1) {
  54.       return this.values[(this.indices[var1 >> 7] & '\uffff') + (var1 & 127)];
  55.    }
  56.  
  57.    public void setElementAt(char var1, char 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, char 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.                   }
  97.  
  98.                   ++var7;
  99.                }
  100.  
  101.                if (this.indices[var4] == -1) {
  102.                   System.arraycopy(this.values, var2, this.values, var6, 128);
  103.                   this.indices[var4] = (short)var6;
  104.                   this.hashes[var7] = this.hashes[var4];
  105.                   ++var1;
  106.                   if (!var5) {
  107.                      var3 = (short)var6;
  108.                   }
  109.                }
  110.             }
  111.  
  112.             ++var4;
  113.          }
  114.  
  115.          int var8 = var1 * 128;
  116.          char[] var9 = new char[var8];
  117.          System.arraycopy(this.values, 0, var9, 0, var8);
  118.          this.values = var9;
  119.          this.isCompact = true;
  120.          this.hashes = null;
  121.       }
  122.  
  123.    }
  124.  
  125.    static final boolean arrayRegionMatches(char[] var0, int var1, char[] var2, int var3, int var4) {
  126.       int var5 = var1 + var4;
  127.       int var6 = var3 - var1;
  128.  
  129.       for(int var7 = var1; var7 < var5; ++var7) {
  130.          if (var0[var7] != var2[var7 + var6]) {
  131.             return false;
  132.          }
  133.       }
  134.  
  135.       return true;
  136.    }
  137.  
  138.    private final void touchBlock(int var1, int var2) {
  139.       this.hashes[var1] = this.hashes[var1] + (var2 << 1) | 1;
  140.    }
  141.  
  142.    private final boolean blockTouched(int var1) {
  143.       return this.hashes[var1] != 0;
  144.    }
  145.  
  146.    public short[] getIndexArray() {
  147.       return this.indices;
  148.    }
  149.  
  150.    public char[] getStringArray() {
  151.       return this.values;
  152.    }
  153.  
  154.    public Object clone() {
  155.       try {
  156.          CompactCharArray var1 = (CompactCharArray)super.clone();
  157.          var1.values = (char[])this.values.clone();
  158.          var1.indices = (short[])this.indices.clone();
  159.          if (this.hashes != null) {
  160.             var1.hashes = (int[])this.hashes.clone();
  161.          }
  162.  
  163.          return var1;
  164.       } catch (CloneNotSupportedException var2) {
  165.          throw new InternalError();
  166.       }
  167.    }
  168.  
  169.    public boolean equals(Object var1) {
  170.       if (var1 == null) {
  171.          return false;
  172.       } else if (this == var1) {
  173.          return true;
  174.       } else if (this.getClass() != var1.getClass()) {
  175.          return false;
  176.       } else {
  177.          CompactCharArray var2 = (CompactCharArray)var1;
  178.  
  179.          for(int var3 = 0; var3 < 65536; ++var3) {
  180.             if (this.elementAt((char)var3) != var2.elementAt((char)var3)) {
  181.                return false;
  182.             }
  183.          }
  184.  
  185.          return true;
  186.       }
  187.    }
  188.  
  189.    public int hashCode() {
  190.       int var1 = 0;
  191.       int var2 = Math.min(3, this.values.length / 16);
  192.  
  193.       for(int var3 = 0; var3 < this.values.length; var3 += var2) {
  194.          var1 = var1 * 37 + this.values[var3];
  195.       }
  196.  
  197.       return var1;
  198.    }
  199.  
  200.    private void expand() {
  201.       if (this.isCompact) {
  202.          char[] var2 = new char[65536];
  203.          this.hashes = new int[512];
  204.  
  205.          for(int var1 = 0; var1 < 65536; ++var1) {
  206.             char var3 = this.elementAt((char)var1);
  207.             var2[var1] = var3;
  208.             this.touchBlock(var1 >> 7, var3);
  209.          }
  210.  
  211.          for(int var4 = 0; var4 < 512; ++var4) {
  212.             this.indices[var4] = (short)(var4 << 7);
  213.          }
  214.  
  215.          this.values = null;
  216.          this.values = var2;
  217.          this.isCompact = false;
  218.       }
  219.  
  220.    }
  221.  
  222.    private char getArrayValue(int var1) {
  223.       return this.values[var1];
  224.    }
  225.  
  226.    private short getIndexArrayValue(int var1) {
  227.       return this.indices[var1];
  228.    }
  229. }
  230.