KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > common > VectorTools


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.syncclient.common;
20
21 import java.util.Vector JavaDoc;
22
23 public class VectorTools {
24
25     /**
26      * Adds all elements of the second vector to the first vector
27      * @param v1
28      * @param v2
29      */

30     public static void add(Vector JavaDoc v1, Vector JavaDoc v2) {
31         int numElements = v2.size();
32         for (int i=0; i<numElements; i++) {
33             v1.addElement(v2.elementAt(i));
34         }
35     }
36     
37     /**
38      * Adds all elements of the object array to the first vector
39      * @param v
40      * @param a
41      */

42     public static void add(Vector JavaDoc v, Object JavaDoc[] a) {
43         for (int i=0; i<a.length; i++) {
44             v.addElement(a[i]);
45         }
46     }
47     
48     /**
49      * Returns the content of the given vector as an array of String
50      *
51      * @param v the vector to convert - NULL = empty vector
52      *
53      * @return a String[] with the content of the vector
54      */

55     public static String JavaDoc[] toStringArray(Vector JavaDoc v) {
56         if (v == null) {
57             return new String JavaDoc[0];
58         }
59         
60         String JavaDoc[] ret = new String JavaDoc[v.size()];
61         
62         for (int i=0; i<ret.length; ++i) {
63             ret[i] = (String JavaDoc)v.elementAt(i);
64         }
65         
66         return ret;
67     }
68 }
Popular Tags