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 / util / Vector.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  5.6 KB  |  399 lines

  1. package java.util;
  2.  
  3. import java.io.Serializable;
  4. import java.lang.reflect.Array;
  5.  
  6. public class Vector extends AbstractList implements List, Cloneable, Serializable {
  7.    protected Object[] elementData;
  8.    protected int elementCount;
  9.    protected int capacityIncrement;
  10.    private static final long serialVersionUID = -2767605614048989439L;
  11.  
  12.    public Vector(int var1, int var2) {
  13.       if (var1 < 0) {
  14.          throw new IllegalArgumentException("Illegal Capacity: " + var1);
  15.       } else {
  16.          this.elementData = new Object[var1];
  17.          this.capacityIncrement = var2;
  18.       }
  19.    }
  20.  
  21.    public Vector(int var1) {
  22.       this(var1, 0);
  23.    }
  24.  
  25.    public Vector() {
  26.       this(10);
  27.    }
  28.  
  29.    public Vector(Collection var1) {
  30.       this.elementCount = var1.size();
  31.       this.elementData = new Object[this.elementCount * 110 / 100];
  32.       var1.toArray(this.elementData);
  33.    }
  34.  
  35.    public synchronized void copyInto(Object[] var1) {
  36.       System.arraycopy(this.elementData, 0, var1, 0, this.elementCount);
  37.    }
  38.  
  39.    public synchronized void trimToSize() {
  40.       ++super.modCount;
  41.       int var1 = this.elementData.length;
  42.       if (this.elementCount < var1) {
  43.          Object[] var2 = this.elementData;
  44.          this.elementData = new Object[this.elementCount];
  45.          System.arraycopy(var2, 0, this.elementData, 0, this.elementCount);
  46.       }
  47.  
  48.    }
  49.  
  50.    public synchronized void ensureCapacity(int var1) {
  51.       ++super.modCount;
  52.       this.ensureCapacityHelper(var1);
  53.    }
  54.  
  55.    private void ensureCapacityHelper(int var1) {
  56.       int var2 = this.elementData.length;
  57.       if (var1 > var2) {
  58.          Object[] var3 = this.elementData;
  59.          int var4 = this.capacityIncrement > 0 ? var2 + this.capacityIncrement : var2 * 2;
  60.          if (var4 < var1) {
  61.             var4 = var1;
  62.          }
  63.  
  64.          this.elementData = new Object[var4];
  65.          System.arraycopy(var3, 0, this.elementData, 0, this.elementCount);
  66.       }
  67.  
  68.    }
  69.  
  70.    public synchronized void setSize(int var1) {
  71.       ++super.modCount;
  72.       if (var1 > this.elementCount) {
  73.          this.ensureCapacityHelper(var1);
  74.       } else {
  75.          for(int var2 = var1; var2 < this.elementCount; ++var2) {
  76.             this.elementData[var2] = null;
  77.          }
  78.       }
  79.  
  80.       this.elementCount = var1;
  81.    }
  82.  
  83.    public int capacity() {
  84.       return this.elementData.length;
  85.    }
  86.  
  87.    public int size() {
  88.       return this.elementCount;
  89.    }
  90.  
  91.    public boolean isEmpty() {
  92.       return this.elementCount == 0;
  93.    }
  94.  
  95.    public Enumeration elements() {
  96.       return new 1(this);
  97.    }
  98.  
  99.    public boolean contains(Object var1) {
  100.       return this.indexOf(var1, 0) >= 0;
  101.    }
  102.  
  103.    public int indexOf(Object var1) {
  104.       return this.indexOf(var1, 0);
  105.    }
  106.  
  107.    public synchronized int indexOf(Object var1, int var2) {
  108.       if (var1 == null) {
  109.          for(int var3 = var2; var3 < this.elementCount; ++var3) {
  110.             if (this.elementData[var3] == null) {
  111.                return var3;
  112.             }
  113.          }
  114.       } else {
  115.          for(int var4 = var2; var4 < this.elementCount; ++var4) {
  116.             if (var1.equals(this.elementData[var4])) {
  117.                return var4;
  118.             }
  119.          }
  120.       }
  121.  
  122.       return -1;
  123.    }
  124.  
  125.    public int lastIndexOf(Object var1) {
  126.       return this.lastIndexOf(var1, this.elementCount - 1);
  127.    }
  128.  
  129.    public synchronized int lastIndexOf(Object var1, int var2) {
  130.       if (var2 >= this.elementCount) {
  131.          throw new IndexOutOfBoundsException(var2 + " >= " + this.elementCount);
  132.       } else {
  133.          if (var1 == null) {
  134.             for(int var3 = var2; var3 >= 0; --var3) {
  135.                if (this.elementData[var3] == null) {
  136.                   return var3;
  137.                }
  138.             }
  139.          } else {
  140.             for(int var4 = var2; var4 >= 0; --var4) {
  141.                if (var1.equals(this.elementData[var4])) {
  142.                   return var4;
  143.                }
  144.             }
  145.          }
  146.  
  147.          return -1;
  148.       }
  149.    }
  150.  
  151.    public synchronized Object elementAt(int var1) {
  152.       if (var1 >= this.elementCount) {
  153.          throw new ArrayIndexOutOfBoundsException(var1 + " >= " + this.elementCount);
  154.       } else {
  155.          try {
  156.             return this.elementData[var1];
  157.          } catch (ArrayIndexOutOfBoundsException var3) {
  158.             throw new ArrayIndexOutOfBoundsException(var1 + " < 0");
  159.          }
  160.       }
  161.    }
  162.  
  163.    public synchronized Object firstElement() {
  164.       if (this.elementCount == 0) {
  165.          throw new NoSuchElementException();
  166.       } else {
  167.          return this.elementData[0];
  168.       }
  169.    }
  170.  
  171.    public synchronized Object lastElement() {
  172.       if (this.elementCount == 0) {
  173.          throw new NoSuchElementException();
  174.       } else {
  175.          return this.elementData[this.elementCount - 1];
  176.       }
  177.    }
  178.  
  179.    public synchronized void setElementAt(Object var1, int var2) {
  180.       if (var2 >= this.elementCount) {
  181.          throw new ArrayIndexOutOfBoundsException(var2 + " >= " + this.elementCount);
  182.       } else {
  183.          this.elementData[var2] = var1;
  184.       }
  185.    }
  186.  
  187.    public synchronized void removeElementAt(int var1) {
  188.       ++super.modCount;
  189.       if (var1 >= this.elementCount) {
  190.          throw new ArrayIndexOutOfBoundsException(var1 + " >= " + this.elementCount);
  191.       } else if (var1 < 0) {
  192.          throw new ArrayIndexOutOfBoundsException(var1);
  193.       } else {
  194.          int var2 = this.elementCount - var1 - 1;
  195.          if (var2 > 0) {
  196.             System.arraycopy(this.elementData, var1 + 1, this.elementData, var1, var2);
  197.          }
  198.  
  199.          --this.elementCount;
  200.          this.elementData[this.elementCount] = null;
  201.       }
  202.    }
  203.  
  204.    public synchronized void insertElementAt(Object var1, int var2) {
  205.       ++super.modCount;
  206.       if (var2 >= this.elementCount + 1) {
  207.          throw new ArrayIndexOutOfBoundsException(var2 + " > " + this.elementCount);
  208.       } else {
  209.          this.ensureCapacityHelper(this.elementCount + 1);
  210.          System.arraycopy(this.elementData, var2, this.elementData, var2 + 1, this.elementCount - var2);
  211.          this.elementData[var2] = var1;
  212.          ++this.elementCount;
  213.       }
  214.    }
  215.  
  216.    public synchronized void addElement(Object var1) {
  217.       ++super.modCount;
  218.       this.ensureCapacityHelper(this.elementCount + 1);
  219.       this.elementData[this.elementCount++] = var1;
  220.    }
  221.  
  222.    public synchronized boolean removeElement(Object var1) {
  223.       ++super.modCount;
  224.       int var2 = this.indexOf(var1);
  225.       if (var2 >= 0) {
  226.          this.removeElementAt(var2);
  227.          return true;
  228.       } else {
  229.          return false;
  230.       }
  231.    }
  232.  
  233.    public synchronized void removeAllElements() {
  234.       for(int var1 = 0; var1 < this.elementCount; ++var1) {
  235.          this.elementData[var1] = null;
  236.       }
  237.  
  238.       this.elementCount = 0;
  239.    }
  240.  
  241.    public synchronized Object clone() {
  242.       try {
  243.          Vector var1 = (Vector)super.clone();
  244.          var1.elementData = new Object[this.elementCount];
  245.          System.arraycopy(this.elementData, 0, var1.elementData, 0, this.elementCount);
  246.          var1.modCount = 0;
  247.          return var1;
  248.       } catch (CloneNotSupportedException var2) {
  249.          throw new InternalError();
  250.       }
  251.    }
  252.  
  253.    public synchronized Object[] toArray() {
  254.       Object[] var1 = new Object[this.elementCount];
  255.       System.arraycopy(this.elementData, 0, var1, 0, this.elementCount);
  256.       return var1;
  257.    }
  258.  
  259.    public synchronized Object[] toArray(Object[] var1) {
  260.       if (var1.length < this.elementCount) {
  261.          var1 = Array.newInstance(var1.getClass().getComponentType(), this.elementCount);
  262.       }
  263.  
  264.       System.arraycopy(this.elementData, 0, var1, 0, this.elementCount);
  265.       if (var1.length > this.elementCount) {
  266.          var1[this.elementCount] = null;
  267.       }
  268.  
  269.       return var1;
  270.    }
  271.  
  272.    public synchronized Object get(int var1) {
  273.       if (var1 >= this.elementCount) {
  274.          throw new ArrayIndexOutOfBoundsException(var1);
  275.       } else {
  276.          return this.elementData[var1];
  277.       }
  278.    }
  279.  
  280.    public synchronized Object set(int var1, Object var2) {
  281.       if (var1 >= this.elementCount) {
  282.          throw new ArrayIndexOutOfBoundsException(var1);
  283.       } else {
  284.          Object var3 = this.elementData[var1];
  285.          this.elementData[var1] = var2;
  286.          return var3;
  287.       }
  288.    }
  289.  
  290.    public synchronized boolean add(Object var1) {
  291.       ++super.modCount;
  292.       this.ensureCapacityHelper(this.elementCount + 1);
  293.       this.elementData[this.elementCount++] = var1;
  294.       return true;
  295.    }
  296.  
  297.    public boolean remove(Object var1) {
  298.       return this.removeElement(var1);
  299.    }
  300.  
  301.    public void add(int var1, Object var2) {
  302.       this.insertElementAt(var2, var1);
  303.    }
  304.  
  305.    public synchronized Object remove(int var1) {
  306.       ++super.modCount;
  307.       if (var1 >= this.elementCount) {
  308.          throw new ArrayIndexOutOfBoundsException(var1);
  309.       } else {
  310.          Object var2 = this.elementData[var1];
  311.          int var3 = this.elementCount - var1 - 1;
  312.          if (var3 > 0) {
  313.             System.arraycopy(this.elementData, var1 + 1, this.elementData, var1, var3);
  314.          }
  315.  
  316.          this.elementData[--this.elementCount] = null;
  317.          return var2;
  318.       }
  319.    }
  320.  
  321.    public void clear() {
  322.       this.removeAllElements();
  323.    }
  324.  
  325.    public synchronized boolean containsAll(Collection var1) {
  326.       return super.containsAll(var1);
  327.    }
  328.  
  329.    public synchronized boolean addAll(Collection var1) {
  330.       ++super.modCount;
  331.       int var2 = var1.size();
  332.       this.ensureCapacityHelper(this.elementCount + var2);
  333.       Iterator var3 = var1.iterator();
  334.  
  335.       for(int var4 = 0; var4 < var2; ++var4) {
  336.          this.elementData[this.elementCount++] = var3.next();
  337.       }
  338.  
  339.       return var2 != 0;
  340.    }
  341.  
  342.    public synchronized boolean removeAll(Collection var1) {
  343.       return super.removeAll(var1);
  344.    }
  345.  
  346.    public synchronized boolean retainAll(Collection var1) {
  347.       return super.retainAll(var1);
  348.    }
  349.  
  350.    public synchronized boolean addAll(int var1, Collection var2) {
  351.       ++super.modCount;
  352.       if (var1 >= 0 && var1 <= this.elementCount) {
  353.          int var3 = var2.size();
  354.          this.ensureCapacityHelper(this.elementCount + var3);
  355.          int var4 = this.elementCount - var1;
  356.          if (var4 > 0) {
  357.             System.arraycopy(this.elementData, var1, this.elementData, var1 + var3, var4);
  358.          }
  359.  
  360.          Iterator var5 = var2.iterator();
  361.  
  362.          for(int var6 = 0; var6 < var3; ++var6) {
  363.             this.elementData[var1++] = var5.next();
  364.          }
  365.  
  366.          this.elementCount += var3;
  367.          return var3 != 0;
  368.       } else {
  369.          throw new ArrayIndexOutOfBoundsException(var1);
  370.       }
  371.    }
  372.  
  373.    public synchronized boolean equals(Object var1) {
  374.       return super.equals(var1);
  375.    }
  376.  
  377.    public synchronized int hashCode() {
  378.       return super.hashCode();
  379.    }
  380.  
  381.    public synchronized String toString() {
  382.       return super.toString();
  383.    }
  384.  
  385.    public List subList(int var1, int var2) {
  386.       return Collections.synchronizedList(super.subList(var1, var2), this);
  387.    }
  388.  
  389.    protected void removeRange(int var1, int var2) {
  390.       ++super.modCount;
  391.       int var3 = this.elementCount - var2;
  392.       System.arraycopy(this.elementData, var2, this.elementData, var1, var3);
  393.  
  394.       for(int var4 = this.elementCount - (var2 - var1); this.elementCount != var4; this.elementData[--this.elementCount] = null) {
  395.       }
  396.  
  397.    }
  398. }
  399.