View Javadoc

1   /*
2    * $Id: StringUtils.java,v 1.1 2004/12/15 14:18:20 patforna Exp $
3    *
4    * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
5    * Berne University of Applied Sciences
6    * School of Engineering and Information Technology
7    * All rights reserved.
8    */
9   package bexee.util;
10  
11  /***
12   * Utility class for String values.
13   * 
14   * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:20 $
15   * @author Pawel Kowalski
16   */
17  public class StringUtils {
18  
19      /***
20       * The separator used for splitting.
21       */
22      private static final String separator = ":";
23  
24      /***
25       * Test whether a given String is null or empty.
26       * 
27       * @param stringToTest
28       * @return boolean
29       */
30      public static boolean isNullOrEmpty(String stringToTest) {
31          return (stringToTest == null || stringToTest.equals(""));
32      }
33  
34      /***
35       * Split a String using the ":" separator. A null or empty String will
36       * result in a String array containing two empty Strings. A unseparable
37       * String (without the separator) will result in a String array with the
38       * values: {"", value}.
39       * 
40       * @param string
41       * @return String[] with splitted Strings
42       */
43      public static String[] split(String string) {
44          if (isNullOrEmpty(string)) {
45              return new String[] { "", "" };
46          } else if (string.indexOf(separator) == -1) {
47              return new String[] { "", string };
48          }
49          return org.apache.commons.lang.StringUtils.split(string, separator);
50  
51      }
52  
53  }