diff options
author | wisberg <wisberg> | 2003-05-01 13:15:39 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2003-05-01 13:15:39 +0000 |
commit | c562ca65e19051e7d12d8db63d49f13445b12e87 (patch) | |
tree | 94426a4f8ec3be94026134f48f9152e3cf03db48 /util | |
parent | 2a0ce5da6e2839e21345f9cff3327038e40408db (diff) | |
download | aspectj-c562ca65e19051e7d12d8db63d49f13445b12e87.tar.gz aspectj-c562ca65e19051e7d12d8db63d49f13445b12e87.zip |
- permit empty input to split
- split classpath
- check for array arguments
Diffstat (limited to 'util')
-rw-r--r-- | util/src/org/aspectj/util/LangUtil.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/util/src/org/aspectj/util/LangUtil.java b/util/src/org/aspectj/util/LangUtil.java index 3dc5a2f9d..6e40f6ec4 100644 --- a/util/src/org/aspectj/util/LangUtil.java +++ b/util/src/org/aspectj/util/LangUtil.java @@ -14,6 +14,7 @@ package org.aspectj.util; +import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; @@ -94,6 +95,27 @@ public class LangUtil { /** * Shorthand for "if not null or not assignable, throw IllegalArgumentException" + * @param c the Class to check - use null to ignore type check + * @throws IllegalArgumentException "null {name}" if o is null + */ + public static final void throwIaxIfNotAssignable(final Object ra[], final Class c, final String name) { + throwIaxIfNull(ra, name); + String label = (null == name ? "input" : name); + for (int i = 0; i < ra.length; i++) { + if (null == ra[i]) { + String m = " null " + label + "[" + i + "]"; + throw new IllegalArgumentException(m); + } else if (null != c) { + Class actualClass = ra[i].getClass(); + if (!c.isAssignableFrom(actualClass)) { + String message = label + " not assignable to " + c.getName(); + throw new IllegalArgumentException(message); + } + } + } + } + /** + * Shorthand for "if not null or not assignable, throw IllegalArgumentException" * @throws IllegalArgumentException "null {name}" if o is null */ public static final void throwIaxIfNotAssignable(final Object o, final Class c, final String name) { @@ -173,6 +195,27 @@ public class LangUtil { } /** + * Split string as classpath, delimited at File.pathSeparator. + * Entries are not trimmed, but empty entries are ignored. + * @param classpath the String to split - may be null or empty + * @return String[] of classpath entries + */ + public static String[] splitClasspath(String classpath) { + if (LangUtil.isEmpty(classpath)) { + return new String[0]; + } + StringTokenizer st = new StringTokenizer(classpath, File.pathSeparator); + ArrayList result = new ArrayList(st.countTokens()); + while (st.hasMoreTokens()) { + String entry = st.nextToken(); + if (!LangUtil.isEmpty(entry)) { + result.add(entry); + } + } + return (String[]) result.toArray(new String[0]); + } + + /** * Splits <code>input</code>, removing delimiter and * trimming any white space. * Returns an empty collection if the input is null. @@ -210,6 +253,9 @@ public class LangUtil { * @param text <code>String</code> to split. */ public static List strings(String text) { + if (LangUtil.isEmpty(text)) { + return Collections.EMPTY_LIST; + } List strings = new ArrayList(); StringTokenizer tok = new StringTokenizer(text); while (tok.hasMoreTokens()) { |