Class UtilCM

java.lang.Object
  extended by UtilCM

public class UtilCM
extends java.lang.Object

Collection of utility functions used by various other classes.

 List of Methods
 clearDebugNameValuePairs() - clear DEBUG (name,value) list
 setDebugNameValue() - set DEBUG (name,value) pair.
 testDebugValue - test if str is indexOf() value if name is debug(name,value).
 testDebugValue - test DEBUG value is indexOf(str) if name is debug(name,value).
 logMsg() - print a message
 setReportTextArea() - assign report text area in popup report GUI window
 setReportStatusLineTextField() - assign report status line GUI text field
 setReportStatusLineLabel() - assign report status line label in GUI
 appendPRmsg() - append message to  report text area in GUI window
 updateReportStatusLine() - set status line message if text field in GUI
 dateStr() - return the current date stamp
 timeStr() - return the current time stamp
 getCurTimeStr() - return current time string in the format of HHMMSS.
 mapCRLF2space() - map CRLFs in the string to spaces
 mapCRLForCR2LF() - map all CRLF or CR(not LF) to LF
 mapComma2Tab() - map "," to "\t" in the string
 mapIllegalChars() - map illegal characters to '_'
 mapSpaceToMinus() - map " " to "-"
 removeQuotes() - remove '\"' characters from string
 isEmptyArray() - test if array consists of empty data elements
 isNumber() - test if a string is a number (i.e., Double)
 cvf2s() - convert float to string with precision  # of digits
 cvd2s() - convert double to string with precision  # of digits
 cvs2d() - convert String to double
 cvs2f() - convert String to float
 cvs2i() - convert String to int
 cvs2long() - convert String to long
 cvb2s() - convert boolean String
 cvs2l() - convert String to long
 cvs2b() - convert String to boolean 
 cvs2ArrayNullFill() - cvt arg list "1,4,3,6,..."  to "," fill nulls.
 cvs2Array() - cvt arg list "1,4,3,6,..."  to "," - delim String[]. 
 rightSizeArray() - extend or shrink an array to requiredSize.
 cloneString() - clone a copy of a String array
 lookupDataIdx() - lookup index of element if exists in a strData[].
 isListInAnotherList() - test if all listA in listB order independent.
 mapAllkeywords() - map data from 'keyword' to 'toString' lists.
 rmvRtnChars() - remove return chars. Map '\r' or "\r\n" to '\n' chars. 
 rmvSpecifiedChar() - remove specified character from string.
 rmvEnclosingWhitespace() - remove enclosing whitespace from string
 trimArrayEnclWhitespace() - trim (clean) enclosing white space in 1D array.
 removeEmptyStringsFromArray() - remove nulls and empty Strings in 1D array.
 getCleanArgList() - convert string arg list delimited by "", "," or "\n" to array
 replaceSpaceWithCommaSpaceDelim() - replace " "-delimited list with ", " list 
 replaceSubstrInString() - recursively replace oldToken w/newToken in str
 changeWorkingDirectory() - change the working directory
 cvDeltaTime2str() - convert a delta epoch time msec to a string
 off_timer() - Compute the time banner String 
 on_timer() - Get the current time (in milliseconds)
 sleepMsec() - sleep for mSec.
 appendElementToArray() - Append String element to String array.  
 startsWithIgnoreCase() - test if str starts with startStr ignoring case
 endsWithIgnoreCase() - test if str ends with endsStr ignoring case
 indexOfIgnoreCase() - indexOf subStr of str ignoring case.
 cvtHTMLcolorNameToHex() - map HTML color name to HEX value string
 updateJarFile() - update .jar file from URL into program install area.
 copyFile() - binary copy of one file or URL to a local file
 readBytesFromURL() - read binary data from URL into byte[] array.
 deleteLocalFile() - delete local file.
 

This code is available at the HTMLtools project on SourceForge at http://htmltools.sourceforge.org/ under the "Common Public License Version 1.0" http://www.opensource.org/licenses/cpl1.0.php.

It was derived and refactored from the open source MAExplorer (http://maexplorer.sourceforge.org/), and Open2Dprot (http://Open2Dprot.sourceforge.net/) Table modules.

$Date: 2009/11/26 11:45:56 $ $Revision: 1.38 $
Copyright 2008, 2009 by Peter Lemkin E-Mail: lemkin@users.sourceforge.net http://lemkingroup.com/


Field Summary
static java.lang.String[] debugName
          Name list for Debug facility of (name,value) pairs
static java.lang.String[] debugValue
          Value list for Debug facility of (name,value) pairs
static float defaultFloat
          Default value of float for cvs2f() calls
static int defaultInt
          Default value of int for cvs2i() calls
static boolean loggingFlag
          Local logging flag.
static java.lang.String loggingStr
          logging String if loggingFlag enabled
static int MAX_DEBUGS
          Maximum number of debug(name,value) pairs
static int nDebugPairs
          Current number of debug(name,value) pairs
static PopupTextViewer ptViewer
          Optional Big Report PopupTextViewer text area will output appendPRmsg if not null.
static javax.swing.JLabel rptStatusLineLabel
          Report Label will output updateReportStatusLine if not null.
static javax.swing.JTextField rptStatusLineTextField
          Report text field will output updateReportStatusLine if not null.
static javax.swing.JTextArea rptTextArea
          Report text area will output appendPRmsg if not null.
 
Constructor Summary
UtilCM()
          UtilCM() - constructor for setup utility pkg for additional UtilCM instances.
UtilCM(boolean loggingFlag)
          UtilCM() - constructor for setup utility pkg
 
Method Summary
static java.lang.String[] appendElementToArray(java.lang.String[] sArray, java.lang.String sElement)
          appendElementToArray() - Append String element to String array.
static void appendPRmsg(java.lang.String msg)
          appendPRmsg() - append message to report text area in GUI window if it exists.
static java.lang.String changeWorkingDirectory(java.lang.String newDir)
          changeWorkingDirectory() - change the working directory
static void clearDebugNameValuePairs()
          clearDebugNameValuePairs() - clear DEBUG (name,value) list
static java.lang.String[] cloneString(java.lang.String[] strArray)
          cloneString() - clone a copy of a String array
static boolean copyFile(java.lang.String srcName, java.lang.String dstName, java.lang.String optUpdateMsg, int optEstInputFileLth)
          copyFile() - binary copy of one file or URL to a local file
static java.lang.String cvb2s(boolean b)
          cvb2s() - convert boolean String
static java.lang.String cvd2s(double v, int precision)
          cvd2s() - convert double to string with precision # of digits If precision > 0 then limit # of digits in fraction
static java.lang.String cvDeltaTime2str(long deltaTimeMsec, boolean fullCvtFlag)
          cvDeltaTime2str() - convert a delta epoch time msec to a string "00:01:30 (H:M:S) or 90.0 seconds"
static java.lang.String cvf2s(float v, int precision)
          cvf2s() - convert float to string with precision # of digits If precision > 0 then limit # of digits in fraction
static java.lang.String[] cvs2Array(java.lang.String str, java.lang.String delimChr)
          cvs2Array() - cvt arg list "1,4,3,6,..." to "," - delim String[].
static java.lang.String[] cvs2ArrayNullFill(java.lang.String str, java.lang.String delimChr, java.lang.String nullFillStr)
          cvs2ArrayNullFill() - cvt arg list "1,4,3,6,..." to "," fill nulls.
static boolean cvs2b(java.lang.String str, boolean defaultBool)
          cvs2b() - convert String to boolean
static double cvs2d(java.lang.String str)
          cvs2d() - convert String to double
static float cvs2f(java.lang.String str)
          cvs2f() - convert String to float
static float cvs2f(java.lang.String str, float defVal)
          cvs2f() - convert String to float
static int cvs2i(java.lang.String str)
          cvs2i() - convert String to int
static int cvs2i(java.lang.String str, int defVal)
          cvs2i() - convert String to int
static long cvs2l(java.lang.String str, long defaultLong)
          cvs2l() - convert String to long
static long cvs2long(java.lang.String str)
          cvs2long() - convert String to long
static java.lang.String cvtHTMLcolorNameToHex(java.lang.String cName)
          cvtHTMLcolorNameToHex() - map HTML color name to HEX value string Names allowed are the 16 colors in version 5 HTML standard.
static java.lang.String dateStr()
          dateStr() - return a new Date string of the current day and time
static boolean deleteLocalFile(java.lang.String fileName)
          deleteLocalFile() - delete local file.
static boolean endsWithIgnoreCase(java.lang.String str, java.lang.String endsStr)
          endsWithIgnoreCase() - test if str ends with endsStr ignoring case
static java.lang.String[] getCleanArgList(java.lang.String strArg)
          getCleanArgList() - convert string arg list delimited by "", "," or "\n" to array Remove blank args.
static java.lang.String getCleanSpaceList(java.lang.String strArg)
          getCleanSpaceList() - cvt str list delim by " ", ",", "\t", "\n" to " " delim str Standardize to space delimited row of symbols map commas, tabs, "\n" and multiple spaces to single space
static java.lang.String getCurTimeStr()
          getCurTimeStr() - return current time string in the format of HHMMSS.
static java.lang.String getDebugValue(java.lang.String name)
          getDebugValue - get value if name is a debug(name,value), else "".
static java.lang.String getLogMsgs()
          getLogMsgs() - return the logging string
static int indexOfIgnoreCase(java.lang.String str, java.lang.String subStr)
          indexOfIgnoreCase() - indexOf subStr of str ignoring case.
static boolean isEmptyArray(java.lang.String[] sList)
          isEmptyArray() - test if array consists of empty data elements
static boolean isListInAnotherList(java.lang.String[] listA, int lthA, java.lang.String[] listB, int lthB)
          isListInAnotherList() - test if all listA in listB order independent.
static boolean isNumber(java.lang.String str)
          isNumber() - test if a string is a number (i.e., Double)
static void logMsg(java.lang.String msg)
          logMsg() - log the message.
static int lookupDataIdx(java.lang.String field, java.lang.String[] strData, int strDataLth)
          lookupDataIdx() - lookup index of element if exists in a strData[].
static java.lang.String mapAllkeywords(java.lang.String str, java.lang.String[] keyList, java.lang.String[] toStrList, int nMaps)
          mapAllkeywords() - map data from 'keyword' to 'toString' lists.
static java.lang.String mapComma2Tab(java.lang.String s)
          mapComma2Tab() - map "," to "\t" in the string
static java.lang.String mapCRLF2space(java.lang.String s)
          mapCRLF2space() - map "\r\n" or "\n\r" or "\r" or '\n' to a single " " in the string.
static java.lang.String mapCRLForCR2LF(java.lang.String rawData)
          mapCRLForCR2LF() - map all CRLF or CR to LF
(package private) static java.lang.String mapIllegalChars(java.lang.String str)
          mapIllegalChars() - map illegal characters to '_' i.e.
static java.lang.String mapSpaceToMinus(java.lang.String str)
          mapSpaceToMinus() - map " " to "-"
static java.lang.String off_timer(long startT)
          off_timer() - Compute the time banner String assuming that a on_timer(cpuTime,runTime) was done previously.
static long on_timer()
          on_timer() - Get the current time (in milliseconds)
static byte[] readBytesFromURL(java.lang.String srcName, java.lang.String optUpdateMsg)
          readBytesFromURL() - read binary data from URL into byte[] array.
static java.lang.String[] removeEmptyStringsFromArray(java.lang.String[] rowData)
          removeEmptyStringsFromArray() - remove nulls and empty Strings in 1D array.
static java.lang.String removeQuotes(java.lang.String line)
          removeQuotes() - remove '\"' characters from string
static java.lang.String replaceSpaceWithCommaSpaceDelim(java.lang.String str)
          replaceSpaceWithCommaSpaceDelim() - replace " "-delim list with ", " list in the string str.
static java.lang.String replaceSubstrInString(java.lang.String str, java.lang.String oldToken, java.lang.String newToken)
          replaceSubstrInString() - recursively replace oldToken with newToken in the string str.
static java.lang.String[] rightSizeArray(java.lang.String[] strArray, int requiredSize, java.lang.String fillStr)
          rightSizeArray() - extend or shrink an array to requiredSize.
static java.lang.String rmvEnclosingWhitespace(java.lang.String str)
          rmvEnclosingWhitespace() - remove enclosing whitespace (spaces proceeding and following the non-space string.
static java.lang.String rmvRtnChars(java.lang.String str)
          rmvRtnChars() - remove return chars.
static java.lang.String rmvSpecifiedChar(java.lang.String str, char rmvChar)
          rmvSpecifiedChar() - remove specified character from string.
static void setBigReportTextViewer(PopupTextViewer pTxtViewer)
          setBigReportTextViewer() - assign Big report text viewer GUI window
static boolean setDebugNameValue(java.lang.String name, java.lang.String value)
          setDebugNameValue() - set DEBUG (name,value) pair.
static void setLogMsgs(boolean loggingFlag)
          setLogMsgs() - enable/disable logging
static void setReportStatusLineLabel(javax.swing.JLabel rptStatusLineLbl)
          setReportStatusLineLabel() - assign report status line label in GUI in popup report window.
static void setReportStatusLineTextField(javax.swing.JTextField rptStatusLineTxtField)
          setReportStatusLineTextField() - assign report status line GUI text field in popup report window.
static void setReportTextArea(javax.swing.JTextArea rptTxtArea)
          setReportTextArea() - assign report text area in popup report GUI window
static void sleepMsec(int mSec)
          sleepMsec() - sleep for mSec.
static boolean startsWithIgnoreCase(java.lang.String str, java.lang.String startStr)
          startsWithIgnoreCase() - test if str starts with startStr ignoring case
static boolean testDebugValue(java.lang.String dbugName, java.lang.String testValue)
          testDebugValue - test if testValue is indexOf() value if name is debug(name,value).
static java.lang.String timeStr()
          timeStr() - return a new daytime HH:MM:SS string of the current time
static java.lang.String[] trimArrayEnclWhitespace(java.lang.String[] rowData)
          trimArrayEnclWhitespace() - trim (clean) enclosing white space in 1D array.
static boolean updateJarFile(java.lang.String pgmName, java.lang.String urlJarFile, java.lang.String localJarFilePath)
          updateJarFile() - update .jar file from URL into program install area.
static void updateReportStatusLine(java.lang.String msg)
          updateReportStatusLine() - set status line message if text field in GUI and/or Label was assigned.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultInt

public static int defaultInt
Default value of int for cvs2i() calls


defaultFloat

public static float defaultFloat
Default value of float for cvs2f() calls


loggingFlag

public static boolean loggingFlag
Local logging flag. If set, then logMsg() output is also printed to System.out


loggingStr

public static volatile java.lang.String loggingStr
logging String if loggingFlag enabled


rptTextArea

public static volatile javax.swing.JTextArea rptTextArea
Report text area will output appendPRmsg if not null. This is set with setReportTextArea().


ptViewer

public static volatile PopupTextViewer ptViewer
Optional Big Report PopupTextViewer text area will output appendPRmsg if not null. This is set with setBigReportTextViewer().


rptStatusLineTextField

public static volatile javax.swing.JTextField rptStatusLineTextField
Report text field will output updateReportStatusLine if not null. This is set with setReportStatusLineTextField().


rptStatusLineLabel

public static volatile javax.swing.JLabel rptStatusLineLabel
Report Label will output updateReportStatusLine if not null. This is set with setReportStatusLineLabel().


MAX_DEBUGS

public static final int MAX_DEBUGS
Maximum number of debug(name,value) pairs

See Also:
Constant Field Values

nDebugPairs

public static int nDebugPairs
Current number of debug(name,value) pairs


debugName

public static java.lang.String[] debugName
Name list for Debug facility of (name,value) pairs


debugValue

public static java.lang.String[] debugValue
Value list for Debug facility of (name,value) pairs

Constructor Detail

UtilCM

public UtilCM()
UtilCM() - constructor for setup utility pkg for additional UtilCM instances. NOTE: you should call the logging version of the Constructor first or make a call to setLogMsgs that otherwise.

Parameters:
loggingFlag -

UtilCM

public UtilCM(boolean loggingFlag)
UtilCM() - constructor for setup utility pkg

Parameters:
loggingFlag -
Method Detail

clearDebugNameValuePairs

public static void clearDebugNameValuePairs()
clearDebugNameValuePairs() - clear DEBUG (name,value) list


setDebugNameValue

public static boolean setDebugNameValue(java.lang.String name,
                                        java.lang.String value)
setDebugNameValue() - set DEBUG (name,value) pair.

Parameters:
name - of the debug pair.
value - to associate with debug name pair.
Returns:
true if successful
See Also:
getDebugValue(java.lang.String)

getDebugValue

public static java.lang.String getDebugValue(java.lang.String name)
getDebugValue - get value if name is a debug(name,value), else "". or return false it it is not in the debugName[] list.

Parameters:
name - - to test
Returns:
return debug-pair value, else "" if not in debugName[] list.
See Also:
setDebugNameValue(java.lang.String, java.lang.String)

testDebugValue

public static boolean testDebugValue(java.lang.String dbugName,
                                     java.lang.String testValue)
testDebugValue - test if testValue is indexOf() value if name is debug(name,value).

Parameters:
dbugName - - debug name in Debug(name,value) DB to test
testValue - - to test if testValue is indexOf() the corresponding dbugName in the Debug (name,value) list.
Returns:
return true, if value in debug-pair value, else false if not in debugName[] list.
See Also:
setDebugNameValue(java.lang.String, java.lang.String)

setLogMsgs

public static void setLogMsgs(boolean loggingFlag)
setLogMsgs() - enable/disable logging

Parameters:
loggingFlag -

getLogMsgs

public static java.lang.String getLogMsgs()
getLogMsgs() - return the logging string

Returns:
loggingStr

logMsg

public static void logMsg(java.lang.String msg)
logMsg() - log the message.

Parameters:
msg -

setReportTextArea

public static void setReportTextArea(javax.swing.JTextArea rptTxtArea)
setReportTextArea() - assign report text area in popup report GUI window

Parameters:
rptTxtArea - is text area to write appendPRmsg() calls if this is null, then it will not append output to this text area but rather send it to stdout.

setBigReportTextViewer

public static void setBigReportTextViewer(PopupTextViewer pTxtViewer)
setBigReportTextViewer() - assign Big report text viewer GUI window

Parameters:
pTxtViewer - is PopupTextViewer that contains a text area to write appendPRmsg() calls if this is null, then it will not append output to it's text area.

setReportStatusLineTextField

public static void setReportStatusLineTextField(javax.swing.JTextField rptStatusLineTxtField)
setReportStatusLineTextField() - assign report status line GUI text field in popup report window.

Parameters:
rptStatusLineTxtField - is text field to write updateReportStatusLine() calls if this is null, then it will not output this text field but rather send it to stdout.

setReportStatusLineLabel

public static void setReportStatusLineLabel(javax.swing.JLabel rptStatusLineLbl)
setReportStatusLineLabel() - assign report status line label in GUI in popup report window.

Parameters:
rptStatusLineLabel - is label to write updateReportStatusLine() calls if this is null, then it will not output this text field but rather send it to stdout.

appendPRmsg

public static void appendPRmsg(java.lang.String msg)
appendPRmsg() - append message to report text area in GUI window if it exists. Otherwise it send it to stdout. If the dbugConsoleFlag is set, it also sends it to stdout. Scroll to the bottom of the window each time append data.

Parameters:
msg - to display

updateReportStatusLine

public static void updateReportStatusLine(java.lang.String msg)
updateReportStatusLine() - set status line message if text field in GUI and/or Label was assigned.

Parameters:
msg - to display
See Also:
setReportStatusLineTextField(javax.swing.JTextField), setReportStatusLineLabel(javax.swing.JLabel)

dateStr

public static java.lang.String dateStr()
dateStr() - return a new Date string of the current day and time

Returns:
date string

timeStr

public static java.lang.String timeStr()
timeStr() - return a new daytime HH:MM:SS string of the current time

Returns:
time of day string

getCurTimeStr

public static java.lang.String getCurTimeStr()
getCurTimeStr() - return current time string in the format of HHMMSS. This string is sortable. Note: Adds "0" to first single digit if value is 1-9.


mapCRLF2space

public static java.lang.String mapCRLF2space(java.lang.String s)
mapCRLF2space() - map "\r\n" or "\n\r" or "\r" or '\n' to a single " " in the string.

Parameters:
s - input string to map
Returns:
mapped string

mapCRLForCR2LF

public static java.lang.String mapCRLForCR2LF(java.lang.String rawData)
mapCRLForCR2LF() - map all CRLF or CR to LF

Parameters:
rawData - raw data representing string table to analyze
Returns:
mapped string

mapComma2Tab

public static java.lang.String mapComma2Tab(java.lang.String s)
mapComma2Tab() - map "," to "\t" in the string

Parameters:
s - input string to map
Returns:
mapped string

mapIllegalChars

static java.lang.String mapIllegalChars(java.lang.String str)
mapIllegalChars() - map illegal characters to '_' i.e. ' ', '\t', ':', ';', '\"', ',', '\'' '@', '*', '=' to '_'

Parameters:
str - to map
Returns:
String mapped

mapSpaceToMinus

public static java.lang.String mapSpaceToMinus(java.lang.String str)
mapSpaceToMinus() - map " " to "-"

Parameters:
str - to map
Returns:
mapped string

removeQuotes

public static java.lang.String removeQuotes(java.lang.String line)
removeQuotes() - remove '\"' characters from string

Parameters:
line - to check and edit out quotes

isEmptyArray

public static boolean isEmptyArray(java.lang.String[] sList)
isEmptyArray() - test if array consists of empty data elements

Parameters:
sList - is array of data
Returns:
true if the sList is empty or null, false if at least 1 non-empty element

isNumber

public static boolean isNumber(java.lang.String str)
isNumber() - test if a string is a number (i.e., Double)

Parameters:
str - is the string to test if it is a number
Returns:
value of string

cvf2s

public static java.lang.String cvf2s(float v,
                                     int precision)
cvf2s() - convert float to string with precision # of digits If precision > 0 then limit # of digits in fraction

Parameters:
v - is the value to convert
precision - is the # of digits to display
Returns:
string approximating "%0.pd"

cvd2s

public static java.lang.String cvd2s(double v,
                                     int precision)
cvd2s() - convert double to string with precision # of digits If precision > 0 then limit # of digits in fraction

Parameters:
v - is the value to convert
precision - is the # of digits to display
Returns:
string approximating "%0.pd"

cvs2d

public static double cvs2d(java.lang.String str)
cvs2d() - convert String to double

Parameters:
str - is the string to convert to a number
Returns:
value of string

cvs2f

public static float cvs2f(java.lang.String str)
cvs2f() - convert String to float

Parameters:
str - is the string to convert to a number
Returns:
value of string

cvs2f

public static float cvs2f(java.lang.String str,
                          float defVal)
cvs2f() - convert String to float

Parameters:
str - is the string to convert to a number
defVal - is the explicit default value
Returns:
value of string

cvs2i

public static int cvs2i(java.lang.String str)
cvs2i() - convert String to int

Parameters:
str - is the string to convert to a number
Returns:
value of string

cvs2i

public static int cvs2i(java.lang.String str,
                        int defVal)
cvs2i() - convert String to int

Parameters:
str - is the string to convert to a number
defVal - is the explicit default value
Returns:
value of string

cvs2long

public static long cvs2long(java.lang.String str)
cvs2long() - convert String to long

Parameters:
str - is the string to convert to a long number
Returns:
value of string

cvb2s

public static java.lang.String cvb2s(boolean b)
cvb2s() - convert boolean String

Parameters:
b - is boolean input to convert
Returns:
output string as either "true" or "false"

cvs2l

public static long cvs2l(java.lang.String str,
                         long defaultLong)
cvs2l() - convert String to long

Parameters:
str - containing integer to convert to long
Returns:
converted number else defaultLong if illegal number.

cvs2b

public static boolean cvs2b(java.lang.String str,
                            boolean defaultBool)
cvs2b() - convert String to boolean

Parameters:
str - containing either "true" or "false"
Returns:
converted boolean else false if illegal boolean name.

cvs2ArrayNullFill

public static java.lang.String[] cvs2ArrayNullFill(java.lang.String str,
                                                   java.lang.String delimChr,
                                                   java.lang.String nullFillStr)
cvs2ArrayNullFill() - cvt arg list "1,4,3,6,..." to "," fill nulls. Also, if the delimiter is not "\r" remove all "\r"s, and if the delimiter is not "\n" remove all "\n"s. Ignore delimiters within "..." quotes, and don't include the '\"' character in the token. If the nullFillStr is not null, then replace all null strings with the nullFillStr.

Parameters:
str - string containing a list of Strings
delimChr - delimiter to be used
nullFillStr - is the string to replace all null strings if not null.
Returns:
array of Strings else null if problem

cvs2Array

public static java.lang.String[] cvs2Array(java.lang.String str,
                                           java.lang.String delimChr)
cvs2Array() - cvt arg list "1,4,3,6,..." to "," - delim String[]. Also, if the delimiter is not "\r" remove all "\r"s, and if the delimiter is not "\n" remove all "\n"s. Ignore delimiters within "..." quotes, and don't include the '\"' character in the token.

Parameters:
str - string containing a list of Strings
delimChr - delimiter to be used
Returns:
array of Strings else null if problem

rightSizeArray

public static java.lang.String[] rightSizeArray(java.lang.String[] strArray,
                                                int requiredSize,
                                                java.lang.String fillStr)
rightSizeArray() - extend or shrink an array to requiredSize. If it is less than requiredSize and right fill it with fillStr values. If there is no change or the array is larger than the requiredSize, then return the original array. If it is extended, return a new array. If the args are bad, return null.

Parameters:
strArray - - string array
requiredSize - - required size of the array
fillStr - - fillValue if extending an array for new slots
Returns:
extended String array if succeed, null if error.

cloneString

public static java.lang.String[] cloneString(java.lang.String[] strArray)
cloneString() - clone a copy of a String array

Parameters:
strArray - - string array to clone
Returns:
cloned String array if succeed, null if error.

lookupDataIdx

public static int lookupDataIdx(java.lang.String field,
                                java.lang.String[] strData,
                                int strDataLth)
lookupDataIdx() - lookup index of element if exists in a strData[]. Ignore case in the search.

Parameters:
field - to lookup in the strData[]
strData - is array to search
strDataLth - is how far to search in the strData[]. If LEQ 0, assume it is strData.length
Returns:
index if found, else if it does not exist return -1

isListInAnotherList

public static boolean isListInAnotherList(java.lang.String[] listA,
                                          int lthA,
                                          java.lang.String[] listB,
                                          int lthB)
isListInAnotherList() - test if all listA in listB order independent.

Parameters:
listA - - list that must be completely in listB
lthA - - size of listA, else use listA.length if 0
listB - - list to test against
lthB - - size of listB, else use listB.length if 0
Returns:
true if list A is completely in list B, false if not true or there is any error

mapAllkeywords

public static java.lang.String mapAllkeywords(java.lang.String str,
                                              java.lang.String[] keyList,
                                              java.lang.String[] toStrList,
                                              int nMaps)
mapAllkeywords() - map data from 'keyword' to 'toString' lists. Do this for all instances in the mapping list.

Parameters:
str - input string containing possible keywords.
keyList - is list of keywords to look for when map string
toStrList - is list of replacement strings when map string
nMaps - is size of the keyList[] and toStrList[] data
Returns:
true if succeed

rmvRtnChars

public static final java.lang.String rmvRtnChars(java.lang.String str)
rmvRtnChars() - remove return chars. Map '\r' or "\r\n" to '\n' chars.

Parameters:
String - str to process
Returns:
String with '\r' removed.

rmvSpecifiedChar

public static final java.lang.String rmvSpecifiedChar(java.lang.String str,
                                                      char rmvChar)
rmvSpecifiedChar() - remove specified character from string.

Parameters:
str - to process
rmvChar - to remove
Returns:
String with all instances of the specified character removed.

rmvEnclosingWhitespace

public static final java.lang.String rmvEnclosingWhitespace(java.lang.String str)
rmvEnclosingWhitespace() - remove enclosing whitespace (spaces proceeding and following the non-space string. If there is only spaces, leave one. This counts space as white space not tabs or CR or LF. [TODO] could use trim() and save a lot of time...

Parameters:
str - to process
Returns:
String with all enclosing whitespace removed.

trimArrayEnclWhitespace

public static final java.lang.String[] trimArrayEnclWhitespace(java.lang.String[] rowData)
trimArrayEnclWhitespace() - trim (clean) enclosing white space in 1D array. It goes element by element to try to remove white space. If an element is cleaned, it replaces the element string, otherwise the element string is not replaced.

Parameters:
rowData - - row of data. Trim all non-null elements of the array
Returns:
the row with non-null elements trimmed.

removeEmptyStringsFromArray

public static final java.lang.String[] removeEmptyStringsFromArray(java.lang.String[] rowData)
removeEmptyStringsFromArray() - remove nulls and empty Strings in 1D array. It removes "" (empty String) elements and nulls from an array.

Parameters:
rowData - - row of data.
Returns:
the row with non-null elements trimmed.

getCleanArgList

public static final java.lang.String[] getCleanArgList(java.lang.String strArg)
getCleanArgList() - convert string arg list delimited by "", "," or "\n" to array Remove blank args.

Parameters:
strArg - to process
Returns:
String array if succeed with empty args removed.

getCleanSpaceList

public static final java.lang.String getCleanSpaceList(java.lang.String strArg)
getCleanSpaceList() - cvt str list delim by " ", ",", "\t", "\n" to " " delim str Standardize to space delimited row of symbols map commas, tabs, "\n" and multiple spaces to single space

Parameters:
strArg - to process
Returns:
String if succeed with empty args removed.

replaceSpaceWithCommaSpaceDelim

public static final java.lang.String replaceSpaceWithCommaSpaceDelim(java.lang.String str)
replaceSpaceWithCommaSpaceDelim() - replace " "-delim list with ", " list in the string str. It does it in a two stage process using the recursive replaceSubstrInString() by first mapping spaces to "@#$*" and then again to change that to ", ".

Parameters:
str - to process
Returns:
String " "-delimited list with ", "-delim. list, else null if fail.
See Also:
replaceSubstrInString(java.lang.String, java.lang.String, java.lang.String)

replaceSubstrInString

public static final java.lang.String replaceSubstrInString(java.lang.String str,
                                                           java.lang.String oldToken,
                                                           java.lang.String newToken)
replaceSubstrInString() - recursively replace oldToken with newToken in the string str. Call it recursively to get all of the instances.

Parameters:
str - to process
oldToken - to be replaced
newToken - to replace it with
Returns:
String with replaced token, else null if fail.

changeWorkingDirectory

public static java.lang.String changeWorkingDirectory(java.lang.String newDir)
changeWorkingDirectory() - change the working directory

Parameters:
newDir - to change the user.dir to.
Returns:
the new conanocalPath of the directory if succeed, else null

cvDeltaTime2str

public static java.lang.String cvDeltaTime2str(long deltaTimeMsec,
                                               boolean fullCvtFlag)
cvDeltaTime2str() - convert a delta epoch time msec to a string "00:01:30 (H:M:S) or 90.0 seconds"

Parameters:
deltaTimeMsec - is the runtime (end-start) in msec.
fullCvtFlag - to generate a full conversion with H:M:S "00:01:30 (H:M:S) or 90.0 seconds" else generate "90.0 seconds"

off_timer

public static java.lang.String off_timer(long startT)
off_timer() - Compute the time banner String assuming that a on_timer(cpuTime,runTime) was done previously. EXAMPLE: "00:01:30 (H:M:S) or 90.0 seconds"

Parameters:
startT - is the starting times runtime

on_timer

public static long on_timer()
on_timer() - Get the current time (in milliseconds)

Returns:
runtime

sleepMsec

public static void sleepMsec(int mSec)
sleepMsec() - sleep for mSec.

Parameters:
mSec -

appendElementToArray

public static java.lang.String[] appendElementToArray(java.lang.String[] sArray,
                                                      java.lang.String sElement)
appendElementToArray() - Append String element to String array. If the array is null, create the array, else extend it 1 element.

Parameters:
sArray - - is array to append element to.
sElement - to append
Returns:
extended array.

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(java.lang.String str,
                                           java.lang.String startStr)
startsWithIgnoreCase() - test if str starts with startStr ignoring case

Parameters:
str - - string to search
startStr - - substring to see if str starts with this startStr
Returns:
true if it starts with the substring ignoring case.

endsWithIgnoreCase

public static boolean endsWithIgnoreCase(java.lang.String str,
                                         java.lang.String endsStr)
endsWithIgnoreCase() - test if str ends with endsStr ignoring case

Parameters:
str - - string to search
endsStr - - substring to see if str starts with this endsStr
Returns:
true if it starts with the substring ignoring case.

indexOfIgnoreCase

public static int indexOfIgnoreCase(java.lang.String str,
                                    java.lang.String subStr)
indexOfIgnoreCase() - indexOf subStr of str ignoring case.

Parameters:
str - - string to search
subStr - - substring to see if str starts with this endsStr
Returns:
indexOf subStr of str ignoring case.

cvtHTMLcolorNameToHex

public static java.lang.String cvtHTMLcolorNameToHex(java.lang.String cName)
cvtHTMLcolorNameToHex() - map HTML color name to HEX value string Names allowed are the 16 colors in version 5 HTML standard.

Parameters:
cName - color name
Returns:
hex string equivalent name if found, else just return cName.

updateJarFile

public static boolean updateJarFile(java.lang.String pgmName,
                                    java.lang.String urlJarFile,
                                    java.lang.String localJarFilePath)
updateJarFile() - update .jar file from URL into program install area.
 [1] Define directory for .jar path and other file and URL names.
 [2] Backup the old {pgmName}.jar as {pgmName}.jar.bkup
 [3] Open the url: from urlJarFile and read the file from
     the Web into local file {pgmName}+".jar.tmp"
 [4] Move the {pgmName}+".jar.tmp" file into {pgmName}+".jar" in the
     program directory

Parameters:
pgmName - - base name of the program (no extension)
urlJarFile - - full URL for file on the server
localJarFilePath - - full path for the target file
Returns:
true if succeed
See Also:
copyFile(java.lang.String, java.lang.String, java.lang.String, int), deleteLocalFile(java.lang.String)

copyFile

public static boolean copyFile(java.lang.String srcName,
                               java.lang.String dstName,
                               java.lang.String optUpdateMsg,
                               int optEstInputFileLth)
copyFile() - binary copy of one file or URL to a local file

Parameters:
srcName - is either a full path local file name or a http:// prefixed URL string of the source file.
dstName - is the full path of the local destination file name
optUpdateMsg - (opt) will display message in showMsg() and increasing ... in showMsg2(). One '.' for every 10K bytes read. This only is used when reading a URL. Set to null if not used.
optEstInputFileLth - is the estimate size of the input file if known else 0. Used in progress bar.
Returns:
true if succeed.

readBytesFromURL

public static byte[] readBytesFromURL(java.lang.String srcName,
                                      java.lang.String optUpdateMsg)
readBytesFromURL() - read binary data from URL into byte[] array.

Parameters:
srcName - is either a full path local file name or a http:// prefixed URL string of the source file.
optUpdateMsg - (opt) will display message in showMsg() and increasing ... in showMsg2(). One '.' for every 10K bytes read. This only is used when reading a URL. Set to null if not used.
Returns:
a byte[] if succeed, else null.

deleteLocalFile

public static boolean deleteLocalFile(java.lang.String fileName)
deleteLocalFile() - delete local file.

Parameters:
fileName - to delete
Returns:
false if failed..