KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > uitags > util > StringUtils


1 /**
2  * May 7, 2006
3  *
4  * Copyright 2004 uitags
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package net.sf.uitags.util;
19
20 public final class StringUtils {
21   private StringUtils() {
22     // Non-instantiable utility class
23
}
24   
25   /**
26    * Combines the string representation of the elements in the supplied array
27    * into one string. Each value is separated by a comma.
28    * If <code>elements</code> is <code>null</code>, returns an empty string.
29    *
30    * @param elements the array elements whose string representation is to be
31    * joined
32    * @return join result
33    */

34   public static String JavaDoc join(Object JavaDoc[] elements) {
35     if (elements == null) {
36       return "";
37     }
38     
39     StringBuffer JavaDoc joined = new StringBuffer JavaDoc();
40     
41     for (int i = 0; i < elements.length; i++) {
42       joined.append(elements[i]);
43       
44       if (i < (elements.length - 1)) {
45         joined.append(',');
46       }
47     }
48     
49     return joined.toString();
50   }
51
52   public static String JavaDoc toStringOrNull(Object JavaDoc value) {
53     if (value == null) {
54       return null;
55     }
56     return String.valueOf(value);
57   }
58 }
59
Popular Tags