View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  package org.apache.jdo.util;
18  
19  /***
20   * Helper class providing string utility methods.
21   */
22  public class StringHelper {
23  
24      /***
25       * Checks if a string is null or empty.
26       * @param aString the string to be checked.
27       * @return <code>true</code> if the string is null or empty after trim,
28       *         <code>false</code> otherwise.
29       */
30      public static boolean isEmpty(String aString) {
31          return ((aString == null) || (aString.trim().length() == 0));
32      }
33  
34      /***
35       * Returns the package portion of the specified class
36       * @param className the name of the class from which to extract the package
37       * @return package portion of the specified class
38       */
39      public static String getPackageName(final String className) {
40          if (className != null) {
41              final int index = className.lastIndexOf('.');
42  
43              return ((index != -1) ? className.substring(0, index) : ""); // NOI18N
44          }
45  
46          return null;
47      }
48  
49      /***
50       * Returns the name of a class without the package name.  For example: if
51       * input = "java.lang.Object" , then output = "Object".
52       * @param fully qualified classname
53       * @return the unqualified classname 
54       */
55      public static String getShortClassName(final String className) {
56          if (className != null) {
57              final int index = className.lastIndexOf('.');
58  
59              return className.substring(index + 1);
60          }
61          return null;
62      }
63  }