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

Quick Search    Search Deep

Source code: com/flexstor/common/util/FlexVector.java


1   /*
2    * FlexVector.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:30 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.common.util;
12  
13  import java.util.Vector;
14  
15  /*****************************************************
16   * This class is merely a class as an interface between
17   * java.util.vector and potentially derived classes. As of now,
18   * FlexVector does not implement any methods.
19   * @Version: 1.0
20   * @Author: Raimund Dettmer
21   * @see java.util.vector
22   ******************************************************/
23  public class FlexVector extends java.util.Vector
24  {
25     /**
26      * Constructor documentation identical to java.util.vector
27      * @see java.util.vector
28      */
29     public FlexVector()
30     {
31        super();
32     }
33     public FlexVector(int initialCapacity)
34     {
35        super(initialCapacity);
36     }
37     public FlexVector(int initialCapacity, int capacityIncrement)
38     {
39        super(initialCapacity, capacityIncrement);
40     }
41     
42     public void addElements(Object[] obj)
43     {
44        int x = 0;
45        if(obj != null)
46        {
47           for(x = 0; x < obj.length; x++)
48           {
49              this.addElement(obj[x]);
50           }
51        }
52        
53     }
54     
55     public void setElements(Object[] obj)
56     {
57          removeAllElements();
58          addElements(obj);
59     }
60     
61     
62     /**
63     * Adds the elements of a Vector
64     * as Elements to this Vector 
65     * (as opposed to adding the entire vector as one element
66     **/
67     public void addVector(Vector vect)
68     {
69        for(int x = 0; x < vect.size(); x++)
70        {
71           addElement(vect.elementAt(x));
72        }
73     }
74     
75     /**
76     * toStringArray
77     * Uses copyInto to copy items into a String array all items are copied
78     * @return String array of elements in the vector
79     **/
80     public final String[] toStringArray()
81     {
82        String[] s;
83        s = new String[this.size()];
84        for(int x = 0; x < s.length; x++)
85           s[x] = this.elementAt(x).toString();
86        //this.copyInto(s);
87        return s;
88     }
89    /**
90    * toStringArray
91    * @param filter whether or not to filter nulls
92    * so they won't be returned in the string array
93    **/
94    public final String[] toStringArray(boolean filter) 
95    {
96      
97      if(!filter)
98      {
99       return this.toStringArray();
100    }
101    
102    String[] anArray = null;
103    if(elementCount > 0)
104    {
105       int i = elementCount, nGood = 0;
106       // find out how many valid (non-null) elements there are
107       while (i-- > 0)
108       {
109          if(elementData[i] != null)
110            nGood++;
111       }
112       
113       anArray = new String[nGood];
114       i = elementCount;
115       while (i-- > 0) 
116       {
117         if(elementData[i] != null)
118            anArray[--nGood] = elementData[i].toString();
119       }
120     }
121     
122     return anArray;
123   }
124   
125 }
126