Package org.aspectj.util
Class LangUtil
java.lang.Object
org.aspectj.util.LangUtil
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Handle an external process asynchrously.static class
check if input contains any packages to elide. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionSplitsinput
, removing delimiter and trimming any white space.static <T> List
<T> arrayAsList
(T[] array) Replacement for Arrays.asList(..) which gacks on null and returns a List in which remove is an unsupported operation.commaSplit
(String input) Splitsinput
at commas, trimming any white space.static String[][]
copyStrings
(String[][] in) copy non-null two-dimensional String[][]static String[]
extractOptions
(String[] args, String[][] options) Extract options and arguments to input option list, returning remainder.static boolean
getBoolean
(String propertyName, boolean defaultValue) Get System property as boolean, but use default value where the system property is not set.static File
Find java executable File path from java.home system property.static String
static String
static double
static String
static boolean
isEmpty
(byte[] ra) static boolean
static boolean
static boolean
isEmpty
(Collection<?> collection) static boolean
static boolean
isVMGreaterOrEqual
(double javaVersion) static boolean
isVMGreaterOrEqual
(int javaVersion) static boolean
isVMLessOrEqual
(double javaVersion) static boolean
isVMLessOrEqual
(int javaVersion) static String
makeClasspath
(String bootclasspath, String classpath, String classesDir, String outputJar) Gen classpath.static LangUtil.ProcessController
makeProcess
(LangUtil.ProcessController controller, String classpath, String mainClass, String[] args) Create or initialize a process controller to run a process in another VM asynchronously.static String
Renders exceptiont
after unwrapping and eliding any test packages.static String
renderException
(Throwable t, boolean elide) Renders exceptiont
, unwrapping, optionally eliding and limiting total number of lines.static String
static String
inefficient way to replace all instances of sought with replacestatic Object[]
Convert arrays safely.static <T> List
<T> static boolean
sleepUntil
(long time) Sleep until a particular time.static String[]
Splitstext
at whitespace.static String[]
splitClasspath
(String classpath) Split string as classpath, delimited at File.pathSeparator.static StringBuffer
stackToString
(Throwable throwable, boolean skipMessage) Dump message and stack to StringBuffer.Splits strings into aList
using aStringTokenizer
.static final void
throwIaxIfFalse
(boolean test, String message) Shorthand for "if false, throw IllegalArgumentException"static final void
throwIaxIfNotAssignable
(Object[] ra, Class<?> c, String name) Shorthand for "if not null or not assignable, throw IllegalArgumentException"static final void
throwIaxIfNotAssignable
(Object o, Class<?> c, String name) Shorthand for "if not null or not assignable, throw IllegalArgumentException"static final void
throwIaxIfNull
(Object o, String name) Shorthand for "if null, throw IllegalArgumentException"static String
toSizedString
(long i, int width) render i right-justified with a given width less than about 40static String
unqualifiedClassName
(Class<?> c) static String
static Throwable
-
Field Details
-
EOL
-
JRT_FS
- See Also:
-
-
Constructor Details
-
LangUtil
public LangUtil()
-
-
Method Details
-
getVmVersionString
- Returns:
- the vm version (1.1, 1.2, 1.3, 1.4, etc)
-
getVmVersion
public static double getVmVersion() -
isVMGreaterOrEqual
public static boolean isVMGreaterOrEqual(int javaVersion) -
isVMGreaterOrEqual
public static boolean isVMGreaterOrEqual(double javaVersion) -
isVMLessOrEqual
public static boolean isVMLessOrEqual(int javaVersion) -
isVMLessOrEqual
public static boolean isVMLessOrEqual(double javaVersion) -
throwIaxIfNull
Shorthand for "if null, throw IllegalArgumentException"- Throws:
IllegalArgumentException
- "null {name}" if o is null
-
throwIaxIfNotAssignable
Shorthand for "if not null or not assignable, throw IllegalArgumentException"- Parameters:
c
- the Class to check - use null to ignore type check- Throws:
IllegalArgumentException
- "null {name}" if o is null
-
throwIaxIfNotAssignable
Shorthand for "if not null or not assignable, throw IllegalArgumentException"- Throws:
IllegalArgumentException
- "null {name}" if o is null
-
throwIaxIfFalse
Shorthand for "if false, throw IllegalArgumentException"- Throws:
IllegalArgumentException
- "{message}" if test is false
-
isEmpty
- Returns:
- ((null == s) || (0 == s.length()));
-
isEmpty
- Returns:
- ((null == ra) || (0 == ra.length))
-
isEmpty
public static boolean isEmpty(byte[] ra) - Returns:
- ((null == ra) || (0 == ra.length))
-
isEmpty
- Returns:
- ((null == collection) || (0 == collection.size()))
-
isEmpty
- Returns:
- ((null == map) || (0 == map.size()))
-
split
Splitstext
at whitespace.- Parameters:
text
-String
to split.
-
commaSplit
Splitsinput
at commas, trimming any white space.- Parameters:
input
-String
to split.- Returns:
- List of String of elements.
-
splitClasspath
Split string as classpath, delimited at File.pathSeparator. Entries are not trimmed, but empty entries are ignored.- Parameters:
classpath
- the String to split - may be null or empty- Returns:
- String[] of classpath entries
-
getBoolean
Get System property as boolean, but use default value where the system property is not set.- Returns:
- true if value is set to true, false otherwise
-
anySplit
Splitsinput
, removing delimiter and trimming any white space. Returns an empty collection if the input is null. If delimiter is null or empty or if the input contains no delimiters, the input itself is returned after trimming white space.- Parameters:
input
-String
to split.delim
-String
separators for input.- Returns:
- List of String of elements.
-
strings
Splits strings into aList
using aStringTokenizer
.- Parameters:
text
-String
to split.
-
safeList
- Returns:
- a non-null unmodifiable List
-
copyStrings
copy non-null two-dimensional String[][]- See Also:
-
extractOptions
Extract options and arguments to input option list, returning remainder. The input options will be nullified if not found. e.g.,String[] options = new String[][] { new String[] { "-verbose" }, new String[] { "-classpath", null } }; String[] args = extractOptions(args, options); boolean verbose = null != options[0][0]; boolean classpath = options[1][1];
- Parameters:
args
- the String[] input optionsoptions
- the String[][]options to find in the input args - not null for each String[] component the first subcomponent is the option itself, and there is one String subcomponent for each additional argument.- Returns:
- String[] of args remaining after extracting options to extracted
-
safeCopy
Convert arrays safely. The number of elements in the result will be 1 smaller for each element that is null or not assignable. This will use sink if it has exactly the right size. The result will always have the same component type as sink.- Returns:
- an array with the same component type as sink containing any assignable elements in source (in the same order).
- Throws:
IllegalArgumentException
- if either is null
-
unqualifiedClassName
- Returns:
- a String with the unqualified class name of the class (or "null")
-
unqualifiedClassName
- Returns:
- a String with the unqualified class name of the object (or "null")
-
replace
inefficient way to replace all instances of sought with replace -
toSizedString
render i right-justified with a given width less than about 40 -
renderExceptionShort
- Returns:
- "({UnqualifiedExceptionClass}) {message}"
-
renderException
Renders exceptiont
after unwrapping and eliding any test packages.- Parameters:
t
-Throwable
to print.- See Also:
-
renderException
Renders exceptiont
, unwrapping, optionally eliding and limiting total number of lines.- Parameters:
t
-Throwable
to print.elide
- true to limit to 100 lines and elide test packages- See Also:
-
stackToString
Dump message and stack to StringBuffer. -
unwrapException
- Returns:
- Throwable input or tail of any wrapped exception chain
-
arrayAsList
Replacement for Arrays.asList(..) which gacks on null and returns a List in which remove is an unsupported operation.- Parameters:
array
- the Object[] to convert (may be null)- Returns:
- the List corresponding to array (never null)
-
makeClasspath
public static String makeClasspath(String bootclasspath, String classpath, String classesDir, String outputJar) Gen classpath.- Parameters:
bootclasspath
-classpath
-classesDir
-outputJar
-- Returns:
- String combining classpath elements
-
makeProcess
public static LangUtil.ProcessController makeProcess(LangUtil.ProcessController controller, String classpath, String mainClass, String[] args) Create or initialize a process controller to run a process in another VM asynchronously.- Parameters:
controller
- the ProcessController to initialize, if not nullclasspath
-mainClass
-args
-- Returns:
- initialized ProcessController
-
getJavaExecutable
Find java executable File path from java.home system property.- Returns:
- File associated with the java command, or null if not found.
-
sleepUntil
public static boolean sleepUntil(long time) Sleep until a particular time.- Parameters:
time
- the long time in milliseconds to sleep until- Returns:
- true if delay succeeded, false if interrupted 100 times
-
getJrtFsFilePath
-
getJavaHome
-