|
|||||||||
| Home >> All >> com >> port80 >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.port80.util
Class msg

java.lang.Objectcom.port80.util.msg
- public final class msg
- extends java.lang.Object
Debug and utility functions. Class cannot be instantiated. All functions are static.
- Version:
| Field Summary | |
private static boolean |
DEBUG_CALLFUNC
|
private static java.util.Map |
filepathEscapeChars
|
private static java.util.Map |
hexTable
|
private static java.lang.String |
NAME
|
private static int |
NONE
|
private static int |
OPT
|
private static int |
OPTARRAY
|
private static java.lang.String |
pwd
|
private static org.apache.oro.text.perl.Perl5Util |
re
NOTE: Perl5Util methods (such as split, match ... |
private static int |
REQ
|
private static int |
REQARRAY
|
private static java.util.Map |
standardErrors
|
private static java.util.Map |
uriEscapeChars
|
| Constructor Summary | |
private |
msg()
Prevent instantiation. |
| Method Summary | |
static boolean |
asserts(boolean ok)
|
static java.lang.String[] |
basename(java.lang.String path)
Get dir,name,base,ext parts of a file path. |
static java.lang.String |
baseName(java.lang.String path)
Return base name part of a file path. |
static int |
binarySearch(int[] a,
int from,
int to,
int key)
Same as Arrays.binarySearch(int[],int) but within the specified range. |
static java.lang.Object |
callFunc(java.lang.Class c,
java.lang.String func,
java.lang.Object userdata)
Create a new instance of a given class and call its object.func(Object). |
static java.lang.Object |
callFunc(java.lang.Class c,
java.lang.String func,
java.lang.Object[] userdata)
Create a new instance of a class and call its object.func(Object[]) method. |
static java.lang.Object |
callFunc(java.lang.Object object,
java.lang.String func,
java.lang.Object userdata)
Call a method Object object.func(Object) through reflection. |
static java.lang.Object |
callFunc(java.lang.Object object,
java.lang.String func,
java.lang.Object[] userdata)
Call a method object.func(Object[]) through reflection. |
static int |
count(java.lang.String s,
char c)
Count number of occurance of a char in a string. |
static java.io.File |
createFile(java.lang.String path)
Create a new File at the given path, create directories if neccessary. |
static void |
debug(java.lang.String s)
|
static void |
debugs(java.lang.String s)
|
static java.lang.String |
dirName(java.lang.String path)
Return dir part of a file path. |
static void |
err(java.lang.Exception e)
|
static void |
err(java.lang.String s)
|
static void |
err(java.lang.String s,
java.lang.Exception e)
|
static void |
err(java.lang.String s,
java.sql.SQLException e)
|
static void |
errExit(java.lang.String s)
|
static java.lang.String |
escapeFilepath(java.lang.String s)
Esacpe characters that are sensitive as a unix filename. |
static java.lang.String |
escapeURI(java.lang.String s)
|
static java.lang.String |
escapeURL(java.lang.String s)
Esacpe reserved URL characters. |
static java.lang.String |
escString(java.lang.String s)
|
static void |
exit(java.lang.String id,
java.lang.String m)
Exit with standard error messages. |
private static int |
fail(java.lang.String message)
|
static void |
fatal(java.lang.String s)
|
static java.lang.String |
fileName(java.lang.String path)
Return name part of a file path. |
static java.util.List |
findFiles(java.io.File dir,
java.io.FileFilter filter,
java.util.List ret)
Return a list of File (with absolute path) under specified filepath. |
static java.util.List |
findFiles(java.io.File dir,
java.lang.String pattern,
java.util.List ret)
|
static java.lang.String[] |
findFiles(java.lang.String path,
java.lang.String pattern)
Return a list of absolute filepath under specified filepath. |
static java.util.List |
findFiles(java.lang.String path,
java.lang.String pattern,
java.util.List ret)
|
static java.lang.String[] |
getArgs(java.util.Map ret,
java.lang.String name,
java.lang.String[] args,
java.lang.String spec)
Return the stripped args[] instead of optind. |
static int |
getOpt(java.util.Map ret,
java.lang.String name,
java.lang.String[] args,
java.lang.String spec)
Get short/long options. |
static boolean |
getOptBool(java.util.Map opt,
java.lang.String optname)
|
static float |
getOptFloat(java.util.Map opt,
java.lang.String optname,
float def)
|
static int |
getOptInt(java.util.Map opt,
java.lang.String optname,
int def)
|
static java.lang.String |
getOptString(java.util.Map opt,
java.lang.String optname)
|
static java.lang.String[] |
groups(java.lang.String pattern,
java.lang.String s)
|
static int |
hexToInt(java.lang.String s,
int def)
Convert hex string to int. |
static int |
insertionIndex(int[] a,
int x)
Binary search for insertion point of 'x' in 'a'. |
static int |
insertionIndex(int[] a,
int from,
int to,
int x)
Binary search for insertion point of 'x' in the given range of 'a' . |
static java.lang.String |
join(java.lang.String sep,
java.util.List a)
|
static void |
main(java.lang.String[] args)
|
static boolean |
match(java.lang.String pattern,
java.lang.String s)
|
static void |
move(int[] a,
int from,
int to)
Move element at index 'from' to index 'to'. |
static java.lang.Object |
newClass(java.lang.String classname)
Create a new class of given name with default constructor. |
static java.lang.Object |
newClass(java.lang.String classname,
java.lang.String func,
java.lang.Object userdata)
Create a new class of given name with default constructor and call a function with the given function name that has the following signature: Object func(Object); |
static java.util.List |
newListInstance()
|
static java.util.Map |
newMapInstance()
|
static java.util.Set |
newSetInstance()
|
static java.lang.String |
normalizeFilePath(java.lang.String path)
Fixup file path to full path and remove redundant chars. |
static java.lang.String |
normalizeFilePath(java.lang.String path,
java.lang.String pwd)
Fixup file path to full path and remove redundant chars. |
static void |
out(java.lang.String s)
|
static void |
outln(java.lang.String s)
|
static double |
parseDouble(java.lang.String s)
|
static double |
parseDouble(java.lang.String s,
double def)
|
static double[] |
parseDouble2(java.lang.String s)
Parse 's' for two comma separated float numbers. |
static float |
parseFloat(java.lang.String s)
|
static float |
parseFloat(java.lang.String s,
float def)
|
static float[] |
parseFloat2(java.lang.String s)
Parse 's' for two comma separated float numbers. |
static com.port80.util.struct.FloatList |
parseFloats(java.lang.String s)
Parse 's' for any number of comma separated float numbers. |
static int |
parseInt(java.lang.String s)
|
static int |
parseInt(java.lang.String s,
int def)
|
static void |
permutate(int[] ret)
Generate a random permutation of given array. |
static void |
permutate(java.lang.Object[] ret)
Generate a random permutation of given array. |
static void |
print(java.lang.String s)
|
static void |
println(java.lang.String s)
|
static void |
println(java.lang.String s,
int[] a)
|
static void |
printStack(java.lang.String s)
|
static void |
printStat(long stime,
int n)
|
static java.lang.String |
quote(java.lang.String s)
|
static int[] |
randomSequence(int size)
Generate a random sequence from 0 to size. |
static java.lang.String |
removeExt(java.lang.String path)
Remove filename extension from a filepath if there is one. |
static java.lang.String |
removeQuote(java.lang.String s)
|
static int |
sizeof(java.lang.String name)
Try to determine sizeof an object given by 'name'. |
static int |
skipWS(java.lang.String str,
int start,
int max)
|
static java.util.List |
split(java.lang.String pattern,
java.lang.String s)
|
static java.lang.String |
sprintArray(java.lang.Object object)
|
static java.lang.String |
sprintArray(java.lang.Object object,
java.lang.String indent,
java.lang.String tab,
java.lang.String mesg)
|
static java.lang.String |
sprintObject(java.lang.Object object)
|
static java.lang.String |
sprintObject(java.lang.Object object,
java.lang.String indent,
java.lang.String tab,
java.lang.String mesg)
|
static java.lang.String[] |
standardOptions(java.lang.String name,
java.lang.String[] args)
A convinient function to process standard option (-h,-D) for program that do not have extra options. |
static java.lang.String[] |
standardOptions(java.lang.String name,
java.lang.String[] args,
java.lang.String usage)
|
static java.lang.String |
subst(java.lang.String pattern,
java.lang.String s)
|
static void |
test(java.lang.String s)
|
static int |
test1(java.lang.String[] args)
|
private static void |
testBinarySearch()
|
private static void |
testFilename(java.lang.String[] args)
Call the getConf(Object) method of a given application. |
private static void |
testFindFiles(java.lang.String[] args)
|
private static void |
testGetOpt(java.lang.String[] args)
|
private static void |
testMove()
|
private static void |
testParseFloat()
|
private static void |
testPermutate()
|
private static void |
testSizeof()
|
private static void |
testUnescString()
|
static java.lang.String[] |
toStringArray(java.util.List a)
Convert List of String to String[]. |
static void |
trace(java.lang.String s)
|
static java.lang.String |
unescapeFilepath(java.lang.String s)
Unesacpe sensitive unix filename characters. |
static java.lang.String |
unescapePercents(java.lang.String s)
Unescape all %xx triplets. |
static java.lang.String |
unescapeURI(java.lang.String s)
|
static java.lang.String |
unescapeURL(java.lang.String s)
Unesacpe only the URI reserved characters %xx triplet. |
static java.lang.String |
unescString(java.lang.String s)
Unescape escape sequences inside a string. |
static void |
usage(java.lang.String m)
|
static void |
warn(java.lang.String s)
|
static void |
warns(java.lang.String s)
|
static java.lang.String |
xmlEscape(java.lang.String s)
Escape XML reserved characters. |
static java.lang.String |
xmlUnescape(java.lang.String s)
Decode XML escaped characters back to ASCII. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
NAME
private static final java.lang.String NAME
- See Also:
- Constant Field Values
DEBUG_CALLFUNC
private static boolean DEBUG_CALLFUNC
NONE
private static final int NONE
- See Also:
- Constant Field Values
REQ
private static final int REQ
- See Also:
- Constant Field Values
OPT
private static final int OPT
- See Also:
- Constant Field Values
REQARRAY
private static final int REQARRAY
- See Also:
- Constant Field Values
OPTARRAY
private static final int OPTARRAY
- See Also:
- Constant Field Values
re
private static org.apache.oro.text.perl.Perl5Util re
- NOTE: Perl5Util methods (such as split, match ... etc) are public synchronized.
So no need to synchronize methods because of access to re.
hexTable
private static java.util.Map hexTable
uriEscapeChars
private static java.util.Map uriEscapeChars
filepathEscapeChars
private static java.util.Map filepathEscapeChars
standardErrors
private static java.util.Map standardErrors
pwd
private static java.lang.String pwd
| Constructor Detail |
msg
private msg()
- Prevent instantiation.
| Method Detail |
asserts
public static boolean asserts(boolean ok)
debug
public static void debug(java.lang.String s)
debugs
public static void debugs(java.lang.String s)
trace
public static void trace(java.lang.String s)
test
public static void test(java.lang.String s)
err
public static void err(java.lang.String s)
err
public static void err(java.lang.Exception e)
warn
public static void warn(java.lang.String s)
warns
public static void warns(java.lang.String s)
err
public static void err(java.lang.String s, java.lang.Exception e)
err
public static void err(java.lang.String s, java.sql.SQLException e)
usage
public static void usage(java.lang.String m)
fatal
public static void fatal(java.lang.String s)
errExit
public static void errExit(java.lang.String s)
out
public static void out(java.lang.String s)
outln
public static void outln(java.lang.String s)
public static void print(java.lang.String s)
println
public static void println(java.lang.String s)
println
public static void println(java.lang.String s, int[] a)
printStack
public static void printStack(java.lang.String s)
printStat
public static void printStat(long stime,
int n)
exit
public static void exit(java.lang.String id, java.lang.String m)
- Exit with standard error messages.
sprintObject
public static java.lang.String sprintObject(java.lang.Object object)
sprintObject
public static java.lang.String sprintObject(java.lang.Object object, java.lang.String indent, java.lang.String tab, java.lang.String mesg)
sprintArray
public static java.lang.String sprintArray(java.lang.Object object)
sprintArray
public static java.lang.String sprintArray(java.lang.Object object, java.lang.String indent, java.lang.String tab, java.lang.String mesg)
match
public static boolean match(java.lang.String pattern, java.lang.String s)
subst
public static java.lang.String subst(java.lang.String pattern, java.lang.String s)
split
public static java.util.List split(java.lang.String pattern, java.lang.String s)
groups
public static java.lang.String[] groups(java.lang.String pattern, java.lang.String s)
unescString
public static java.lang.String unescString(java.lang.String s)
- Unescape escape sequences inside a string.
eg. "a\\\tbc\\\n\\
cde"
becomes:
"a\tbc\ncde"
Java EscapeSequence:
\b : backspace BS
\t : horizontal tab HT
\n
: linefeed LF
\f : form feed FF
\r
: carriage return CR
\" ": double quote "
\' ': single quote '
\\ \: backslash \
escString
public static java.lang.String escString(java.lang.String s)
quote
public static java.lang.String quote(java.lang.String s)
join
public static java.lang.String join(java.lang.String sep, java.util.List a)
removeQuote
public static java.lang.String removeQuote(java.lang.String s)
count
public static int count(java.lang.String s, char c)
- Count number of occurance of a char in a string.
xmlEscape
public static java.lang.String xmlEscape(java.lang.String s)
- Escape XML reserved characters.
xmlUnescape
public static java.lang.String xmlUnescape(java.lang.String s)
- Decode XML escaped characters back to ASCII.
escapeURL
public static java.lang.String escapeURL(java.lang.String s)
- Esacpe reserved URL characters.
NOTE: % is escaped, so existing %xx triplet are NOT preserved.
escapeURI
public static java.lang.String escapeURI(java.lang.String s)
unescapeURL
public static java.lang.String unescapeURL(java.lang.String s)
- Unesacpe only the URI reserved characters %xx triplet.
NOTE: %% is unescape to %.
unescapeURI
public static java.lang.String unescapeURI(java.lang.String s)
unescapePercents
public static java.lang.String unescapePercents(java.lang.String s)
- Unescape all %xx triplets.
hexToInt
public static int hexToInt(java.lang.String s, int def)
- Convert hex string to int.
escapeFilepath
public static java.lang.String escapeFilepath(java.lang.String s)
- Esacpe characters that are sensitive as a unix filename.
NOTE: % is not escaped so that existing %xx triplet are preserved.
unescapeFilepath
public static java.lang.String unescapeFilepath(java.lang.String s)
- Unesacpe sensitive unix filename characters.
NOTE that we do not unescape all ^xx triplet. Use unescapePercents() for that purpose.
normalizeFilePath
public static java.lang.String normalizeFilePath(java.lang.String path, java.lang.String pwd)
- Fixup file path to full path and remove redundant chars.
normalizeFilePath
public static java.lang.String normalizeFilePath(java.lang.String path)
- Fixup file path to full path and remove redundant chars.
basename
public static java.lang.String[] basename(java.lang.String path)
- Get dir,name,base,ext parts of a file path.
dirName
public static java.lang.String dirName(java.lang.String path)
- Return dir part of a file path. eg.
dir1/dir2/file.java return dir1/dir2
fileName
public static java.lang.String fileName(java.lang.String path)
- Return name part of a file path. eg.
dir1/dir2/file.java return file.java
baseName
public static java.lang.String baseName(java.lang.String path)
- Return base name part of a file path. eg.
dir1/dir2/file.java return file.
removeExt
public static java.lang.String removeExt(java.lang.String path)
- Remove filename extension from a filepath if there is one. eg.
dir1/dir2/file.java return dir1/dir2/file
findFiles
public static java.util.List findFiles(java.io.File dir, java.io.FileFilter filter, java.util.List ret)
- Return a list of File (with absolute path) under specified
filepath.
findFiles
public static java.util.List findFiles(java.io.File dir, java.lang.String pattern, java.util.List ret)
findFiles
public static java.util.List findFiles(java.lang.String path, java.lang.String pattern, java.util.List ret)
createFile
public static java.io.File createFile(java.lang.String path)
- Create a new File at the given path, create directories if neccessary.
findFiles
public static java.lang.String[] findFiles(java.lang.String path, java.lang.String pattern)
- Return a list of absolute filepath under specified filepath.
toStringArray
public static java.lang.String[] toStringArray(java.util.List a)
- Convert List of String to String[].
getOpt
public static int getOpt(java.util.Map ret, java.lang.String name, java.lang.String[] args, java.lang.String spec)
- Get short/long options.
Options are specified in a space separated string. The first
field is the short options. The second and following specify
the long options.
. Long options format:
[= ]+[:|@] . is the long name, is the short alias name. If short alias is specified, only the long option is returned and the short option should not be specified in the short option spec. . Option end with ':' have an required String argument. . Option end with '@' have an required List of String as argument. . Option end with '::' have an optional String argument. . Option end with '@@' have an optional List of String as argument. . To skip the short option spec. start the spec string with ' ' or '-'. eg 'ab:cI@v:: vv output: help=h debug=d@@ include=I@' specifies options: a b: c d@@ h v:: vv output: help debug@@ include@
getArgs
public static java.lang.String[] getArgs(java.util.Map ret, java.lang.String name, java.lang.String[] args, java.lang.String spec)
- Return the stripped args[] instead of optind.
standardOptions
public static java.lang.String[] standardOptions(java.lang.String name, java.lang.String[] args)
- A convinient function to process standard option (-h,-D) for
program that do not have extra options. Typically used by
class that use the main routine as a test stub.
standardOptions
public static java.lang.String[] standardOptions(java.lang.String name, java.lang.String[] args, java.lang.String usage)
getOptBool
public static boolean getOptBool(java.util.Map opt, java.lang.String optname)
getOptInt
public static int getOptInt(java.util.Map opt, java.lang.String optname, int def)
getOptFloat
public static float getOptFloat(java.util.Map opt, java.lang.String optname, float def)
getOptString
public static java.lang.String getOptString(java.util.Map opt, java.lang.String optname)
parseInt
public static int parseInt(java.lang.String s, int def)
parseInt
public static int parseInt(java.lang.String s)
parseFloat
public static float parseFloat(java.lang.String s, float def)
parseFloat
public static float parseFloat(java.lang.String s)
parseFloat2
public static float[] parseFloat2(java.lang.String s)
- Parse 's' for two comma separated float numbers.
parseFloats
public static com.port80.util.struct.FloatList parseFloats(java.lang.String s)
- Parse 's' for any number of comma separated float numbers.
eg. "10.0,20, 1.3, 2.4,4,5"
parseDouble
public static double parseDouble(java.lang.String s, double def)
parseDouble2
public static double[] parseDouble2(java.lang.String s)
- Parse 's' for two comma separated float numbers.
parseDouble
public static double parseDouble(java.lang.String s)
skipWS
public static int skipWS(java.lang.String str, int start, int max)
randomSequence
public static int[] randomSequence(int size)
- Generate a random sequence from 0 to size.
permutate
public static void permutate(int[] ret)
- Generate a random permutation of given array.
permutate
public static void permutate(java.lang.Object[] ret)
- Generate a random permutation of given array.
move
public static void move(int[] a,
int from,
int to)
- Move element at index 'from' to index 'to'.
Shift element in between to maintain order.
Example:
1 2 from(3) 4 5 to(6) 7 8 9 -> 1 2 4 5 6 (3) 7 8 9
1 2 to(3) 4 5 from(6) 7 8 9 -> 1 2 (6) 3 4 5 7 8 9
insertionIndex
public static int insertionIndex(int[] a,
int x)
- Binary search for insertion point of 'x' in 'a'.
Returned index is the insertion point for 'x' regardless a match is found or not.
insertionIndex
public static int insertionIndex(int[] a,
int from,
int to,
int x)
- Binary search for insertion point of 'x' in the given range of 'a' .
Returned index is the insertion point for 'x' regardless a match is found or not.
binarySearch
public static int binarySearch(int[] a,
int from,
int to,
int key)
- Same as Arrays.binarySearch(int[],int) but within the specified range.
newClass
public static java.lang.Object newClass(java.lang.String classname)
- Create a new class of given name with default constructor.
newClass
public static java.lang.Object newClass(java.lang.String classname, java.lang.String func, java.lang.Object userdata) throws java.lang.NoSuchMethodException
- Create a new class of given name with default constructor and
call a function with the given function name that has the
following signature:
Object func(Object);
callFunc
public static java.lang.Object callFunc(java.lang.Object object, java.lang.String func, java.lang.Object userdata) throws java.lang.NoSuchMethodException
- Call a method Object object.func(Object) through reflection.
callFunc
public static java.lang.Object callFunc(java.lang.Object object, java.lang.String func, java.lang.Object[] userdata) throws java.lang.NoSuchMethodException
- Call a method object.func(Object[]) through reflection.
callFunc
public static java.lang.Object callFunc(java.lang.Class c, java.lang.String func, java.lang.Object userdata) throws java.lang.NoSuchMethodException
- Create a new instance of a given class and call its object.func(Object).
callFunc
public static java.lang.Object callFunc(java.lang.Class c, java.lang.String func, java.lang.Object[] userdata) throws java.lang.NoSuchMethodException
- Create a new instance of a class and call its object.func(Object[]) method.
sizeof
public static int sizeof(java.lang.String name)
- Try to determine sizeof an object given by 'name'.
This is very slow, just for benchmark use.
newListInstance
public static java.util.List newListInstance()
newMapInstance
public static java.util.Map newMapInstance()
newSetInstance
public static java.util.Set newSetInstance()
main
public static void main(java.lang.String[] args)
test1
public static int test1(java.lang.String[] args)
testGetOpt
private static void testGetOpt(java.lang.String[] args)
testFindFiles
private static void testFindFiles(java.lang.String[] args)
testFilename
private static void testFilename(java.lang.String[] args)
- Call the getConf(Object) method of a given application.
testUnescString
private static void testUnescString()
testSizeof
private static void testSizeof()
testParseFloat
private static void testParseFloat()
testPermutate
private static void testPermutate()
testBinarySearch
private static void testBinarySearch()
testMove
private static void testMove()
fail
private static int fail(java.lang.String message)
|
|||||||||
| Home >> All >> com >> port80 >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
com.port80.util.msg