1
2
3
4
5
6
7
8
9
10
11
12
13
14
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) : "");
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 }