org.safs.tools.stringutils
Class StringUtilities

java.lang.Object
  extended by org.safs.tools.stringutils.StringUtilities

public abstract class StringUtilities
extends java.lang.Object


Field Summary
static java.lang.String DATE_FORMAT_a
           
static java.lang.String DATE_FORMAT_AM_PM_DATE_TIME
           
static java.lang.String DATE_FORMAT_AM_PM_TIME
           
static java.lang.String DATE_FORMAT_DATE
           
static java.lang.String DATE_FORMAT_MILITARY_DATE_TIME
           
static java.lang.String DATE_FORMAT_MILITARY_TIME
           
static java.lang.String FILE_TIME_BASE
           
static java.lang.String JAVA_TIME_BASE
           
static java.lang.String TIME_OF_AM
           
static java.lang.String TIME_OF_PM
           
static long TimeBaseDifferenceFromFileTimeToJavaTimeInMillisecond
           TimeBaseDifferenceFromFileTimeToJavaTimeInMillisecond contains the difference from filetime to javatime in millisecond, it is initialized in the static code of this class.
 
Constructor Summary
StringUtilities()
           
 
Method Summary
static boolean charIsInRange(char c, int beg, int end)
          Method charIsInRange.
static boolean convertBool(java.lang.String bool)
          Returns a boolean value based on value of bool.
static java.lang.Integer convertToInteger(java.lang.String value)
           
static java.lang.String findAndReplace(java.lang.String input, java.lang.String search, java.lang.String replace)
          Replace all instances of search string with the replace string.
static java.awt.Rectangle formRectangle(java.lang.String rectangleString, java.lang.String separator)
           
static java.util.Date getDate(java.lang.String date, java.lang.String dateFormat)
          Note According to the dateFormat, use the SimpleDateFormat to convert a string to java.util.Date
static java.lang.String getDateString(java.util.Date date)
          Note With dateFormat "MM-dd-yyyy", use the SimpleDateFormat to convert the date object to string
static java.lang.String getDateString(java.util.Date date, java.lang.String dateFormat)
          Note According to the dateFormat, use the SimpleDateFormat to convert the date object to string
static java.lang.String getDateTimeString(java.util.Date date, boolean isMilitary)
          Note Use the SimpleDateFormat to convert the date object to string, keep both the date and the time part
static int getNumSubstrings(java.lang.String strSub, java.lang.String strText)
          Method getNumSubstrings.
static java.util.Vector getSubStrings(java.lang.String strText)
          Method getSubStrings.
static java.util.Vector getSubStrings(java.lang.String strText, java.util.Vector vQuoteLocs)
          Method getSubStrings.
static java.lang.String getTimeString(java.util.Date date, boolean isMilitary)
          Note Use the SimpleDateFormat to convert the date object to string, just keep the time part
static boolean isLegalVarName(java.lang.String strVarName)
          Method isLegalVarName.
static boolean isQuoted(java.lang.String strText, int location)
          Method isQuoted.
static boolean isQuoted(java.lang.String strText, int location, java.util.Vector vQuoteLocs)
          Method isQuoted.
static boolean isValidNonStdChar(char c)
          Method isValidNonStdChar.
static int locateNextNonWhiteSpace(java.lang.String strSearch, int ipos)
          Method locateNextNonWhiteSpace.
static int locateNextSubstring(java.lang.String strSearch, java.lang.String strFind, int ipos)
          Method locateNextSubstring.
static int locateNextUnquotedNonWhiteSpace(java.lang.String strSearch, int ipos)
          Method locateNextUnquotedNonWhiteSpace.
static int locateNextUnquotedSingleChar(java.lang.String strSearch, java.lang.String strChars, int ipos)
          Method locateNextUnquotedSingleChar.
static int locateNextUnquotedSingleChar(java.lang.String strSearch, java.lang.String strChars, int ipos, java.util.Vector vQuoteLocs)
          Method locateNextUnquotedSingleChar.
static int locateNextUnquotedSubstring(java.lang.String strSearch, java.lang.String strFind, int ipos)
          Method locateNextUnquotedSubstring.
static int locateNextUnquotedSubstring(java.lang.String strSearch, java.lang.String strFind, int ipos, java.util.Vector vQuoteLocs)
          Method locateNextUnquotedSubstring.
static java.util.Vector locateQuotedSubStrings(java.lang.String strText)
          Method locateQuotedSubStrings.
static java.lang.String LTWhitespace(java.lang.String strValue)
          Method LTWhitespace.
static void main(java.lang.String[] args)
           
static boolean nextCharIsDQ(java.lang.String strText, int location)
          Method nextCharIsDQ.
static java.lang.String removeAllNonQuotedWhitespace(java.lang.String strValue)
          Method removeAllNonQuotedWhitespace.
static java.lang.String removeAllNonQuotedWhitespace(java.lang.String strValue, java.util.Vector vQuoteLocs)
          Method removeAllNonQuotedWhitespace.
static java.lang.String removeDoubleQuotes(java.lang.String original)
          Remove any leading and\or trailing double quotes.
static java.lang.String removePrefix(java.lang.String original, java.lang.String prefix)
          Remove the prefix from the original string, and return the result
static java.lang.String removeRelativeFilePathPrefix(java.lang.String relativepath)
          Attempts to remove ".\", "./", "\", or "/" relative path prefixes from the provided String.
static java.lang.String removeSuffix(java.lang.String original, java.lang.String suffix)
          Remove the suffix from the original string, and return the result
static java.lang.String replaceString(java.lang.String strSearch, java.lang.String strReplace, int ibegin, int iend)
          Method replaceString.
static java.lang.String reverse(java.lang.String s)
          Method reverse.
static java.lang.String RTWhitespace(java.lang.String strValue)
          Method RTWhitespace.
static java.lang.String spacePad(int ipad)
          Method spacePad.
static java.lang.String TWhitespace(java.lang.String strValue)
          Method TWhitespace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATE_FORMAT_DATE

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

DATE_FORMAT_MILITARY_TIME

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

DATE_FORMAT_MILITARY_DATE_TIME

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

DATE_FORMAT_AM_PM_TIME

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

DATE_FORMAT_AM_PM_DATE_TIME

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

DATE_FORMAT_a

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

TIME_OF_AM

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

TIME_OF_PM

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

JAVA_TIME_BASE

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

FILE_TIME_BASE

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

TimeBaseDifferenceFromFileTimeToJavaTimeInMillisecond

public static long TimeBaseDifferenceFromFileTimeToJavaTimeInMillisecond
 TimeBaseDifferenceFromFileTimeToJavaTimeInMillisecond contains the difference from 
 filetime to javatime in millisecond, it is initialized in the static code of this class.
 
 FileTime is a class defined in org.safs.natives.win32.Kernel32
 FileTime contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC/GMT).
 FileTime's unit: 100 nanosecond
 FileTime's base: January 1, 1601 00:00:00 (UTC/GMT)

 JavaTime represents a point in time that is time milliseconds after January 1, 1970 00:00:00 (UTC/GMT).
 JavaTime's unit: millisecond
 JavaTime's base: January 1, 1970 00:00:00 (UTC/GMT)
 
 1, 000, 000 nanoseconds = 1 millisecond
 
 As the unit and the base-time are different for FileTime and JavaTime, a conversion is needed.
 
 How to convert?
 Convert from FileTime to JavaTime:
 javatime = filetime/10000 - TimeBaseDifferenceFromFileTimeToJavaTimeInMillisecond
 
 Convert from JavaTime to FileTime:
 filetime = (javatime+TimeBaseDifferenceFromFileTimeToJavaTimeInMillisecond)*10000
 

See Also:
Kernel32.FileTime, NativeWrapper.convertFileTimeToJavaTime(org.safs.natives.win32.Kernel32.FileTime), JAVA_TIME_BASE, FILE_TIME_BASE, DATE_FORMAT_MILITARY_DATE_TIME
Constructor Detail

StringUtilities

public StringUtilities()
Method Detail

LTWhitespace

public static java.lang.String LTWhitespace(java.lang.String strValue)
Method LTWhitespace. Remove whitespace (space and tab chars) from start of strings

Parameters:
strValue - String to remove leading whitespace (space and tab)
Returns:
strValue without leading whitespace

RTWhitespace

public static java.lang.String RTWhitespace(java.lang.String strValue)
Method RTWhitespace. Remove whitespace (space and tab chars) from end of strings

Parameters:
strValue - String to remove trailing whitespace (space and tab)
Returns:
strValue without trailing whitespace

TWhitespace

public static java.lang.String TWhitespace(java.lang.String strValue)
Method TWhitespace. Remove whitespace (space and tab chars) from start and end of strings

Parameters:
strValue - String to remove whitespace (space and tab)
Returns:
strValue without leading or trailing whitespace

charIsInRange

public static boolean charIsInRange(char c,
                                    int beg,
                                    int end)
Method charIsInRange. Return boolean T/F specifying wheather char is numerically between integers beg and end. ( c >= beg && c <= end )

Parameters:
c - character to check
beg - lower end of range
end - higher end of range
Returns:
boolean

getNumSubstrings

public static int getNumSubstrings(java.lang.String strSub,
                                   java.lang.String strText)
Method getNumSubstrings. Returns the number of occurances of strSub within strText as an integer

Parameters:
strSub - substring to count occurances
strText - string to search for strSub occurances
Returns:
int

nextCharIsDQ

public static boolean nextCharIsDQ(java.lang.String strText,
                                   int location)
Method nextCharIsDQ. Return boolean T/F specifying wheather or not the character in strText at location+1 is a double quote (")

Parameters:
strText - String to check
location - int location to start check
Returns:
boolean

locateQuotedSubStrings

public static java.util.Vector locateQuotedSubStrings(java.lang.String strText)
Method locateQuotedSubStrings. Return a Vector that contains Integer objects whose intValue specifies the location of a double quote (") in strText. Note that double quotes must be paired so there should be an even number of Integer objects withing the returned Vector.

Parameters:
strText - String in which to locate the quoted substrings
Returns:
Vector

isQuoted

public static boolean isQuoted(java.lang.String strText,
                               int location)
Method isQuoted. Return boolean T/F specifying wheather or not the string within strText at int location is quoted (within double quotes)

Parameters:
strText - String to check
location - Location to check
Returns:
boolean

isQuoted

public static boolean isQuoted(java.lang.String strText,
                               int location,
                               java.util.Vector vQuoteLocs)
Method isQuoted. Return boolean T/F specifying wheather or not the string within strText at int location is quoted (within double quotes)

Parameters:
strText - String to check
location - Location to check
vQuoteLocs - Vector containing Integer objects whose intValue specifies the location of a double quote (") in strText.
Returns:
boolean

getSubStrings

public static java.util.Vector getSubStrings(java.lang.String strText)
Method getSubStrings. Return a Vector containing String objects that are quoted substrings within strText

Parameters:
strText - The string to find substrings
Returns:
Vector

getSubStrings

public static java.util.Vector getSubStrings(java.lang.String strText,
                                             java.util.Vector vQuoteLocs)
Method getSubStrings. Return a Vector containing String objects that are quoted substrings within strText

Parameters:
strText - The string to find substrings
vQuoteLocs - Vector containing Integer objects whose intValue specifies the location of a double quote (") in strText.
Returns:
Vector

locateNextUnquotedNonWhiteSpace

public static int locateNextUnquotedNonWhiteSpace(java.lang.String strSearch,
                                                  int ipos)
Method locateNextUnquotedNonWhiteSpace. Return an int containing the location in strSearch after ipos where the first non-quoted, non-whitespace character is

Parameters:
strSearch -
ipos -
Returns:
int

locateNextNonWhiteSpace

public static int locateNextNonWhiteSpace(java.lang.String strSearch,
                                          int ipos)
Method locateNextNonWhiteSpace. Return an int containing the location in strSearch after ipos where the first non whitespace character is

Parameters:
strSearch -
ipos -
Returns:
int

locateNextUnquotedSingleChar

public static int locateNextUnquotedSingleChar(java.lang.String strSearch,
                                               java.lang.String strChars,
                                               int ipos)
Method locateNextUnquotedSingleChar. Return the integer location within strSearch that is first occurance of any of the characters making up strChars

Parameters:
strSearch - The string to search
strChars - A string consisting of single characters to find the first occurance of
ipos - int position within strSearch to begin search
Returns:
int

locateNextUnquotedSingleChar

public static int locateNextUnquotedSingleChar(java.lang.String strSearch,
                                               java.lang.String strChars,
                                               int ipos,
                                               java.util.Vector vQuoteLocs)
Method locateNextUnquotedSingleChar. Return the integer location within strSearch that is first occurance of any of the characters making up strChars

Parameters:
strSearch - The string to search
strChars - A string consisting of single characters to find the first occurance of
ipos - int position within strSearch to begin search
vQuoteLocs - Vector containing Integer objects whose intValue specifies the location of a double quote (") in strText.
Returns:
int

locateNextUnquotedSubstring

public static int locateNextUnquotedSubstring(java.lang.String strSearch,
                                              java.lang.String strFind,
                                              int ipos)
Method locateNextUnquotedSubstring. Return the integer location within strSearch that is first occurance of substring strFind

Parameters:
strSearch - The string to search
strFind - The substring to search for
ipos - int position within strSearch to begin search
Returns:
int

locateNextUnquotedSubstring

public static int locateNextUnquotedSubstring(java.lang.String strSearch,
                                              java.lang.String strFind,
                                              int ipos,
                                              java.util.Vector vQuoteLocs)
Method locateNextUnquotedSubstring. Return the integer location within strSearch that is first occurance of substring strFind

Parameters:
strSearch - The string to search
strFind - The substring to search for
ipos - int position within strSearch to begin search
vQuoteLocs - Vector containing Integer objects whose intValue specifies the location of a double quote (") in strText.
Returns:
int

locateNextSubstring

public static int locateNextSubstring(java.lang.String strSearch,
                                      java.lang.String strFind,
                                      int ipos)
Method locateNextSubstring. Return the integer location within strSearch that is first occurance of substring strFind

Parameters:
strSearch - The string to search
strFind - The substring to search for
ipos - int position within strSearch to begin search
Returns:
int

removeAllNonQuotedWhitespace

public static java.lang.String removeAllNonQuotedWhitespace(java.lang.String strValue)
Method removeAllNonQuotedWhitespace. Return a String that is strValue with all non quoted whitespace (space and tab) removed. (keeps whitespace between double quotes)

Parameters:
strValue - The string to remove non-quoted whitespace
Returns:
String

removeAllNonQuotedWhitespace

public static java.lang.String removeAllNonQuotedWhitespace(java.lang.String strValue,
                                                            java.util.Vector vQuoteLocs)
Method removeAllNonQuotedWhitespace. Return a String that is strValue with all non quoted whitespace (space and tab) removed. (keeps whitespace between double quotes)

Parameters:
strValue - The string to remove non-quoted whitespace
vQuoteLocs - Vector containing Integer objects whose intValue specifies the location of a double quote (") in strText.
Returns:
String

replaceString

public static java.lang.String replaceString(java.lang.String strSearch,
                                             java.lang.String strReplace,
                                             int ibegin,
                                             int iend)
Method replaceString. Return a strSearch with strReplace inserted over the locations from ibegin to iend

Parameters:
strSearch - The string to search
strReplace - The replacement string
ibegin - int location to begin replacement
iend - int location to end replacement
Returns:
String

reverse

public static java.lang.String reverse(java.lang.String s)
Method reverse. Return string s with the characters making it up from right to left

Parameters:
s - The string to reverse
Returns:
String

isLegalVarName

public static boolean isLegalVarName(java.lang.String strVarName)
Method isLegalVarName. Return a boolean T/F specifying wheather or not strVarName is a legal variable name within SAFS

Parameters:
strVarName - The variable name to test
Returns:
boolean

isValidNonStdChar

public static boolean isValidNonStdChar(char c)
Method isValidNonStdChar. Return boolean T/F specifying wheather or not the char c is a valid non standard character for SAFS variable names

Parameters:
c - The char to test
Returns:
boolean

findAndReplace

public static java.lang.String findAndReplace(java.lang.String input,
                                              java.lang.String search,
                                              java.lang.String replace)
Replace all instances of search string with the replace string. This is for pre-Java 1.4


spacePad

public static java.lang.String spacePad(int ipad)
Method spacePad. Returns a string consisting of spaces of length ipad

Parameters:
ipad -
Returns:
String

convertBool

public static boolean convertBool(java.lang.String bool)
Returns a boolean value based on value of bool. Returns true if bool is "YES", "TRUE", "ON", "1" or "-1". Uses bool.equalsIgnoreCase...

Parameters:
bool -
Returns:
boolean

removeRelativeFilePathPrefix

public static java.lang.String removeRelativeFilePathPrefix(java.lang.String relativepath)
Attempts to remove ".\", "./", "\", or "/" relative path prefixes from the provided String. Does not alter the path if File.isAbsolute returns TRUE.

Example:

".\Datapool\Filename.ext" returns "Datapool\Filename.ext"

Parameters:
relativepath - String filepath to strip of leading relative path prefix characters.
Returns:
the String stripped of any relative path prefix characters, if any. Returns null if the provided String is null. Returns an empty String if the provided String is empty.

removePrefix

public static java.lang.String removePrefix(java.lang.String original,
                                            java.lang.String prefix)
Remove the prefix from the original string, and return the result

Example:

original = "^filename=c:\file.txt" , prefix="^filename=" the result will be "c:\file.txt"

Parameters:
original -
prefix -
Returns:

removeSuffix

public static java.lang.String removeSuffix(java.lang.String original,
                                            java.lang.String suffix)
Remove the suffix from the original string, and return the result

Example:

original = "^filename=c:\file.txt" , suffix="=c:\file.txt" the result will be "^filename"

Parameters:
original -
suffix -
Returns:

removeDoubleQuotes

public static java.lang.String removeDoubleQuotes(java.lang.String original)
Remove any leading and\or trailing double quotes.

Example:

original = "c:\file.txt" (with quotes) the result will be 'c:\file.txt' (no quotes at all)

Parameters:
original -
Returns:

convertToInteger

public static java.lang.Integer convertToInteger(java.lang.String value)
                                          throws SAFSException
Parameters:
value - A string represents an integer value.
Returns:
An integer converted from string
Throws:
SAFSException

formRectangle

public static java.awt.Rectangle formRectangle(java.lang.String rectangleString,
                                               java.lang.String separator)
Parameters:
rectangleString - A string represent a rectangle: x, y , widht, height.
separator - The separator in rectangleString to separate x y width and height
Returns:
A java Rectangle object, constructed by rectangleString

getDateString

public static java.lang.String getDateString(java.util.Date date,
                                             java.lang.String dateFormat)
Note According to the dateFormat, use the SimpleDateFormat to convert the date object to string

Parameters:
date - A java.util.Date object
dateFormat - A string represents the date format pattern of SimpleDateFormat
Returns:
A string represents the Date object

getDateString

public static java.lang.String getDateString(java.util.Date date)
Note With dateFormat "MM-dd-yyyy", use the SimpleDateFormat to convert the date object to string

Parameters:
date - A java.util.Date object
Returns:
A string represents the Date object's date part

getTimeString

public static java.lang.String getTimeString(java.util.Date date,
                                             boolean isMilitary)
Note Use the SimpleDateFormat to convert the date object to string, just keep the time part

Parameters:
date - A java.util.Date object
isMilitary - A boolean, if true, convert to a military time (24 hours format)
Returns:
A string represents the Date object's time part

getDateTimeString

public static java.lang.String getDateTimeString(java.util.Date date,
                                                 boolean isMilitary)
Note Use the SimpleDateFormat to convert the date object to string, keep both the date and the time part

Parameters:
date - A java.util.Date object
isMilitary - A boolean, if true, convert to a military time (24 hours format)
Returns:
A string represents the Date object

getDate

public static java.util.Date getDate(java.lang.String date,
                                     java.lang.String dateFormat)
Note According to the dateFormat, use the SimpleDateFormat to convert a string to java.util.Date

Parameters:
date - A string represents a date.
dateFormat - A string represents the date format pattern of SimpleDateFormat
Returns:
A java.util.Date object

main

public static void main(java.lang.String[] args)