View Javadoc

1   /**
2    * 
3    */
4   package net.sf.statcvs.util;
5   
6   import java.util.ArrayList;
7   import java.util.Collections;
8   import java.util.List;
9   import java.util.StringTokenizer;
10  
11  /**
12   * @author xhensevalb
13   *
14   */
15  public final class StringUtils {
16      private StringUtils() {
17      }
18  
19      /**
20       * @return true if txt !=null and not empty.
21       */
22      public static boolean isNotEmpty(final String txt) {
23          return txt != null && txt.trim().length() > 0;
24      }
25  
26      /**
27       * helper method to convert a 'delimiter' separated string to a list.
28       * 
29       * @param str
30       *            the 'delimiter' separated string
31       * @param delimiter
32       *            typically a ','
33       * @return a list
34       */
35      public static List listify(final String str, final String delimiter) {
36          if (str == null) {
37              return Collections.EMPTY_LIST;
38          }
39  
40          final StringTokenizer tok = new StringTokenizer(str, delimiter);
41          final List list = new ArrayList();
42  
43          while (tok.hasMoreElements()) {
44              list.add(StringUtils.trim(tok.nextToken()));
45          }
46  
47          return list;
48      }
49  
50      public static String trim(String tok) {
51          return tok != null ? tok.trim() : null;
52      }
53  
54  }