|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.infinityloop.util.Utility
public class Utility
Collection of (static) Utility methods.
| Field Summary | |
|---|---|
static java.text.SimpleDateFormat[] |
rfc822DateFormats
Parses an RFC-1123 compliant date string into a Calendar object. |
| Constructor Summary | |
|---|---|
Utility()
|
|
| Method Summary | |
|---|---|
static java.util.List<java.lang.Object> |
arr2ArrayList(java.lang.Object[] arr)
Convert an array to a Vector. |
static void |
benchmark(int repetitions)
Do a quick and dirty benchmark of the system we are running on. |
static int |
coerceObjectToInt(java.lang.Object obj,
int defaultValue)
Try to make an integer from an arbitrary Java object. |
static java.lang.String |
coerceObjectToString(java.lang.Object obj,
java.lang.String defaultValue)
Try to make a String from an arbitrary Java object. |
static java.util.ArrayList |
convertHashMapToArrayList(java.util.HashMap ht)
Converts a HashMap to a Stack of Pair's. |
static java.util.Stack |
convertHashMapToStack(java.util.HashMap ht)
Converts a HashMap to a Stack of Pair's. |
static java.util.Stack |
convertHashtableToStack(java.util.Hashtable ht)
Converts a Hashtable to a Stack of Pair's. |
static java.util.Stack |
convertHashtableToStackSorted(java.util.Hashtable ht)
Converts a Hashtable to a Stack of Pair's, with sorted keys in natural order. |
static java.lang.String |
convertLineEndings(java.lang.String s,
java.lang.String lineEnding)
Converts the lines in the passed string into a form using the specified line ending string |
static java.util.Hashtable |
convertStackToHashtable(java.util.Vector v)
Converts a Vector of Pair()s to a Hashtable. |
static java.util.Stack |
convertTreeMapToStack(java.util.TreeMap ht)
Converts a TreeMap to a Stack of Pair's. |
static java.util.Map |
convertVectorToHashMap(java.util.Vector v)
Converts a Vector of Pair()s to a Hashtable. |
static int |
countOccurrences(java.lang.String s,
char c)
Returns the number of occurrences of a specified character in a String. |
static int |
dayDifference(java.util.Calendar one,
java.util.Calendar two)
Calculates the difference in days between the two dates passed in (one - two). |
static void |
debugMessage(java.lang.String msg)
Issue a debug level message to the current active log. |
static java.lang.Object |
deserializeJavaObject(java.lang.String ser)
Deserializes the passed serialization string and returns the appropriate Java object. |
static java.awt.Rectangle |
ensureVisibleWindowPosition(java.awt.Rectangle desired)
Returns a possibly modified copy of the passed, desired window bounds rectangle so that the window is actually visible at least 60x60px from the top left corner to be grabbable and draggable. |
static void |
errorMessage(java.lang.String msg)
Issue a error level message to the current active log. |
static java.lang.String |
escapeCharacters(java.lang.String input,
java.lang.String chars,
int mode)
Escapes all characters in input that are listed in chars according to the specified mode. |
static int |
executeCommand(java.util.Vector theCommand,
boolean wait,
java.lang.StringBuffer stdout,
java.lang.StringBuffer stderr)
executes the passed commandline via Runtime.exec(). |
static void |
fatalMessage(java.lang.String msg)
Issue a fatal level message to the current active log. |
static java.lang.String |
getCurrentMethodName()
Return the name of the routine that called getCurrentMethodName |
static java.lang.String |
getJREversionString()
Returns the JRE version as in the system property. |
static java.lang.String |
getMangledComponent(int n,
java.lang.String s)
Retrieves the n-th component of a mangled string, with n starting at 0. |
static java.lang.String |
getTimerInfoString()
prints current Timer information |
static int |
hourDifference(java.util.Calendar one,
java.util.Calendar two)
Calculates the difference in days between the two dates passed in (one - two). does not take into account leap years, leap seconds etc. |
static java.lang.String |
indentation(int steps,
java.lang.String indentationElement)
Calculates indentation string based on passed values: (steps * indentatationElement) as String |
static void |
infoMessage(java.lang.String msg)
Issue a info level message to the current active log. |
static boolean |
isDocFile(DiskFile file)
determines if the passed file is a DOC file |
static boolean |
isHexCharacter(char c)
Determines whether the passed character is a hex representation character, i.e. if it is within [0-9A-Fa-f]. |
static boolean |
isRTFFile(DiskFile file)
determines if the passed file is an RTF file |
static boolean |
isWordFile(DiskFile file)
determines if the passed file is a Word document file, i.e. |
static boolean |
isWordFilePlatform(DiskFile file)
determines if the passed file is a readable Word document file, i.e. |
static int |
makeDTTMFromRFCDate(java.lang.String s)
translates an RFC date to DTTM. |
static java.lang.String |
makeISODateString(java.util.Calendar cld)
Makes an ISO-8601 compliant date from a Java Calendar object. |
static java.lang.String |
makeRFCDateFromDTTM(int value)
translates a DTTM bitfield to a RFC date. |
static java.lang.String |
makeRFCDateString(java.util.Calendar cld)
Makes an RFC-1123 compliant date from a Java Calendar object. |
static java.lang.String |
makeStringFromList(java.util.List list)
Renders a List object into a String, by puttin the string value of each item into a new line (0xa) |
static int |
makeVersionInt(java.lang.String versionstring)
Tranforms the version string (M.m.r) into a int. |
static java.lang.String |
makeVersionString(int version)
Tranforms the integer version into a human readable version string. |
static java.lang.String |
makeVersionString(int version,
java.lang.String build)
Tranforms the integer version into a human readable version string, including the build number. |
static java.lang.String |
minimizeWhitespace(java.lang.String src)
Minimizes whitespace in a string, i.e. condenses all whitespace characters to one single WS character. |
static java.lang.String |
parseCSS2Identifier(java.lang.String src)
Parses a CSS2 (class-)identifier, resolving all hex escapes it might have. |
static java.util.Calendar |
parseISODateString(java.lang.String date)
Parses an ISO-8601 compliant date string into a Calendar object. |
static java.util.Calendar |
parseRFCDateString(java.lang.String date)
|
static java.lang.String |
prependLineNumbers(java.lang.String s)
Prepends line numbers to the passed string, starting with 1 |
static java.lang.String |
prettyPrintBytenumber(long n)
pretty-prints the passed number of bytes. |
static byte[] |
readDataToByteArray(InputProxy ip)
This reads from an input proxy the data into a byte array and returns that. |
static void |
resetTimer(java.lang.String key)
resets the timer with name key |
static void |
resetTimers()
resets all timing info |
static java.lang.String[] |
resolveArgumentString(java.lang.String params,
java.util.Vector charsNeedingQuoting)
Resolves a (commandline-) String into an array of Strings with the single arguments. |
static java.lang.String |
resolveNumericalEntities(java.lang.String s)
Replaces numerical entities in the passed string (&#decdigits;) into a Unicode character. |
static java.util.Stack |
resolveParameters(java.lang.String params)
Resolves a string into a Stack of Pair()s of parameter-name, parameter-value. |
static java.lang.String |
serializeExceptionStacktrace(java.lang.Throwable t)
Serializes the stack trace of the passed Throwable object to a String and returns it. |
static java.lang.String |
serializeJavaObject(java.lang.Object obj)
Serializes the passed Java object to a String. |
static java.lang.String |
setMangledComponent(java.lang.String dest,
int n,
java.lang.String val)
Sets the nth component in the passed string to the indicated value. |
static java.util.ArrayList |
splitTextToLines(java.lang.String source,
boolean stripEmptyLines,
boolean removeComments)
Splits the passed text into single lines and returns an ArrayList of Strings, each containing a single line of the original input. |
static void |
startTimer(java.lang.String key)
start a cumulative timer of key key |
static long |
stopTimer(java.lang.String key)
stops a cumulative timer of key key and returns the length of the just stopped timing action in milliseconds. |
static java.lang.String |
toHexString(long number,
int length,
boolean truncate)
Converts the passed long to a hex string with the specified length, with leading zeros if necessary. |
static java.lang.String |
unquoteCSS2IdentifierOrString(java.lang.String s)
Converts the passed CSS string to the internal format: unquote, resolve escapes etc. |
static void |
warnMessage(java.lang.String msg)
Issue a warning level message to the current active log. |
static void |
writeTextLinesStringPlatform(java.lang.String s,
java.io.Writer w)
Writes a string containing Java GUI newline characters (\n) to the specified OutputWriter, replacing Java GUI newlines by platform newlines. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.text.SimpleDateFormat[] rfc822DateFormats
To support optional components, we try several format string in defined order.
| Constructor Detail |
|---|
public Utility()
| Method Detail |
|---|
public static java.util.Stack convertTreeMapToStack(java.util.TreeMap ht)
public static java.util.Stack convertHashtableToStack(java.util.Hashtable ht)
public static java.util.Stack convertHashMapToStack(java.util.HashMap ht)
public static java.util.ArrayList convertHashMapToArrayList(java.util.HashMap ht)
public static java.util.Stack convertHashtableToStackSorted(java.util.Hashtable ht)
public static java.util.Hashtable convertStackToHashtable(java.util.Vector v)
public static java.util.Map convertVectorToHashMap(java.util.Vector v)
public static int countOccurrences(java.lang.String s,
char c)
public static java.lang.String makeRFCDateFromDTTM(int value)
DTTM format: wwwyyyyy yyyymmmm dddddhhh hhmmmmmm w day of week (0 Sun - 6 Sat) y year-1900 m month (1-12) d day of month (1-31) h hour 0-23 m minute 0-59 0-5 Minute 0-59 6-10 Hour 0-23 11-15 Day of month 1-31 16-19 Month 1-12 20-28 Year = Year-1900 29-31 Day of week 0 (Sun)-6 (Sat)
public static int makeDTTMFromRFCDate(java.lang.String s)
DTTM format: wwwyyyyy yyyymmmm dddddhhh hhmmmmmm w day of week (0 Sun - 6 Sat) y year-1900 m month (1-12) d day of month (1-31) h hour 0-23 m minute 0-59 0-5 Minute 0-59 6-10 Hour 0-23 11-15 Day of month 1-31 16-19 Month 1-12 20-28 Year = Year-1900 29-31 Day of week 0 (Sun)-6 (Sat)
public static java.lang.String unquoteCSS2IdentifierOrString(java.lang.String s)
public static java.lang.String parseCSS2Identifier(java.lang.String src)
public static boolean isHexCharacter(char c)
public static int dayDifference(java.util.Calendar one,
java.util.Calendar two)
public static int hourDifference(java.util.Calendar one,
java.util.Calendar two)
public static java.lang.String indentation(int steps,
java.lang.String indentationElement)
steps - number of steps to indentindentationElement - for each indentation step, this String is written
public static java.util.Stack resolveParameters(java.lang.String params)
[name ('='|':'|':=') '"' value '"']? [ '[;,]' name '=' '"' value '"' ]*
public static java.lang.String[] resolveArgumentString(java.lang.String params,
java.util.Vector charsNeedingQuoting)
public static java.util.ArrayList splitTextToLines(java.lang.String source,
boolean stripEmptyLines,
boolean removeComments)
source - the source stringstripEmptyLines - when true, no elements are generated for lines whose trim().length() == 0.removeComments - when true, all lines starting with '#' or '//' are discarded
public static java.lang.String makeStringFromList(java.util.List list)
list - the list to render
public static java.util.List<java.lang.Object> arr2ArrayList(java.lang.Object[] arr)
arr - the Object array
public static java.lang.String getJREversionString()
public static java.lang.String makeISODateString(java.util.Calendar cld)
public static java.lang.String makeRFCDateString(java.util.Calendar cld)
Format: "Wkd, dd Mon yyyy hh:mm:ss GMT"
public static java.util.Calendar parseISODateString(java.lang.String date)
public static java.util.Calendar parseRFCDateString(java.lang.String date)
public static java.lang.String makeVersionString(int version)
public static java.lang.String makeVersionString(int version,
java.lang.String build)
public static int makeVersionInt(java.lang.String versionstring)
public static void writeTextLinesStringPlatform(java.lang.String s,
java.io.Writer w)
throws java.io.IOException
java.io.IOException
public static java.lang.String convertLineEndings(java.lang.String s,
java.lang.String lineEnding)
public static java.lang.String prependLineNumbers(java.lang.String s)
public static java.lang.String minimizeWhitespace(java.lang.String src)
public static java.lang.String resolveNumericalEntities(java.lang.String s)
throws java.lang.Exception
java.lang.Exception
public static java.lang.String getMangledComponent(int n,
java.lang.String s)
public static java.lang.String setMangledComponent(java.lang.String dest,
int n,
java.lang.String val)
Note: n is 0-based.
public static java.lang.String toHexString(long number,
int length,
boolean truncate)
public static java.lang.String getCurrentMethodName()
public static void startTimer(java.lang.String key)
public static long stopTimer(java.lang.String key)
public static void resetTimers()
public static void resetTimer(java.lang.String key)
public static java.lang.String getTimerInfoString()
public static boolean isRTFFile(DiskFile file)
file - the file to test
public static boolean isDocFile(DiskFile file)
file - the file to test
public static boolean isWordFile(DiskFile file)
file - the file to test
public static boolean isWordFilePlatform(DiskFile file)
file - the file to test
public static int executeCommand(java.util.Vector theCommand,
boolean wait,
java.lang.StringBuffer stdout,
java.lang.StringBuffer stderr)
throws java.lang.Exception
java.lang.Exceptionpublic static java.lang.String serializeJavaObject(java.lang.Object obj)
obj - the object to serialize
public static java.lang.Object deserializeJavaObject(java.lang.String ser)
obj - the object to serialize
public static void debugMessage(java.lang.String msg)
msg - the message to logpublic static void infoMessage(java.lang.String msg)
msg - the message to logpublic static void errorMessage(java.lang.String msg)
msg - the message to logpublic static void warnMessage(java.lang.String msg)
msg - the message to logpublic static void fatalMessage(java.lang.String msg)
msg - the message to logpublic static void benchmark(int repetitions)
repetitions - repetitions of the test
public static java.lang.String escapeCharacters(java.lang.String input,
java.lang.String chars,
int mode)
input - the input stringchars - a String of all characters that need to be escapedmode - the escaping mode
public static java.lang.String prettyPrintBytenumber(long n)
public static java.lang.String serializeExceptionStacktrace(java.lang.Throwable t)
t - the Throwable
public static byte[] readDataToByteArray(InputProxy ip)
ip -
public static java.awt.Rectangle ensureVisibleWindowPosition(java.awt.Rectangle desired)
desired - the desired bounds
public static int coerceObjectToInt(java.lang.Object obj,
int defaultValue)
obj - the object to handle, may be nulldefaultValue - the value to return if the actual object cannot be coerced into an integer
public static java.lang.String coerceObjectToString(java.lang.Object obj,
java.lang.String defaultValue)
obj - the object to make a string of; implementation uses .toString() method on the objectdefaultValue - the default value to return when .toString() does not succeed or the object is null
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||