You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by gg...@apache.org on 2003/05/28 18:20:31 UTC
cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang ClassUtils.java
ggregory 2003/05/28 09:20:31
Modified: lang/src/java/org/apache/commons/lang ClassUtils.java
Log:
Create 'public static final' constants for the package separator and inner class separator characters/Strings.
Revision Changes Path
1.11 +28 -8 jakarta-commons/lang/src/java/org/apache/commons/lang/ClassUtils.java
Index: ClassUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/ClassUtils.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ClassUtils.java 9 Apr 2003 00:07:50 -0000 1.10
+++ ClassUtils.java 28 May 2003 16:20:31 -0000 1.11
@@ -57,16 +57,36 @@
import java.util.Iterator;
import java.util.List;
/**
- * <p><code>ClassUtils</code> contains utility methods for working for
- * classes without using reflection.</p>
+ * <p>Provides utility methods for working for classes without using reflection.</p>
*
* @author Stephen Colebourne
+ * @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
* @since 2.0
* @version $Id$
*/
public class ClassUtils {
/**
+ * The package separator character: <code>.</code>
+ */
+ public static final char PACKAGE_SEPARATOR_CHAR = '.';
+
+ /**
+ * The package separator String: <code>.</code>
+ */
+ public static final String PACKAGE_SEPARATOR = String.valueOf(PACKAGE_SEPARATOR_CHAR);
+
+ /**
+ * The inner class separator character: <code>$</code>
+ */
+ public static final char INNER_CLASS_SEPARATOR_CHAR = '$';
+
+ /**
+ * The inner class separator String: <code>$</code>
+ */
+ public static final String INNER_CLASS_SEPARATOR = String.valueOf(INNER_CLASS_SEPARATOR_CHAR);
+
+ /**
* <p>ClassUtils instances should NOT be constructed in standard programming.
* Instead, the class should be used as
* <code>ClassUtils.getShortClassName(cls)</code>.</p>
@@ -124,10 +144,10 @@
char[] chars = className.toCharArray();
int lastDot = 0;
for (int i = 0; i < chars.length; i++) {
- if (chars[i] == '.') {
+ if (chars[i] == PACKAGE_SEPARATOR_CHAR) {
lastDot = i + 1;
- } else if (chars[i] == '$') { // handle inner classes
- chars[i] = '.';
+ } else if (chars[i] == INNER_CLASS_SEPARATOR_CHAR) { // handle inner classes
+ chars[i] = PACKAGE_SEPARATOR_CHAR;
}
}
return new String(chars, lastDot, chars.length - lastDot);
@@ -177,7 +197,7 @@
if (StringUtils.isEmpty(className)) {
throw new IllegalArgumentException("The class name must not be empty");
}
- int i = className.lastIndexOf('.');
+ int i = className.lastIndexOf(PACKAGE_SEPARATOR_CHAR);
if (i == -1) {
return "";
}
@@ -500,7 +520,7 @@
if (cls == null) {
throw new IllegalArgumentException("The class must not be null");
}
- return (cls.getName().indexOf('$') >= 0);
+ return (cls.getName().indexOf(INNER_CLASS_SEPARATOR_CHAR) >= 0);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org