|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ashridgetech.prevdb.common.Util
Utility methods used by various classes.
Field Summary | |
static Object[] |
EMPTY_ARRAY
|
static Class[] |
EMPTY_CLASS_ARRAY
|
static String[] |
EMPTY_STRING_ARRAY
|
static Pattern |
NAME_PATTERN
A Pattern which finds '.' , '/', '\' so
it can be used for splitting file or package names. |
static Pattern |
SPACE_PATTERN
A Pattern which finds whitespace so
it can be used for splitting space-separated lists of tokens. |
Method Summary | |
static String |
blankToNull(String s)
Change a null or blank String to null. |
static Object |
callStaticMethod(Class clazz,
String name)
Get the value of a static method of a Class with no arguments. |
static String |
capitalize(String s)
Get a String with the first character converted to upper case. |
static void |
checkArg(boolean b,
String message)
|
static void |
checkNotEmpty(String s,
String name)
|
static void |
checkNotNull(Object o,
String name)
|
static void |
checkNull(Object o,
String name)
|
static void |
checkState(boolean b,
String message)
|
static List |
concat(Collection c1,
Collection c2)
Concatenate two Collection s, in their natural order
of iteration, into a single result List . |
static String |
encode(String s)
Encode a String in the manner needed for a Java source string
literal, replacing characters with escape codes as needed. |
static Class |
findClass(String className)
Find a public class by name. |
static Constructor |
findConstructor(Class clazz,
Class argType)
Find a public constructor with a given single argument type in a class. |
static Constructor |
findConstructor(Class clazz,
Class[] argTypes)
Find a constructor with parameter types that are assignable from the given argTypes ,
not necessarily exact matches, as found by Class.getConstructor(java.lang.Class[]) . |
static Constructor |
findExactConstructor(Class clazz,
Class[] argTypes)
Find a public constructor with a given argument list in a class. |
static Class |
findNestedClass(Class outerClass,
String className)
Find a public static nested class by name within another class. |
static Object |
getFirstElement(Collection c)
Get the first element of a collection. |
static Class[] |
getTypes(Object[] objects)
Get the types of an array of objects. |
static boolean |
isBlank(String s)
Test whether a String is null or empty or all whitespace. |
static List |
list(Object o1)
Create a List from the arguments. |
static List |
list(Object o1,
Object o2)
Create a List from the arguments. |
static List |
list(Object o1,
Object o2,
Object o3)
Create a List from the arguments. |
static String |
localizePath(String path)
Localize a path name by replacing both '\' and '/' with the local File.separatorChar . |
static void |
mkdirs(File dir)
Check for the existence of a directory and create it if necessary, including any non-existent parent directories. |
static String |
naturalize(String s)
Get a String from a camel case name with
spaces between each word,
and underscores replaced by spaces. |
static Object |
newInstance(Class clazz)
Create an object of a class with no constructor argument. |
static Object |
newInstance(Class clazz,
Object arg)
Create an object of a class with a given single constructor argument. |
static Object |
newInstance(Class clazz,
Object[] args)
Create an object of a class with a given set of arguments. |
static Object |
newInstance(Class clazz,
Object arg0,
Object arg1)
Create an object of a class with a given pair of constructor arguments. |
static Object |
newInstance(String className)
Create an object of a named class with no constructor argument. |
static Object |
newInstance(String className,
Object arg)
Create an object of a class with a given single constructor argument. |
static Object |
newInstance(String className,
Object[] args)
Create an object of a named class with a given set of arguments. |
static String |
nullToBlank(String s)
Change a null or blank String to an empty String . |
static String |
packageName(String className)
Get the package out of a fully qualified class name. |
static String |
pluralize(String word)
Get a String word made plural (in English). |
static String |
quote(String s)
Put double quotes around a string, and encode it. |
static String |
readFile(String fileName)
Read from a named file into a String . |
static String |
readReader(Reader rdr)
Read from a Reader into a String . |
static void |
readToPosition(BufferedReader rdr,
int line,
int col)
Read from the current position in a Reader to a given
relative line and column. |
static String |
singularize(String word)
Get a String word made singular (in English). |
static String[] |
splitAtSpace(String s)
Split a string at spaces. |
static String[] |
splitName(String name)
Split a string at periods or file separators. |
static String |
toString(Collection c)
|
static String |
uncapitalize(String s)
Get a String with the first character converted to lower case. |
static String |
unqualifiedClassName(String className)
Get the name of a class, without its package or containing class. |
static String[] |
wrap(String text,
int maxLength)
Split text at whitespace so that each line is less than maxLength . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final Object[] EMPTY_ARRAY
public static final String[] EMPTY_STRING_ARRAY
public static final Class[] EMPTY_CLASS_ARRAY
public static final Pattern NAME_PATTERN
Pattern
which finds '.' , '/', '\' so
it can be used for splitting file or package names.
public static final 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(Object o, String name)
public static void checkNotEmpty(String s, String name)
public static void checkNull(Object o, String name)
public static void checkArg(boolean b, String message)
public static void checkState(boolean b, String message)
public static String toString(Collection c)
public static Object getFirstElement(Collection c)
c
- the collection from which to get the first element
c
is emptypublic static List list(Object o1)
List
from the arguments.
o1
- the first element of the list
List
public static List list(Object o1, Object o2)
List
from the arguments.
o1
- the first element of the listo2
- the second element of the list
List
public static List list(Object o1, Object o2, Object o3)
List
from the arguments.
o1
- the first element of the listo2
- the second element of the listo3
- the third element of the list
List
public static String uncapitalize(String s)
String
with the first character converted to lower case.
s
- the String
to convert
String
public static String capitalize(String s)
String
with the first character converted to upper case.
s
- the String
to convert
String
public static String pluralize(String word)
String
word made plural (in English). Only the
basic rules for English plurals are applied.
word
- the word to convert
singularize(java.lang.String)
public static String singularize(String word)
String
word made singular (in English). Only the
basic rules for English plurals are applied.
word
- the word to convert
pluralize(java.lang.String)
public static String naturalize(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 String[] wrap(String text, int maxLength)
maxLength
.
text
- the String to split - may be nullmaxLength
- the maximum line length
text
is null or blankpublic static boolean isBlank(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 String blankToNull(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 String nullToBlank(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 String packageName(String className)
className
does not contain a "." then it is
returned unchanged.
className
- the qualified name
public static String unqualifiedClassName(String className)
className
does not contain a "." then it is
returned unchanged.
className
- the qualified name
public static String[] splitName(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 String[] splitAtSpace(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 String localizePath(String path)
File.separatorChar
.
path
- the name to split
public static Class findClass(String className)
className
- the name of the Class
required
public static Class findNestedClass(Class outerClass, String className)
outerClass
- the class that contains the required nested classclassName
- the name of the nested Class
required
(unqualified - does not include the name of the outer class)
public static Constructor findExactConstructor(Class clazz, Class[] argTypes)
clazz
- the Class
in which to look for the constructorargTypes
- the argument types of the required constructor
public static Constructor findConstructor(Class clazz, Class[] argTypes)
argTypes
,
not necessarily exact matches, as found by Class.getConstructor(java.lang.Class[])
.
clazz
- the Class
in which to find the constructorargTypes
- the types of the arguments to be passed to the constructor
Constructor
or null if clazz
does
not have the correct constructorpublic static Constructor findConstructor(Class clazz, Class argType)
clazz
- the Class
in which to look for the constructorargType
- the argument type of the required constructor
public static Class[] getTypes(Object[] objects)
objects
- the Objects
of which the types are required
public static Object newInstance(Class clazz, Object[] args) throws Exception
InvocationTargetException
.
clazz
- the Class
of object to createargs
- the arguments
Exception
- if an exception occurs calling the constructor of the object.
IllegalArgumentException
- if there is no constructor
which can accept the given argumentspublic static Object newInstance(String className, Object[] args) throws Exception
className
- the name of the Class
of object to createargs
- the arguments
Exception
newInstance( Class , Object[] )
public static Object newInstance(Class clazz) throws Exception
newInstance( Class , Object[] )
for details
clazz
- the Class
of object to create
Exception
newInstance( Class , Object[] )
public static Object newInstance(String className) throws Exception
newInstance( Class , Object[] )
for details
className
- the name of the Class
of object to create
Exception
newInstance( Class , Object[] )
public static Object newInstance(Class clazz, Object arg) throws Exception
newInstance( Class , Object[] )
for details
clazz
- the Class
of object to createarg
- the argument
Exception
newInstance( Class , Object[] )
public static Object newInstance(Class clazz, Object arg0, Object arg1) throws Exception
newInstance( Class , Object[] )
for details
clazz
- the Class
of object to createarg0
- the first argumentarg1
- the second argument
Exception
newInstance( Class , Object[] )
public static Object newInstance(String className, Object arg) throws Exception
newInstance( Class , Object[] )
for details
className
- the name of the Class
of object to createarg
- the argument
Exception
newInstance( Class , Object[] )
public static Object callStaticMethod(Class clazz, String name) throws 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
Exception
- if an exception occurs while making the call.
IllegalArgumentException
- if there is no method with the given name
with zero argumentspublic static void mkdirs(File dir) throws IOException
dir
- the directory to be created
IOException
- if the directory cannot be createdpublic static List concat(Collection c1, 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 String readReader(Reader rdr) throws IOException
Reader
into a String
.
rdr
- the Reader
from which to read
rdr
IOException
public static String readFile(String fileName) throws IOException
String
.
fileName
- the name of the file from which to read
fileName
IOException
public static void readToPosition(BufferedReader rdr, int line, int col) throws 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 tocol
- the column to move to
IOException
- if there is a problem reading from rdr
public static String quote(String s)
s
- the String
to quote
String
encode(java.lang.String)
public static String encode(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 |