|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ashridgetech.jamda.common.Util
Utility methods used by various classes.
Field Summary | |
static java.lang.Object[] |
EMPTY_ARRAY
|
static java.lang.Class[] |
EMPTY_CLASS_ARRAY
|
static java.lang.String[] |
EMPTY_STRING_ARRAY
|
static java.util.regex.Pattern |
NAME_PATTERN
A Pattern which finds '.' , '/', '\' so
it can be used for splitting file or package names. |
static java.util.regex.Pattern |
SPACE_PATTERN
A Pattern which finds whitespace so
it can be used for splitting space-separated lists of tokens. |
Method Summary | |
static java.lang.String |
blankToNull(java.lang.String s)
Change a null or blank String to null. |
static java.lang.Object |
callStaticMethod(java.lang.Class clazz,
java.lang.String name)
Get the value of a static method of a Class with no arguments. |
static java.lang.String |
capitalize(java.lang.String s)
Get a String with the first character converted to upper case. |
static void |
checkArg(boolean b,
java.lang.String message)
|
static void |
checkNotEmpty(java.lang.String s,
java.lang.String name)
|
static void |
checkNotNull(java.lang.Object o,
java.lang.String name)
|
static void |
checkNull(java.lang.Object o,
java.lang.String name)
|
static void |
checkState(boolean b,
java.lang.String message)
|
static java.util.List |
concat(java.util.Collection c1,
java.util.Collection c2)
Concatenate two Collection s, in their natural order
of iteration, into a single result List . |
static java.lang.String |
encode(java.lang.String s)
Encode a String in the manner needed for a Java source string
literal, replacing characters with escape codes as needed. |
static java.lang.reflect.Constructor |
findConstructor(java.lang.Class clazz,
java.lang.Class argType)
Find a public constructor with a given single argument type in a class. |
static java.lang.reflect.Constructor |
findConstructor(java.lang.Class clazz,
java.lang.Class[] argTypes)
Find a public constructor with a given argument list in a class. |
static java.lang.Object |
getFirstElement(java.util.Collection c)
Get the first element of a collection. |
static java.lang.Class[] |
getTypes(java.lang.Object[] objects)
Get the types of an array of objects. |
static boolean |
isBlank(java.lang.String s)
Test whether a String is null or empty or all whitespace. |
static java.lang.String |
localizePath(java.lang.String path)
Localize a path name by replacing both '\' and '/' with the local File.separatorChar . |
static void |
mkdirs(java.io.File dir)
Check for the existence of a directory and create it if necessary, including any non-existent parent directories. |
static java.lang.String |
naturalize(java.lang.String s)
Get a String from a camel case name with
spaces between each word,
and underscores replaced by spaces. |
static java.lang.Object |
newInstance(java.lang.Class clazz)
Create an object of a class with no constructor argument. |
static java.lang.Object |
newInstance(java.lang.Class clazz,
java.lang.Object arg)
Create an object of a class with a given single constructor argument. |
static java.lang.Object |
newInstance(java.lang.Class clazz,
java.lang.Object[] args)
Create an object of a class with a given set of arguments. |
static java.lang.Object |
newInstance(java.lang.String className)
Create an object of a named class with no constructor argument. |
static java.lang.Object |
newInstance(java.lang.String className,
java.lang.Object arg)
Create an object of a class with a given single constructor argument. |
static java.lang.Object |
newInstance(java.lang.String className,
java.lang.Object[] args)
Create an object of a named class with a given set of arguments. |
static java.lang.String |
nullToBlank(java.lang.String s)
Change a null or blank String to an empty String . |
static java.lang.String |
packageName(java.lang.String className)
Get the package out of a fully qualified class name. |
static java.lang.String |
pluralize(java.lang.String word)
Get a String word made plural (in English). |
static java.lang.String |
quote(java.lang.String s)
Put double quotes around a string, and encode it. |
static java.lang.String |
readFile(java.lang.String fileName)
Read from a named file into a String . |
static java.lang.String |
readReader(java.io.Reader rdr)
Read from a Reader into a String . |
static void |
readToPosition(java.io.BufferedReader rdr,
int line,
int col)
Read from the current position in a Reader to a given
relative line and column. |
static java.util.List |
select(java.util.Collection inputColl,
org.apache.commons.collections.Predicate predicate)
Select from a Collection into a new List using a Predicate . |
static java.lang.String[] |
splitAtSpace(java.lang.String s)
Split a string at spaces. |
static java.lang.String[] |
splitName(java.lang.String name)
Split a string at periods or file separators. |
static java.lang.String |
toString(java.util.Collection c)
|
static java.util.List |
transform(java.util.Collection inputColl,
org.apache.commons.collections.Transformer transformer)
Transform a List into a new List using a Transformer . |
static java.lang.String |
uncapitalize(java.lang.String s)
Get a String with the first character converted to lower case. |
static java.lang.String |
unqualifiedClassName(java.lang.String className)
Get the name of a class, without its package or containing class. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.Object[] EMPTY_ARRAY
public static final java.lang.String[] EMPTY_STRING_ARRAY
public static final java.lang.Class[] EMPTY_CLASS_ARRAY
public static final java.util.regex.Pattern NAME_PATTERN
Pattern
which finds '.' , '/', '\' so
it can be used for splitting file or package names.
public static final java.util.regex.Pattern SPACE_PATTERN
Pattern
which finds whitespace so
it can be used for splitting space-separated lists of tokens.
Method Detail |
public static void checkNotNull(java.lang.Object o, java.lang.String name)
public static void checkNotEmpty(java.lang.String s, java.lang.String name)
public static void checkNull(java.lang.Object o, java.lang.String name)
public static void checkArg(boolean b, java.lang.String message)
public static void checkState(boolean b, java.lang.String message)
public static java.lang.String toString(java.util.Collection c)
public static java.lang.Object getFirstElement(java.util.Collection c)
c
- the collection from whcih to get the first element
c
is emptypublic static java.lang.String uncapitalize(java.lang.String s)
String
with the first character converted to lower case.
s
- the String
to convert
String
public static java.lang.String capitalize(java.lang.String s)
String
with the first character converted to upper case.
s
- the String
to convert
String
public static java.lang.String pluralize(java.lang.String word)
String
word made plural (in English). Only the
basic rules for English plurals are applied.
word
- the word to convert
public static java.lang.String naturalize(java.lang.String s)
String
from a camel case name with
spaces between each word,
and underscores replaced by spaces.
For example "customerStartDate" and "CUSTOMER_START_DATE"
would both become "Customer Start Date".
s
- the String
to convert
String
public static boolean isBlank(java.lang.String s)
String
is null or empty or all whitespace.
s
- the String
to test
s
is either null or its length,
trimmed of whitespace, is zeropublic static java.lang.String blankToNull(java.lang.String s)
String
to null.
s
- the String
to test
s
is either null or its length,
trimmed of whitespace, is zero, otherwise the original String
isBlank(java.lang.String)
public static java.lang.String nullToBlank(java.lang.String s)
String
to an empty String
.
s
- the String
to test
String
if s
is either null or its length,
trimmed of whitespace, is zero, otherwise the original String
#blankToNull
public static java.lang.String packageName(java.lang.String className)
className
does not contain a "." then it is
returned unchanged.
className
- the qualified name
public static java.lang.String unqualifiedClassName(java.lang.String className)
className
does not contain a "." then it is
returned unchanged.
className
- the qualified name
public static java.lang.String[] splitName(java.lang.String name)
name
If the trimmed name
starts with a separator, the first
element of the array will be an empty string.
Uses NAME_PATTERN
.
name
- the name to split
name
is null or empty
(as returned by isBlank(java.lang.String)
, an empty array is returnedpublic static java.lang.String[] splitAtSpace(java.lang.String s)
s
s
- the String
to split
name
is null or empty
(as returned by isBlank(java.lang.String)
, an empty array is returnedpublic static java.lang.String localizePath(java.lang.String path)
File.separatorChar
.
path
- the name to split
public static java.lang.reflect.Constructor findConstructor(java.lang.Class clazz, java.lang.Class[] argTypes)
clazz
- the Class
in which to look for the constructorargTypes
- the argument types of the required constructor
public static java.lang.reflect.Constructor findConstructor(java.lang.Class clazz, java.lang.Class argType)
clazz
- the Class
in which to look for the constructorargType
- the argument type of the required constructor
public static java.lang.Class[] getTypes(java.lang.Object[] objects)
objects
- the Objects
of whcih the types are required
public static java.lang.Object newInstance(java.lang.Class clazz, java.lang.Object[] args) throws java.lang.Exception
InvocationTargetException
.
clazz
- the Class
of object to createargs
- the arguments
java.lang.Exception
- if an exception occurs calling the constructor of the object.
java.lang.IllegalArgumentException
- if there is no constructor
which can accept the given argumentspublic static java.lang.Object newInstance(java.lang.String className, java.lang.Object[] args) throws java.lang.Exception
className
- the name of the Class
of object to createargs
- the arguments
java.lang.Exception
newInstance( Class , Object[] )
public static java.lang.Object newInstance(java.lang.Class clazz) throws java.lang.Exception
newInstance( Class , Object[] )
for details
clazz
- the Class
of object to create
java.lang.Exception
newInstance( Class , Object[] )
public static java.lang.Object newInstance(java.lang.String className) throws java.lang.Exception
newInstance( Class , Object[] )
for details
className
- the name of the Class
of object to create
java.lang.Exception
newInstance( Class , Object[] )
public static java.lang.Object newInstance(java.lang.Class clazz, java.lang.Object arg) throws java.lang.Exception
newInstance( Class , Object[] )
for details
clazz
- the Class
of object to createarg
- the argument
java.lang.Exception
newInstance( Class , Object[] )
public static java.lang.Object newInstance(java.lang.String className, java.lang.Object arg) throws java.lang.Exception
newInstance( Class , Object[] )
for details
className
- the name of the Class
of object to createarg
- the argument
java.lang.Exception
newInstance( Class , Object[] )
public static java.lang.Object callStaticMethod(java.lang.Class clazz, java.lang.String name) throws java.lang.Exception
Class
with no arguments.
If an exception is thrown, that exception is thrown,
rather than, InvocationTargetException
.
clazz
- the Class
of object on which the method is calledname
- the name of the method to be called - must have no arguments
java.lang.Exception
- if an exception occurs while making the call.
java.lang.IllegalArgumentException
- if there is no method with the given name
with zero argumentspublic static void mkdirs(java.io.File dir) throws java.io.IOException
dir
- the directory to be created
java.io.IOException
- if the directory cannot be createdpublic static java.util.List concat(java.util.Collection c1, java.util.Collection c2)
Collection
s, in their natural order
of iteration, into a single result List
.
c1
- the first Collection
c2
- the second Collection
List
public static java.util.List transform(java.util.Collection inputColl, org.apache.commons.collections.Transformer transformer)
List
into a new List
using a Transformer
.
inputColl
- the Collection
to be transformed - this is not modifiedtransformer
- the Transformer
to apply
List
resulting from applying transformer
to each element of inputColl
.public static java.util.List select(java.util.Collection inputColl, org.apache.commons.collections.Predicate predicate)
Collection
into a new List
using a Predicate
.
inputColl
- the Collection
to be transformed - this is not modifiedpredicate
- the Predicate
to apply
List
resulting from selecting elements of
inputColl
for which predicate
is true.public static java.lang.String readReader(java.io.Reader rdr) throws java.io.IOException
Reader
into a String
.
rdr
- the Reader
from which to read
rdr
java.io.IOException
public static java.lang.String readFile(java.lang.String fileName) throws java.io.IOException
String
.
fileName
- the name of the file from which to read
fileName
java.io.IOException
public static void readToPosition(java.io.BufferedReader rdr, int line, int col) throws java.io.IOException
Reader
to a given
relative line and column. If line
is 1, the method will only work
correctly if the current position is at the start of the line.
rdr
- the reader from which to readline
- the line to move to
java.io.IOException
- if there is a problem reading from rdr
public static java.lang.String quote(java.lang.String s)
s
- the String
to quote
String
encode(java.lang.String)
public static java.lang.String encode(java.lang.String s)
String
in the manner needed for a Java source string
literal, replacing characters with escape codes as needed.
s
- the String
to encode
String
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |