From: wisberg Date: Thu, 1 May 2003 13:15:39 +0000 (+0000) Subject: - permit empty input to split X-Git-Tag: V1_1_0_RC2~98 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c562ca65e19051e7d12d8db63d49f13445b12e87;p=aspectj.git - permit empty input to split - split classpath - check for array arguments --- 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; @@ -92,6 +93,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 @@ -172,6 +194,27 @@ public class LangUtil { return anySplit(input, ","); } + /** + * 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 input, removing delimiter and * trimming any white space. @@ -210,6 +253,9 @@ public class LangUtil { * @param text String 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()) {