KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > launcher > StringList


1 /*====================================================================
2
3 ObjectWeb Util Launcher Package.
4 Copyright (C) 2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Romain Rouvoy.
23 Contributor(s): .
24
25 --------------------------------------------------------------------
26 $Id: StringList.java,v 1.1 2004/05/19 15:58:29 rouvoy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.launcher ;
30
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.Arrays JavaDoc;
34 import java.util.Collection JavaDoc;
35
36
37 /**
38  * Dynamic list of strings.<BR>
39  * <p>
40  * this structure considers only characters list.
41  * </p>
42  *
43  * @author <a HREF="mailto:Romain.Rouvoy@lifl.fr">Romain Rouvoy</a>
44  *
45  * @version 0.1
46  */

47 public class StringList
48      extends ArrayList JavaDoc
49 {
50     /**
51      * Default Constructor
52      *
53      */

54     public StringList() {
55         super();
56     }
57     
58     /**
59      * Constructor based on static String array.
60      * @param str the array to convert.
61      */

62     public StringList(String JavaDoc[] str) {
63         super(Arrays.asList(str));
64     }
65     
66     /**
67      * Adds a new string at the end of the list
68      *
69      * @param value - the new element to add
70      */

71     public void add(String JavaDoc value) {
72         if (!value.trim().equals(""))
73             add((Object JavaDoc)value);
74     }
75
76     /**
77      * Adds the content of a StringList at the end of the current list
78      *
79      * @param value - the elements to add
80      */

81     public void addAll(StringList value) {
82         addAll((Collection JavaDoc)value);
83     }
84
85     /**
86      * Converts the current list to a static String[] object
87      *
88      * @return a static array containing all the values of the current list
89      */

90     public String JavaDoc[] toStringArray() {
91         return (String JavaDoc[]) toArray(new String JavaDoc[0]);
92     }
93
94
95     /**
96      * Provides a string representation of the list
97      *
98      * @return a string representation
99      */

100     public String JavaDoc toString() {
101         java.util.Iterator JavaDoc iter = super.iterator();
102         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
103         result.append("[");
104         while (iter.hasNext()) {
105           String JavaDoc value = (String JavaDoc) iter.next() ;
106           result.append(value);
107           if (iter.hasNext()) result.append(", ");
108         }
109         result.append("]");
110         return result.toString();
111     }
112
113     /**
114      * Returns true if the two lists contain the same string values
115      *
116      * @param obj - the value to compare
117      *
118      * @return true if the list have the same content
119      */

120     public boolean equals(Object JavaDoc obj) {
121         if (obj instanceof StringList) {
122             StringList list = (StringList) obj;
123             return super.equals(obj);
124         }
125         return false ;
126     }
127 }
Popular Tags