You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mb...@apache.org on 2005/05/27 19:14:28 UTC

svn commit: r178800 - /incubator/jdo/trunk/core20/src/java/org/apache/jdo/util/StringHelper.java

Author: mbo
Date: Fri May 27 10:14:27 2005
New Revision: 178800

URL: http://svn.apache.org/viewcvs?rev=178800&view=rev
Log:
Checkin missing StringHelper class for core20 project

Added:
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/util/StringHelper.java

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/util/StringHelper.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/util/StringHelper.java?rev=178800&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/util/StringHelper.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/util/StringHelper.java Fri May 27 10:14:27 2005
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+package org.apache.jdo.util;
+
+/**
+ * Helper class providing string utility methods.
+ */
+public class StringHelper {
+
+    /**
+     * Checks if a string is null or empty.
+     * @param aString the string to be checked.
+     * @return <code>true</code> if the string is null or empty after trim,
+     *         <code>false</code> otherwise.
+     */
+    public static boolean isEmpty(String aString) {
+        return ((aString == null) || (aString.trim().length() == 0));
+    }
+
+    /**
+     * Returns the package portion of the specified class
+     * @param className the name of the class from which to extract the package
+     * @return package portion of the specified class
+     */
+    public static String getPackageName(final String className) {
+        if (className != null) {
+            final int index = className.lastIndexOf('.');
+
+            return ((index != -1) ? className.substring(0, index) : ""); // NOI18N
+        }
+
+        return null;
+    }
+
+    /**
+     * Returns the name of a class without the package name.  For example: if
+     * input = "java.lang.Object" , then output = "Object".
+     * @param fully qualified classname
+     * @return the unqualified classname 
+     */
+    public static String getShortClassName(final String className) {
+        if (className != null) {
+            final int index = className.lastIndexOf('.');
+
+            return className.substring(index + 1);
+        }
+        return null;
+    }
+}