public abstract class StringUtilities
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
StringUtilities.TestStacktraceCaller |
Modifier and Type | Field and Description |
---|---|
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 int |
SAFS_DEFAULT_START_INDEX
The default start index, it is 1
|
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 and Description |
---|
StringUtilities() |
Modifier and Type | Method and Description |
---|---|
static boolean |
charIsInRange(char c,
int beg,
int end)
Method charIsInRange.
|
static boolean |
convertBool(java.lang.Object bool)
Returns a boolean value based on value of bool.
|
static java.lang.Integer |
convertToInteger(java.lang.String value) |
static java.lang.String |
current(boolean isMilitary) |
static java.lang.String |
debugmsg(boolean fullQualified) |
static java.lang.String |
debugmsg(java.lang.Class<?> clazz,
java.lang.String methodName)
Generate debug message with class name and method name.
|
static java.lang.String |
debugmsg(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.String message)
Generate debug message with class name, method name and message.
|
static java.lang.String |
debugmsg(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.String message,
java.lang.Throwable e)
Generate debug message with class name, method name, detail message and Throwable object.
|
static java.lang.String |
debugmsg(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Throwable e)
Generate debug message with class name, method name and Throwable object.
|
static java.lang.String |
debugmsg(java.lang.Throwable e) |
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 boolean |
getBoolean(java.util.Map<?,?> map,
java.lang.String key)
Get a boolean value from the map according to the key.
If it doesn't exist in map, the SAFSException will be thrown out. |
static java.lang.String |
getCallerClassName(boolean fullQualified) |
static java.lang.String |
getCallerID(boolean fullQualified)
Get my caller's id, which is a string containing 'full-qualified-callername'+'current-thread-id',
|
static java.lang.String |
getCallerName(boolean fullQualified) |
static java.lang.String |
getClassName(int level,
boolean fullQualified)
Get the class name, or class-name of its caller, or class-name of its caller's caller etc.
this depends on the parameter 'level'. |
static java.lang.String |
getCurrentMethodName(boolean fullQualified) |
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 double |
getDouble(java.util.Map<?,?> map,
java.lang.String key)
Get a double value from the map according to the key.
If it doesn't exist in map, the SAFSException will be thrown out. |
static float |
getFloat(java.util.Map<?,?> map,
java.lang.String key)
Get a float value from the map according to the key.
If it doesn't exist in map, the SAFSException will be thrown out. |
static int |
getIndex(java.lang.String index)
Parse a string to get an integer index.
|
static int |
getIndex(java.lang.String index,
int baseIndex)
Parse a string to get an integer index.
|
static int |
getInteger(java.util.Map<?,?> map,
java.lang.String key)
Get an int value from the map according to the key.
If it doesn't exist in map, the SAFSException will be thrown out. |
static long |
getLong(java.util.Map<?,?> map,
java.lang.String key)
Get a long value from the map according to the key.
If it doesn't exist in map, the SAFSException will be thrown out. |
static java.lang.String |
getMethodName(int level,
boolean fullQualified)
Get the method name, or its caller's name, or its caller's caller's name etc.
this depends on the parameter 'level'. |
static java.lang.Number |
getNumber(java.util.Map<?,?> map,
java.lang.String key,
java.lang.Class<?> numberClass)
Warn: If the key can't be found in the map object, a SAFSException will be thrown out
|
static int |
getNumSubstrings(java.lang.String strSub,
java.lang.String strText)
Method getNumSubstrings.
|
static java.lang.StackTraceElement |
getStackTraceElement(int level)
To get the current method information or its caller or its ancestor dynamically,
we can refer to the StackTrace, which is a stack recording the methods' invocation trace.
|
static java.lang.String |
getString(java.util.Map<?,?> map,
java.lang.String key)
Get a String value from the map according to the key.
If it doesn't exist in map, the SAFSException will be thrown out. |
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 java.lang.Object |
getValue(java.util.Map<?,?> map,
java.lang.String key)
Get a Object value from the map according to the key.
If it doesn't exist in map, the SAFSException will be thrown out. |
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)
java -ea org.safs.tools.stringutils.StringUtilities
|
static boolean |
nextCharIsDQ(java.lang.String strText,
int location)
Method nextCharIsDQ.
|
static int |
parseIndex(java.lang.String index)
Parse a string to get an integer index.
|
static int |
parseIndex(java.lang.String index,
int baseIndex)
Parse a string to get an integer index.
|
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 |
removeSingleQuotes(java.lang.String original)
Remove any leading and\or trailing single quotes.
|
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 void |
sleep(int milliseconds) |
static java.lang.String |
spacePad(int ipad)
Method spacePad.
|
static java.lang.String |
TWhitespace(java.lang.String strValue)
Method TWhitespace.
|
public static final java.lang.String DATE_FORMAT_DATE
public static final java.lang.String DATE_FORMAT_MILITARY_TIME
public static final java.lang.String DATE_FORMAT_MILITARY_DATE_TIME
public static final java.lang.String DATE_FORMAT_a
public static final java.lang.String DATE_FORMAT_AM_PM_TIME
public static final java.lang.String DATE_FORMAT_AM_PM_DATE_TIME
public static final java.lang.String TIME_OF_AM
public static final java.lang.String TIME_OF_PM
public static final java.lang.String JAVA_TIME_BASE
public static final java.lang.String FILE_TIME_BASE
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
public static final int SAFS_DEFAULT_START_INDEX
public static java.lang.String LTWhitespace(java.lang.String strValue)
strValue
- String to remove leading whitespace (space and tab)public static java.lang.String RTWhitespace(java.lang.String strValue)
strValue
- String to remove trailing whitespace (space and tab)public static java.lang.String TWhitespace(java.lang.String strValue)
strValue
- String to remove whitespace (space and tab)public static boolean charIsInRange(char c, int beg, int end)
c
- character to checkbeg
- lower end of rangeend
- higher end of rangepublic static int getNumSubstrings(java.lang.String strSub, java.lang.String strText)
strSub
- substring to count occurancesstrText
- string to search for strSub occurancespublic static boolean nextCharIsDQ(java.lang.String strText, int location)
strText
- String to checklocation
- int location to start checkpublic static java.util.Vector locateQuotedSubStrings(java.lang.String strText)
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.strText
- String in which to locate the quoted substringspublic static boolean isQuoted(java.lang.String strText, int location)
strText
- String to checklocation
- Location to checkpublic static boolean isQuoted(java.lang.String strText, int location, java.util.Vector vQuoteLocs)
strText
- String to checklocation
- Location to checkvQuoteLocs
- Vector
containing Integer
objects whose intValue
specifies the location of a double quote (") in strText.public static java.util.Vector getSubStrings(java.lang.String strText)
Vector
containing String
objects
that are quoted substrings within strTextstrText
- The string to find substringspublic static java.util.Vector getSubStrings(java.lang.String strText, java.util.Vector vQuoteLocs)
Vector
containing String
objects
that are quoted substrings within strTextstrText
- The string to find substringsvQuoteLocs
- Vector
containing Integer
objects whose intValue
specifies the location of a double quote (") in strText.public static int locateNextUnquotedNonWhiteSpace(java.lang.String strSearch, int ipos)
strSearch
- ipos
- public static int locateNextNonWhiteSpace(java.lang.String strSearch, int ipos)
strSearch
- ipos
- public static int locateNextUnquotedSingleChar(java.lang.String strSearch, java.lang.String strChars, int ipos)
strSearch
- The string to searchstrChars
- A string consisting of single characters to find the first occurance ofipos
- int position within strSearch to begin searchpublic static int locateNextUnquotedSingleChar(java.lang.String strSearch, java.lang.String strChars, int ipos, java.util.Vector vQuoteLocs)
strSearch
- The string to searchstrChars
- A string consisting of single characters to find the first occurance ofipos
- int position within strSearch to begin searchvQuoteLocs
- Vector
containing Integer
objects whose intValue
specifies the location of a double quote (") in strText.public static int locateNextUnquotedSubstring(java.lang.String strSearch, java.lang.String strFind, int ipos)
strSearch
- The string to searchstrFind
- The substring to search foripos
- int position within strSearch to begin searchpublic static int locateNextUnquotedSubstring(java.lang.String strSearch, java.lang.String strFind, int ipos, java.util.Vector vQuoteLocs)
strSearch
- The string to searchstrFind
- The substring to search foripos
- int position within strSearch to begin searchvQuoteLocs
- Vector
containing Integer
objects whose intValue
specifies the location of a double quote (") in strText.public static int locateNextSubstring(java.lang.String strSearch, java.lang.String strFind, int ipos)
strSearch
- The string to searchstrFind
- The substring to search foripos
- int position within strSearch to begin searchpublic static java.lang.String removeAllNonQuotedWhitespace(java.lang.String strValue)
String
that is strValue with
all non quoted whitespace (space and tab) removed. (keeps whitespace between double quotes)strValue
- The string to remove non-quoted whitespacepublic static java.lang.String removeAllNonQuotedWhitespace(java.lang.String strValue, java.util.Vector vQuoteLocs)
String
that is strValue with
all non quoted whitespace (space and tab) removed. (keeps whitespace between double quotes)strValue
- The string to remove non-quoted whitespacevQuoteLocs
- Vector
containing Integer
objects whose intValue
specifies the location of a double quote (") in strText.public static java.lang.String replaceString(java.lang.String strSearch, java.lang.String strReplace, int ibegin, int iend)
strSearch
- The string to searchstrReplace
- The replacement stringibegin
- int location to begin replacementiend
- int location to end replacementpublic static java.lang.String reverse(java.lang.String s)
s
- The string to reversepublic static boolean isLegalVarName(java.lang.String strVarName)
strVarName
- The variable name to testpublic static boolean isValidNonStdChar(char c)
c
- The char to testpublic static java.lang.String findAndReplace(java.lang.String input, java.lang.String search, java.lang.String replace)
public static java.lang.String spacePad(int ipad)
ipad
- public static boolean convertBool(java.lang.Object bool)
bool
- public static boolean getBoolean(java.util.Map<?,?> map, java.lang.String key) throws SAFSException
SAFSException
public static java.lang.Object getValue(java.util.Map<?,?> map, java.lang.String key) throws SAFSException
SAFSException
public static java.lang.String getString(java.util.Map<?,?> map, java.lang.String key) throws SAFSException
SAFSException
public static int getInteger(java.util.Map<?,?> map, java.lang.String key) throws SAFSException
SAFSException
public static float getFloat(java.util.Map<?,?> map, java.lang.String key) throws SAFSException
SAFSException
public static double getDouble(java.util.Map<?,?> map, java.lang.String key) throws SAFSException
SAFSException
public static long getLong(java.util.Map<?,?> map, java.lang.String key) throws SAFSException
SAFSException
public static java.lang.Number getNumber(java.util.Map<?,?> map, java.lang.String key, java.lang.Class<?> numberClass) throws SAFSException
SAFSException
public static java.lang.String removeRelativeFilePathPrefix(java.lang.String relativepath)
Example:
".\Datapool\Filename.ext" returns "Datapool\Filename.ext"
relativepath
- String filepath to strip of leading relative path prefix characters.public static java.lang.String removePrefix(java.lang.String original, java.lang.String prefix)
Example:
original = "^filename=c:\file.txt" , prefix="^filename=" the result will be "c:\file.txt"
original
- prefix
- public static java.lang.String removeSuffix(java.lang.String original, java.lang.String suffix)
Example:
original = "^filename=c:\file.txt" , suffix="=c:\file.txt" the result will be "^filename"
original
- suffix
- public static java.lang.String removeDoubleQuotes(java.lang.String original)
Example:
original = "c:\file.txt" (with quotes) the result will be 'c:\file.txt' (no quotes at all)
original
- public static java.lang.String removeSingleQuotes(java.lang.String original)
Example:
original = 'c:\file.txt' (with quotes) the result will be 'c:\file.txt' (no quotes at all)
original
- public static java.lang.Integer convertToInteger(java.lang.String value) throws SAFSException
value
- A string represents an integer value.SAFSException
public static java.awt.Rectangle formRectangle(java.lang.String rectangleString, java.lang.String separator)
rectangleString
- A string represent a rectangle: x, y , widht, height.separator
- The separator in rectangleString to separate x y width and heightpublic static java.lang.String getDateString(java.util.Date date, java.lang.String dateFormat)
date
- A java.util.Date objectdateFormat
- A string represents the date format pattern of SimpleDateFormatpublic static java.lang.String getDateString(java.util.Date date)
date
- A java.util.Date objectpublic static java.lang.String getTimeString(java.util.Date date, boolean isMilitary)
date
- A java.util.Date objectisMilitary
- A boolean, if true, convert to a military time (24 hours format)public static java.lang.String getDateTimeString(java.util.Date date, boolean isMilitary)
date
- A java.util.Date objectisMilitary
- A boolean, if true, convert to a military time (24 hours format)public static java.lang.String current(boolean isMilitary)
isMilitary
- boolean, true to return date-time in format DATE_FORMAT_MILITARY_DATE_TIME
;DATE_FORMAT_AM_PM_DATE_TIME
DATE_FORMAT_AM_PM_DATE_TIME
or DATE_FORMAT_MILITARY_DATE_TIME
public static int parseIndex(java.lang.String index)
index
- String, the index given as a stringparseIndex(String, int)
,
getIndex(String)
public static int parseIndex(java.lang.String index, int baseIndex)
index
- String, the index given as a stringbaseIndex
- int, the base indexgetIndex(String, int)
public static int getIndex(java.lang.String index) throws SAFSException
index
- String, the index given as a stringSAFSException
- If the string index is not an integer or it is smaller than the SAFS_DEFAULT_START_INDEX
getIndex(String, int)
,
parseIndex(String)
public static int getIndex(java.lang.String index, int baseIndex) throws SAFSException
index
- String, the index given as a stringbaseIndex
- int, the base indexSAFSException
- If the string index is not an integer or it is smaller than the 'base index'parseIndex(String, int)
public static java.util.Date getDate(java.lang.String date, java.lang.String dateFormat)
date
- A string represents a date.dateFormat
- A string represents the date format pattern of SimpleDateFormatpublic static void sleep(int milliseconds)
milliseconds
- int, milliseconds to sleeppublic static java.lang.String debugmsg(java.lang.Throwable e)
public static java.lang.String debugmsg(java.lang.Class<?> clazz, java.lang.String methodName)
clazz
- Class, the class object of the instance, which is caller of the method.methodName
- String, the string name of the method.public static java.lang.String debugmsg(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.String message)
clazz
- Class, the class object of the instance, which is caller of the method.methodName
- String, the string name of the method.message
- String, the detail message for the debug IndependantLog.public static java.lang.String debugmsg(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Throwable e)
clazz
- Class, the class object of the instance, which is caller of the method.methodName
- String, the string name of the method.e
- Throwable, the Throwable object rose when calling method.public static java.lang.String debugmsg(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.String message, java.lang.Throwable e)
clazz
- Class, the class object of the instance, which is caller of the method.methodName
- String, the string name of the method.message
- String, the detail message for the debug IndependantLog.e
- Throwable, the Throwable object rose when calling method.public static java.lang.String debugmsg(boolean fullQualified)
fullQualified
- boolean, true if the returned method name should be full-qualified.getMethodName(int, boolean)
public static java.lang.String getCurrentMethodName(boolean fullQualified)
fullQualified
- boolean, true if the returned method name should be full qualified.getMethodName(int, boolean)
public static java.lang.String getCallerName(boolean fullQualified)
fullQualified
- boolean, true if the returned method name should be full qualified.getMethodName(int, boolean)
public static java.lang.String getCallerClassName(boolean fullQualified)
fullQualified
- boolean, true if the returned class name should be full qualified.getClassName(int, boolean)
public static java.lang.String getCallerID(boolean fullQualified)
fullQualified
- boolean, true if the returned method name should be full qualified.getMethodName(int, boolean)
public static java.lang.String getMethodName(int level, boolean fullQualified)
level
- int, the level in the StackTrace.fullQualified
- boolean, true if the returned name should be full qualified.getStackTraceElement(int)
public static java.lang.String getClassName(int level, boolean fullQualified)
level
- int, the level in the StackTrace.fullQualified
- boolean, true if the returned name should be full qualified.getStackTraceElement(int)
public static java.lang.StackTraceElement getStackTraceElement(int level)
To get the current method information or its caller or its ancestor dynamically, we can refer to the StackTrace, which is a stack recording the methods' invocation trace. The current thread trace of this method is as following: ... java.lang.Thread.getStackTrace org.safs.tools.stringutils.StringUtilities.getStackTraceElement level=0, Here is the method, who calls StringUtilities.getStackTraceElement() level=1, Here is the direct caller of method at level 0 level=2, Here is the direct caller of method at level 1 ... We can supply the parameter 'level' to this method, and we can get the appropriate StackTraceElement.
level
- int, the level in the StackTrace under 'org.safs.tools.stringutils.StringUtilities.getStackTraceElement'public static void main(java.lang.String[] args)
args
- Copyright © SAS Institute. All Rights Reserved.