Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: konspire/common/Vector.java


1   // Jason Rohrer
2   // Vector.java
3   
4   /**
5   *
6   *  Extends Java 1.1 Vector to provide some 1.2 functionality
7   *
8   *  Created 5-5-2000
9   *  Mods:
10  */
11  
12  
13  package konspire.common;
14  
15  //import java.util.Vector;
16  import java.util.Enumeration;
17  
18  
19  /**
20   * Extends Java 1.1 <code>Vector</code> to provide some 1.2 functionality.  
21   * <p>
22   * Will be replaced
23   * permanently by the 1.2 <code>Vector</code> implementation (or java.util.ArrayList) once
24   * every konspire target platform has access to Java 1.2.
25   *
26   *
27   * @author Jason Rohrer
28   */
29  public class Vector extends java.util.Vector {
30  
31  
32    public Vector() {
33      super();
34      }
35    
36    /**
37     * Constructs a <code>Vector</code> that starts with elements from a starting <code>java.util.Vector</code>.
38     *
39     * @param start starting point <code>Vector</code> for this new <code>Vector</code><br>
40     * constructed <code>Vector</code> will contain all elements from <code>start</code>
41     */ 
42    public Vector( java.util.Vector start ) {
43      super();
44      
45      addAll( start );
46      }
47    
48    
49    /**
50     * Constructs a <code>Vector</code> using standard <code>java.util.Vector</code> constructor
51     * parameters.
52     *
53     * @param startSize suggested starting capacity of <code>Vector</code>
54     */
55    public Vector( int startSize ) {
56      super( startSize );
57      }
58      
59    /**
60     * Adds all elements from a <code>java.util.Vector</code> to this <code>Vector</code>.
61     *
62     * @param v source <code>java.util.Vector</code> for all elements to be added
63     */
64    public synchronized boolean addAll( java.util.Vector v ) {
65      Enumeration e = v.elements();
66      
67      while( e.hasMoreElements() ) {
68        addElement( e.nextElement() );
69        }
70      return true;
71      }
72      
73    
74    /**
75     * Takes the intersection of this <code>Vector</code> with a <code>java.util.Vector</code>.
76     *
77     * @param v source <code>java.util.Vector</code> for all elements to be retained
78     *
79     * @return true iff this <code>Vector</code> changes as a result
80     */
81    public synchronized boolean retainAll( java.util.Vector v ) {
82      Enumeration e = elements();
83      
84      boolean returnVal = false;
85      
86      while( e.hasMoreElements() ) {
87        Object o = e.nextElement();
88        
89        // remove all elements not also contained in v
90        if( ! v.contains( o ) ) {
91          removeElement( o );
92          // restart enumeration after remove
93          // YUCK... but only safe way to do this with 1.1
94          // Enumeration no longer functions properly after the underlying
95          // class has been altered by the remove
96          e = elements();    
97          returnVal = true;  
98          }
99        }
100     return returnVal;  
101     }  
102 
103   /**
104    * Extracts elements from this <code>Vector</code> in the form of an array.
105    *
106    * @return array containing all elements from this <code>Vector</code>
107    */
108   public synchronized Object[] toArray() {
109     Object[] result = new Object[elementCount];
110     System.arraycopy(elementData, 0, result, 0, elementCount);
111     return result;
112     }
113   
114   }
115