1 /************************************************************
2 * Copyright *
3 * Portions of this software are Copyright (c) 1993 - 2002, *
4 * Chad Z. Hower (Kudzu) and the Indy Pit Crew *
5 * - http://www.nevrona.com/Indy/ *
6 ************************************************************/
7 package org.indy.util;
8
9 import java.io.BufferedReader;
10 import java.io.IOException;
11 import java.io.StringReader;
12
13 import java.util.ArrayList;
14
15
16 /***
17 * This class IS NOT thread safe.
18 *
19 *@author owen
20 */
21 public final class StringList {
22 private ArrayList stringList = new ArrayList();
23
24 /***
25 * Sets the text attribute of the IdStrings object
26 *
27 *@param data The new text value
28 */
29 public void setText(String data) {
30 stringList.clear();
31
32 BufferedReader read = new BufferedReader(new StringReader(data));
33
34 String line = null;
35
36 try {
37 while ((line = read.readLine()) != null) {
38 stringList.add(line);
39 }
40 }
41 catch (IOException ioe) {
42 ioe.printStackTrace();
43 }
44 }
45
46 /***
47 * Gets the text attribute of the IdStrings object
48 *
49 *@return The text value
50 */
51 public String getText() {
52 StringBuffer sb = new StringBuffer();
53
54 for (int i = 0, n = stringList.size(); i < n; i++) {
55 sb.append(stringList.get(i));
56 sb.append("\n");
57 }
58
59 return sb.toString();
60 }
61
62 /***
63 * Description of the Method
64 *
65 *@param index Description of the Parameter
66 *@return Description of the Return Value
67 */
68 public String get(int index) {
69 if ((index < 0) || (index > stringList.size())) {
70 throw new IndexOutOfBoundsException();
71 }
72
73 return (String) stringList.get(index);
74 }
75
76 /***
77 * Description of the Method
78 *
79 *@param strings Description of the Parameter
80 */
81 public void copy(StringList strings) {
82 stringList = (ArrayList) strings.stringList.clone();
83 }
84
85 /***
86 * Description of the Method
87 *
88 *@return Description of the Return Value
89 */
90 public int size() {
91 return stringList.size();
92 }
93
94 /***
95 * Description of the Method
96 *
97 *@param s Description of the Parameter
98 *@return Description of the Return Value
99 */
100 public int add(String s) {
101 stringList.add(s);
102
103 return stringList.indexOf(s);
104 }
105
106 /***
107 * Description of the Method
108 *
109 *@param s Description of the Parameter
110 */
111 public void append(String s) {
112 stringList.add(s);
113 }
114
115 /***
116 * Adds a feature to the Strings attribute of the IdStrings object
117 *
118 *@param strings The feature to be added to the Strings attribute
119 */
120 public void addStrings(StringList strings) {
121 stringList.addAll(strings.stringList);
122 }
123
124 /***
125 * Description of the Method
126 */
127 public void clear() {
128 stringList.clear();
129 }
130
131 /***
132 * Description of the Method
133 *
134 *@param s Description of the Parameter
135 *@param index Description of the Parameter
136 */
137 public void replace(String s, int index) {
138 if ((index < 0) || (index > stringList.size())) {
139 throw new IndexOutOfBoundsException();
140 }
141
142 stringList.set(index, s);
143 }
144
145 /***
146 * Description of the Method
147 *
148 *@param index Description of the Parameter
149 */
150 public void remove(int index) {
151 if ((index < 0) || (index > stringList.size())) {
152 throw new IndexOutOfBoundsException();
153 }
154
155 stringList.remove(index);
156 }
157
158 /***
159 * Description of the Method
160 *
161 *@param s Description of the Parameter
162 */
163 public void remove(String s) {
164 stringList.remove(s);
165 }
166
167 /***
168 * Description of the Method
169 *
170 *@param s Description of the Parameter
171 *@return Description of the Return Value
172 */
173 public int indexOf(String s) {
174 return stringList.indexOf(s);
175 }
176
177 /***
178 * Description of the Method
179 *
180 *@param s Description of the Parameter
181 *@param index Description of the Parameter
182 */
183 public void insert(String s, int index) {
184 if ((index < 0) || (index > stringList.size())) {
185 throw new IndexOutOfBoundsException();
186 }
187
188 stringList.add(index, s);
189 }
190 }
This page was automatically generated by Maven