View Javadoc

1   /*
2    * JarInspector - Copyright (C) 2004 Che Inc., Rosario Argentina
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Library General Public
6    * License as published by the Free Software Foundation; either
7    * version 2 of the License, or (at your option) any later version.
8    *
9    * This library 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 GNU
12   * Library General Public License for more details.
13   *
14   * You should have received a copy of the GNU Library General Public
15   * License along with this library; if not, write to the Free
16   * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17   */
18  
19  package inc.che.common.array;
20  
21  // Imports
22  
23  import org.apache.log4j.Logger;
24  
25  /***
26   *  <b>Urtilitymethoden fuer Arrays</b>
27   * @version $Id: ArrayUtil.java,v 1.1 2005/03/06 12:56:46 stevemcmee Exp $
28   * @author <address> Steve McMee &lt;stevemcmee@users.sourceforge.net&gt;</address>
29   */
30  
31  public final class ArrayUtil {
32  
33      /*** CVS ID of this file */
34      public static final String CVS_ID =
35          "$Id: ArrayUtil.java,v 1.1 2005/03/06 12:56:46 stevemcmee Exp $";
36  
37      /***
38       * logger instance for this class
39       */
40  
41      private static Logger log = Logger.getLogger(ArrayUtil.class);
42  
43      /*** the default separator */
44      public static final String SEP = ",";
45  
46      /***
47       * forbidden constructor
48       */
49      private ArrayUtil() {
50      }
51  
52      /***
53       * converts an object array into a comma-separated String
54       * @param array the object Array
55       * @param sep the separator
56       * @return comma separated String containing all elements
57       */
58      public static String toSeparatedString(Object[] array, String sep) {
59          if (log.isDebugEnabled()) {
60              log.debug("toSeparatedString(" + array + "," + sep + ")");
61          }
62          String erg = "(";
63          boolean first = true;
64          for (int i = 0; i < array.length; i++) {
65              erg = erg + (first ? "" : sep) + array[i];
66              first = false;
67          }
68          return erg + ")";
69      }
70  
71      /***
72       * converts an byte array into a comma-separated String
73       * @param array the byte Array
74       * @param sep the separator
75       * @return comma separated String containing all elements
76       */
77  
78      public static String toSeparatedString(byte[] array, String sep) {
79          if (log.isDebugEnabled()) {
80              log.debug("toSeparatedString(" + array + "," + sep + ")");
81          }
82  
83          Object[] objectArray = new Byte[array.length];
84          for (int i = 0; i < array.length; i++) {
85              objectArray[i] = new Byte(array[i]);
86          }
87          return toSeparatedString(objectArray, sep);
88      }
89  
90      /***
91       * converts an int array into a comma-separated String
92       * @param array the int Array
93       * @param sep the separator
94       * @return comma separated String containing all elements
95       */
96  
97      public static String toSeparatedString(int[] array, String sep) {
98          if (log.isDebugEnabled()) {
99              log.debug("toSeparatedString(" + array + ", " + sep + ")");
100         }
101 
102         Object[] objectArray = new Integer[array.length];
103         for (int i = 0; i < array.length; i++) {
104             objectArray[i] = new Integer(array[i]);
105         }
106         return toSeparatedString(objectArray, sep);
107     }
108     /***
109      * converts an short array into a comma-separated String
110      * @param array the short Array
111      * @param sep the separator
112      * @return comma separated String containing all elements
113      */
114 
115     public static String toSeparatedString(short[] array, String sep) {
116         if (log.isDebugEnabled()) {
117             log.debug("toSeparatedString(" + array + "," + sep + ")");
118         }
119 
120         Object[] objectArray = new Short[array.length];
121         for (int i = 0; i < array.length; i++) {
122             objectArray[i] = new Short(array[i]);
123         }
124         return toSeparatedString(objectArray, sep);
125     }
126 
127     /***
128      * converts an long array into a comma-separated String
129      * @param array the long Array
130      * @param sep the separator
131      * @return comma separated String containing all elements
132      */
133 
134     public static String toSeparatedString(long[] array, String sep) {
135         if (log.isDebugEnabled()) {
136             log.debug("toSeparatedString(" + array + "," + sep + ")");
137         }
138 
139         Object[] objectArray = new Long[array.length];
140         for (int i = 0; i < array.length; i++) {
141             objectArray[i] = new Long(array[i]);
142         }
143         return toSeparatedString(objectArray, sep);
144     }
145 
146     /***
147      * converts an float array into a comma-separated String
148      * @param array the float Array
149      * @param sep the separator
150      * @return comma separated String containing all elements
151      */
152 
153     public static String toSeparatedString(float[] array, String sep) {
154         if (log.isDebugEnabled()) {
155             log.debug("toSeparatedString(" + array + "," + sep + ")");
156         }
157 
158         Object[] objectArray = new Float[array.length];
159         for (int i = 0; i < array.length; i++) {
160             objectArray[i] = new Float(array[i]);
161         }
162         return toSeparatedString(objectArray, sep);
163     }
164 
165     /***
166      * converts an double array into a comma-separated String
167      * @param array the double Array
168      * @param sep the separator
169      * @return comma separated String containing all elements
170      */
171 
172     public static String toSeparatedString(double[] array, String sep) {
173         if (log.isDebugEnabled()) {
174             log.debug("toSeparatedString(" + array + "," + sep + ")");
175         }
176 
177         Object[] objectArray = new Double[array.length];
178         for (int i = 0; i < array.length; i++) {
179             objectArray[i] = new Double(array[i]);
180          }
181         return toSeparatedString(objectArray, sep);
182     }
183     /***
184      * converts an char array into a comma-separated String
185      * @param array the char Array
186      * @param sep the separator
187      * @return comma separated String containing all elements
188      */
189 
190     public static String toSeparatedString(char[] array, String sep) {
191         if (log.isDebugEnabled()) {
192             log.debug("toSeparatedString(" + array + "," + sep + ")");
193         }
194 
195         Object[] objectArray = new Character[array.length];
196         for (int i = 0; i < array.length; i++) {
197             objectArray[i] = new Character(array[i]);
198         }
199         return toSeparatedString(objectArray, sep);
200     }
201 
202     /***
203      * converts an object array into a comma-separated String
204      * @param array the object Array
205      * @return comma separated String containing all elements
206      */
207     public static String toSeparatedString(Object[] array) {
208         if (log.isDebugEnabled()) {
209             log.debug("toSeparatedString(" + array + ")");
210         }
211         return toSeparatedString(array, SEP);
212     }
213 
214     /***
215      * converts an byte array into a comma-separated String
216      * @param array the byte Array
217      * @return comma separated String containing all elements
218      */
219 
220     public static String toSeparatedString(byte[] array) {
221         if (log.isDebugEnabled()) {
222             log.debug("toSeparatedString(" + array + ")");
223         }
224 
225         Object[] objectArray = new Byte[array.length];
226         for (int i = 0; i < array.length; i++) {
227             objectArray[i] = new Byte(array[i]);
228         }
229         return toSeparatedString(objectArray, SEP);
230     }
231 
232     /***
233      * converts an int array into a comma-separated String
234      * @param array the int Array
235      * @return comma separated String containing all elements
236      */
237 
238     public static String toSeparatedString(int[] array) {
239         if (log.isDebugEnabled()) {
240             log.debug("toSeparatedString(" + array + ")");
241         }
242 
243         Object[] objectArray = new Integer[array.length];
244         for (int i = 0; i < array.length; i++) {
245             objectArray[i] = new Integer(array[i]);
246         }
247         return toSeparatedString(objectArray, SEP);
248     }
249     /***
250      * converts an short array into a comma-separated String
251      * @param array the short Array
252      * @return comma separated String containing all elements
253      */
254 
255     public static String toSeparatedString(short[] array) {
256         if (log.isDebugEnabled()) {
257             log.debug("toSeparatedString(" + array + ")");
258         }
259 
260         Object[] objectArray = new Short[array.length];
261         for (int i = 0; i < array.length; i++) {
262             objectArray[i] = new Short(array[i]);
263         }
264         return toSeparatedString(objectArray, SEP);
265     }
266 
267     /***
268      * converts an long array into a comma-separated String
269      * @param array the long Array
270      * @return comma separated String containing all elements
271      */
272 
273     public static String toSeparatedString(long[] array) {
274         if (log.isDebugEnabled()) {
275             log.debug("toSeparatedString(" + array + ")");
276         }
277 
278         Object[] objectArray = new Long[array.length];
279         for (int i = 0; i < array.length; i++) {
280             objectArray[i] = new Long(array[i]);
281         }
282         return toSeparatedString(objectArray, SEP);
283     }
284 
285     /***
286      * converts an float array into a comma-separated String
287      * @param array the float Array
288      * @return comma separated String containing all elements
289      */
290 
291     public static String toSeparatedString(float[] array) {
292         if (log.isDebugEnabled()) {
293             log.debug("toSeparatedString(" + array + ")");
294         }
295 
296         Object[] objectArray = new Float[array.length];
297         for (int i = 0; i < array.length; i++) {
298             objectArray[i] = new Float(array[i]);
299         }
300         return toSeparatedString(objectArray, SEP);
301     }
302 
303     /***
304      * converts an double array into a comma-separated String
305      * @param array the double Array
306      * @return comma separated String containing all elements
307      */
308 
309     public static String toSeparatedString(double[] array) {
310         if (log.isDebugEnabled()) {
311             log.debug("toSeparatedString(" + array + ")");
312         }
313 
314         Object[] objectArray = new Double[array.length];
315         for (int i = 0; i < array.length; i++) {
316             objectArray[i] = new Double(array[i]);
317          }
318         return toSeparatedString(objectArray, SEP);
319     }
320     /***
321      * converts an char array into a comma-separated String
322      * @param array the char Array
323      * @return comma separated String containing all elements
324      */
325 
326     public static String toSeparatedString(char[] array) {
327         if (log.isDebugEnabled()) {
328             log.debug("toSeparatedString(" + array + ")");
329         }
330 
331         Object[] objectArray = new Character[array.length];
332         for (int i = 0; i < array.length; i++) {
333             objectArray[i] = new Character(array[i]);
334         }
335         return toSeparatedString(objectArray, SEP);
336     }
337 }