com.dynamide.util
Class Tools

java.lang.Object
  extended by com.dynamide.util.Tools

public class Tools
extends java.lang.Object


Field Summary
static java.lang.String DATE_SEPARATOR
           
static java.lang.String[] daysOfWeek
           
static java.lang.String DUMPHTML_ELEMSEP
           
static java.lang.String DUMPHTML_END
           
static java.lang.String DUMPHTML_LINESEP
           
static java.lang.String DUMPHTML_OBJPLACEHOLDER
           
static java.lang.String DUMPHTML_START
           
static int FS_DOS
           
static int FS_MAC
           
static int FS_UNIX
           
static java.lang.String NEW_LINE
           
 
Constructor Summary
Tools()
           
 
Method Summary
static java.lang.String arrayToString(java.lang.Object[] array)
           
static java.lang.String arrayToString(java.lang.Object[] array, java.lang.String delimiter)
           
static java.lang.String cleanAndReportMemory()
           
static java.lang.String cleanAndReportMemory(long millis)
           
static java.lang.String collectionToString(java.util.Collection list)
          Lists with null elements are not allowed.
static java.lang.String collectionToString(java.util.Collection list, java.lang.String delim)
          Lists with null elements are not allowed.
static boolean copyFile(java.lang.String sourceFileName, java.lang.String destFileName)
          Copy a binary source file to a destination file.
static java.util.Map createSortedCaseInsensitiveMap()
          Creates a TreeMap with a case-insenstive collator using the US Locale.
static java.lang.String dateLongToLocale(long longdate)
           
static java.lang.String dateLongToLocale(java.lang.Long longdate)
           
static java.lang.String dateLongToLocale(java.lang.String longdatestr)
           
static java.lang.String dateLongToLocale(java.sql.Timestamp timestamp)
           
static java.lang.String dateToLocale(java.util.Date date)
           
static java.lang.String dump(java.util.Map map)
           
static java.lang.String dump(java.util.Map map, java.lang.String lineBreak)
           
static java.lang.String dump(java.util.Map map, java.lang.String start, java.lang.String lineSeparator, java.lang.String elementSeparator, java.lang.String objectPlaceholder, java.lang.String end, boolean dumphtml)
           
static java.lang.String dumpHTML(java.util.Map map)
           
static void enableIf(java.awt.Component[] components, boolean value)
          Enables all Components in an array if value parameter is true, else disables them
static java.lang.String enumerationToString(java.util.Enumeration stringList, java.lang.String delim)
           
static java.lang.String errorToString(java.lang.Throwable e, boolean stackTraceOnException)
          Takes an Exception object and formats a message that provides more debug information suitable for developers for printing to System.out or for logging.
static java.lang.String errorToString(java.lang.Throwable e, boolean stackTraceOnException, boolean showmsg)
           
static boolean fileSystemIsDOS()
           
static java.lang.String fixFilename(java.lang.String filename)
           
static java.lang.String formatCheckedValue(boolean isTrue)
          format the correct checked value for browsers, based on a boolean.
static java.lang.String formatUptime(long startTime)
           
static java.lang.String getGMTTimestamp()
           
static java.lang.String getGMTTimestamp(long longTime)
           
static java.lang.String getIniValue(java.lang.String iniFile, java.lang.String section, java.lang.String key, java.lang.String defaultValue)
           
static java.lang.String getIniValue(java.lang.String directory, java.lang.String iniFile, java.lang.String section, java.lang.String key, java.lang.String defaultValue)
           
static java.lang.String getIniValue(java.util.Vector iniValues, java.lang.String section, java.lang.String key, java.lang.String defaultValue)
           
static boolean getIniValueBoolean(java.util.Vector iniValues, java.lang.String section, java.lang.String key, boolean defaultValue)
           
static int getIniValueInt(java.util.Vector iniValues, java.lang.String section, java.lang.String key, int defaultValue)
           
static java.lang.String getStackTrace()
           
static java.lang.String getStackTrace(java.lang.Throwable t)
           
static java.lang.String getStackTraceWithMessage(java.lang.Throwable e)
           
static java.lang.String intToString(int i)
          Instead of this convenience funtion, you can just place the integer in a string context, e.g.
static boolean isBlank(java.lang.String value)
          Use this static method to determine if a string represents a blank value.
static boolean isChecked(java.lang.String value)
           
static boolean isJVM13()
           
static boolean isJVM14()
           
static boolean isTrue(java.lang.Object arg)
           
static boolean isTrue(java.lang.String arg)
          Use this static method to determine if a string represents boolean True.
static java.lang.String iteratorToString(java.util.Iterator i, java.lang.String delim)
           
static java.lang.String listToString(java.util.List list)
          Lists with null elements are not allowed.
static java.lang.String listToString(java.util.List list, java.lang.String delim)
          Lists with null elements are not allowed.
static java.util.Vector listToVector(java.lang.String whiteSpaceDelimitedElements)
          Turn any whitespace delimited list into a Vector.
static void makeVisibleIf(java.awt.Component[] components, boolean value)
          Makes all Components in an array visible if value parameter is true, else makes them invisible
static java.lang.Long now()
          Milliseconds from start time as definded by the Date class.
static java.lang.String nowLocale()
           
static java.sql.Timestamp nowSQL()
           
static java.io.File openFile(java.lang.String dir, java.lang.String relPath)
           
static void printStackTrace()
           
static java.lang.String readFile(java.lang.String fullPath)
           
static java.lang.String readFile(java.lang.String dir, java.lang.String relPath)
           
static java.util.Vector readFileToVector(java.lang.String dir, java.lang.String relPath)
          Doesn't throw any exceptions: returns null if the file was not found, etc.
static java.util.Vector readIniFile(java.lang.String filename)
           
static java.util.Vector readIniFile(java.lang.String dir, java.lang.String relPath)
           
static java.lang.String readln()
           
static java.lang.String readln(java.io.InputStream in)
          WARNING: Some unix terminal drivers expect \r as a line end char, although we look for strictly a \n here.
static java.lang.String readln(java.io.InputStream in, int fsType)
          fsType is one of FS_UNIX, FS_DOS, FS_MAC
static java.lang.String readln(java.lang.String prompt)
           
static void reverseEnabledIf(java.awt.Component[] components, boolean value)
          Reverses the enabled state for all Components in an array if value parameter is true, else leaves them alone
static void reverseVisibleIf(java.awt.Component[] components, boolean value)
          Reverses the visible state for all Components in an array if value parameter is true, else leaves them alone
static java.io.File saveFile(java.lang.String dir, java.lang.String relativeName, java.lang.String content)
           
static java.io.File saveIniFile(java.util.Vector iniValues, java.lang.String filename)
           
static java.io.File saveIniFile(java.util.Vector iniValues, java.lang.String dir, java.lang.String relPath)
           
static java.io.File saveVectorToFile(java.util.Vector vector, java.lang.String delim, java.lang.String dir, java.lang.String relPath)
           
static void setBackground(java.awt.Component comp, java.awt.Color newColor)
           
static void setIniValue(java.util.Vector iniValues, java.lang.String section, java.lang.String key, java.lang.String value)
           
static java.lang.String setToString(java.util.Set list)
          Sets with null elements are not allowed.
static java.lang.String setToString(java.util.Set list, java.lang.String delim)
          Sets with null elements are not allowed.
static java.lang.String showControlChars(java.lang.String inString)
          Show all control chars in string, except CRLF.
static java.lang.String showControlChars(java.lang.String inString, boolean showCRLF)
          Shows all control chars (less than ASCII 32) by converting them to the format #nnn, where nnn is a 1 to 3 digit decimal number.
static void sleep(java.lang.Integer millis)
           
static void sleep(long millis)
           
static int stringToInt(java.lang.String source)
          Returns a fundamental type int.
static int stringToIntSafe(java.lang.Object source, int def)
           
static int stringToIntSafe(java.lang.String source, int def)
          Returns a fundamental type int.
static java.lang.String vectorToString(java.util.Vector stringList)
           
static java.lang.String vectorToString(java.util.Vector stringList, java.lang.String delim)
           
static java.lang.String vectorToString(java.util.Vector stringList, java.lang.String delim, java.lang.String linenumberTemplate, int startingNumber)
          Formats the vector into a String, using the supplied delimiter, and, optionally, the supplied line number template, which can contain the magic variable "$linenumber", without the quotes.
static java.lang.String[] vectorToStringArray(java.util.Vector source)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEW_LINE

public static java.lang.String NEW_LINE

DATE_SEPARATOR

public static java.lang.String DATE_SEPARATOR

daysOfWeek

public static java.lang.String[] daysOfWeek

FS_UNIX

public static final int FS_UNIX
See Also:
Constant Field Values

FS_DOS

public static final int FS_DOS
See Also:
Constant Field Values

FS_MAC

public static final int FS_MAC
See Also:
Constant Field Values

DUMPHTML_START

public static final java.lang.String DUMPHTML_START
See Also:
Constant Field Values

DUMPHTML_LINESEP

public static final java.lang.String DUMPHTML_LINESEP
See Also:
Constant Field Values

DUMPHTML_ELEMSEP

public static final java.lang.String DUMPHTML_ELEMSEP
See Also:
Constant Field Values

DUMPHTML_OBJPLACEHOLDER

public static final java.lang.String DUMPHTML_OBJPLACEHOLDER
See Also:
Constant Field Values

DUMPHTML_END

public static final java.lang.String DUMPHTML_END
See Also:
Constant Field Values
Constructor Detail

Tools

public Tools()
Method Detail

intToString

public static java.lang.String intToString(int i)
Instead of this convenience funtion, you can just place the integer in a string context, e.g. String s = "my string" + i; If you just have a single integer with no leading string, call this method, or just use String s = ""+i;


stringToInt

public static int stringToInt(java.lang.String source)
Returns a fundamental type int. For StringToInteger, just create a new Integer object, using the constructor Integer(String).

Switched to Integer.parseInt in hopes of avoiding object overhead. MattD 20010414.


stringToIntSafe

public static int stringToIntSafe(java.lang.Object source,
                                  int def)

stringToIntSafe

public static int stringToIntSafe(java.lang.String source,
                                  int def)
Returns a fundamental type int. Returns zero if the source string can't be parsed instead of throwing a NumberFormatException.


listToVector

public static java.util.Vector listToVector(java.lang.String whiteSpaceDelimitedElements)
Turn any whitespace delimited list into a Vector. There is no way to define an empty element, so if your syntax has an empty element character sequence, just walk the Vector when this method returns and look for that sequence. For example, if you use "", then the characters "" will be an element on the list. You could search out each occurence and replace with an empty string.


enumerationToString

public static java.lang.String enumerationToString(java.util.Enumeration stringList,
                                                   java.lang.String delim)

vectorToString

public static java.lang.String vectorToString(java.util.Vector stringList)

vectorToString

public static java.lang.String vectorToString(java.util.Vector stringList,
                                              java.lang.String delim)

vectorToString

public static java.lang.String vectorToString(java.util.Vector stringList,
                                              java.lang.String delim,
                                              java.lang.String linenumberTemplate,
                                              int startingNumber)
Formats the vector into a String, using the supplied delimiter, and, optionally, the supplied line number template, which can contain the magic variable "$linenumber", without the quotes.


listToString

public static java.lang.String listToString(java.util.List list)
Lists with null elements are not allowed.


listToString

public static java.lang.String listToString(java.util.List list,
                                            java.lang.String delim)
Lists with null elements are not allowed.


collectionToString

public static java.lang.String collectionToString(java.util.Collection list)
Lists with null elements are not allowed.


collectionToString

public static java.lang.String collectionToString(java.util.Collection list,
                                                  java.lang.String delim)
Lists with null elements are not allowed.


iteratorToString

public static java.lang.String iteratorToString(java.util.Iterator i,
                                                java.lang.String delim)

setToString

public static java.lang.String setToString(java.util.Set list)
Sets with null elements are not allowed.


setToString

public static java.lang.String setToString(java.util.Set list,
                                           java.lang.String delim)
Sets with null elements are not allowed.


vectorToStringArray

public static java.lang.String[] vectorToStringArray(java.util.Vector source)

arrayToString

public static java.lang.String arrayToString(java.lang.Object[] array,
                                             java.lang.String delimiter)

arrayToString

public static java.lang.String arrayToString(java.lang.Object[] array)

createSortedCaseInsensitiveMap

public static java.util.Map createSortedCaseInsensitiveMap()
Creates a TreeMap with a case-insenstive collator using the US Locale.


isTrue

public static boolean isTrue(java.lang.String arg)
Use this static method to determine if a string represents boolean True. Note that numbers other than one return false.

Returns:
boolean "true" only if value (CASE-INSENSITIVE) is TRUE, T, YES, Y, 1 or ON.

isTrue

public static boolean isTrue(java.lang.Object arg)

isChecked

public static boolean isChecked(java.lang.String value)

formatCheckedValue

public static java.lang.String formatCheckedValue(boolean isTrue)
format the correct checked value for browsers, based on a boolean.


isBlank

public static boolean isBlank(java.lang.String value)
Use this static method to determine if a string represents a blank value. A string such as " " will be determined to be blank on the front end.

Returns:
boolean "true" if value is null or only whitespace.

sleep

public static void sleep(java.lang.Integer millis)

sleep

public static void sleep(long millis)

now

public static java.lang.Long now()
Milliseconds from start time as definded by the Date class.


nowSQL

public static java.sql.Timestamp nowSQL()

nowLocale

public static java.lang.String nowLocale()

dateLongToLocale

public static java.lang.String dateLongToLocale(java.lang.String longdatestr)

dateLongToLocale

public static java.lang.String dateLongToLocale(java.lang.Long longdate)

dateLongToLocale

public static java.lang.String dateLongToLocale(long longdate)

dateLongToLocale

public static java.lang.String dateLongToLocale(java.sql.Timestamp timestamp)

dateToLocale

public static java.lang.String dateToLocale(java.util.Date date)

formatUptime

public static java.lang.String formatUptime(long startTime)

getGMTTimestamp

public static java.lang.String getGMTTimestamp()

getGMTTimestamp

public static java.lang.String getGMTTimestamp(long longTime)

showControlChars

public static java.lang.String showControlChars(java.lang.String inString)
Show all control chars in string, except CRLF.

See Also:
showControlChars(String,boolean)

showControlChars

public static java.lang.String showControlChars(java.lang.String inString,
                                                boolean showCRLF)
Shows all control chars (less than ASCII 32) by converting them to the format #nnn, where nnn is a 1 to 3 digit decimal number. For debugging only, does not encode the character # in any way if found in the string.

Returns:
A copy of the string passed in, with any ASCII control characters converted.

enableIf

public static void enableIf(java.awt.Component[] components,
                            boolean value)
Enables all Components in an array if value parameter is true, else disables them


reverseEnabledIf

public static void reverseEnabledIf(java.awt.Component[] components,
                                    boolean value)
Reverses the enabled state for all Components in an array if value parameter is true, else leaves them alone


makeVisibleIf

public static void makeVisibleIf(java.awt.Component[] components,
                                 boolean value)
Makes all Components in an array visible if value parameter is true, else makes them invisible


reverseVisibleIf

public static void reverseVisibleIf(java.awt.Component[] components,
                                    boolean value)
Reverses the visible state for all Components in an array if value parameter is true, else leaves them alone


setBackground

public static void setBackground(java.awt.Component comp,
                                 java.awt.Color newColor)

readln

public static java.lang.String readln()

readln

public static java.lang.String readln(java.lang.String prompt)

readln

public static java.lang.String readln(java.io.InputStream in)
                               throws java.io.IOException
WARNING: Some unix terminal drivers expect \r as a line end char, although we look for strictly a \n here.

Throws:
java.io.IOException

readln

public static java.lang.String readln(java.io.InputStream in,
                                      int fsType)
                               throws java.io.IOException
fsType is one of FS_UNIX, FS_DOS, FS_MAC

Throws:
java.io.IOException

fileSystemIsDOS

public static boolean fileSystemIsDOS()

fixFilename

public static java.lang.String fixFilename(java.lang.String filename)

copyFile

public static boolean copyFile(java.lang.String sourceFileName,
                               java.lang.String destFileName)
Copy a binary source file to a destination file. Filenames are platform dependent. Returns true for copying a zero byte file. Returns true if the file copy was succesful.


openFile

public static java.io.File openFile(java.lang.String dir,
                                    java.lang.String relPath)

readFile

public static java.lang.String readFile(java.lang.String fullPath)

readFile

public static java.lang.String readFile(java.lang.String dir,
                                        java.lang.String relPath)

saveFile

public static java.io.File saveFile(java.lang.String dir,
                                    java.lang.String relativeName,
                                    java.lang.String content)

readFileToVector

public static java.util.Vector readFileToVector(java.lang.String dir,
                                                java.lang.String relPath)
Doesn't throw any exceptions: returns null if the file was not found, etc.


saveVectorToFile

public static java.io.File saveVectorToFile(java.util.Vector vector,
                                            java.lang.String delim,
                                            java.lang.String dir,
                                            java.lang.String relPath)
Returns:
the File object of the saved file, or null if there was an error.

readIniFile

public static java.util.Vector readIniFile(java.lang.String dir,
                                           java.lang.String relPath)

readIniFile

public static java.util.Vector readIniFile(java.lang.String filename)

saveIniFile

public static java.io.File saveIniFile(java.util.Vector iniValues,
                                       java.lang.String dir,
                                       java.lang.String relPath)

saveIniFile

public static java.io.File saveIniFile(java.util.Vector iniValues,
                                       java.lang.String filename)

getIniValueInt

public static int getIniValueInt(java.util.Vector iniValues,
                                 java.lang.String section,
                                 java.lang.String key,
                                 int defaultValue)

getIniValueBoolean

public static boolean getIniValueBoolean(java.util.Vector iniValues,
                                         java.lang.String section,
                                         java.lang.String key,
                                         boolean defaultValue)

getIniValue

public static java.lang.String getIniValue(java.lang.String iniFile,
                                           java.lang.String section,
                                           java.lang.String key,
                                           java.lang.String defaultValue)

getIniValue

public static java.lang.String getIniValue(java.lang.String directory,
                                           java.lang.String iniFile,
                                           java.lang.String section,
                                           java.lang.String key,
                                           java.lang.String defaultValue)

getIniValue

public static java.lang.String getIniValue(java.util.Vector iniValues,
                                           java.lang.String section,
                                           java.lang.String key,
                                           java.lang.String defaultValue)
Parameters:
section - Use 'null' to ignore section names, scanning all sections, or if section names are not used in the file.

setIniValue

public static void setIniValue(java.util.Vector iniValues,
                               java.lang.String section,
                               java.lang.String key,
                               java.lang.String value)

printStackTrace

public static void printStackTrace()

getStackTrace

public static java.lang.String getStackTrace()

getStackTrace

public static java.lang.String getStackTrace(java.lang.Throwable t)

getStackTraceWithMessage

public static java.lang.String getStackTraceWithMessage(java.lang.Throwable e)

errorToString

public static java.lang.String errorToString(java.lang.Throwable e,
                                             boolean stackTraceOnException)
Takes an Exception object and formats a message that provides more debug information suitable for developers for printing to System.out or for logging. Not suitable for presentation of error messages to clients.


errorToString

public static java.lang.String errorToString(java.lang.Throwable e,
                                             boolean stackTraceOnException,
                                             boolean showmsg)

isJVM13

public static boolean isJVM13()

isJVM14

public static boolean isJVM14()

cleanAndReportMemory

public static java.lang.String cleanAndReportMemory()

cleanAndReportMemory

public static java.lang.String cleanAndReportMemory(long millis)

dump

public static java.lang.String dump(java.util.Map map)

dump

public static java.lang.String dump(java.util.Map map,
                                    java.lang.String lineBreak)

dumpHTML

public static java.lang.String dumpHTML(java.util.Map map)

dump

public static java.lang.String dump(java.util.Map map,
                                    java.lang.String start,
                                    java.lang.String lineSeparator,
                                    java.lang.String elementSeparator,
                                    java.lang.String objectPlaceholder,
                                    java.lang.String end,
                                    boolean dumphtml)


Copyright © 2001-2013 DYNAMIDE.COM. All Rights Reserved.