Package oracle.stellent.ridc.common.util
Class StringTools
java.lang.Object
oracle.stellent.ridc.common.util.StringTools
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAllows a user to append/modify a buffer during a call to evaluateRegexWithCallback -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringBoolean string "false"static final StringBoolean string "no" - analog for "false"static final StringBoolean string "off" - analog for "false"static final StringBoolean string "on" - analog for "true"static final StringBoolean string "true"static final StringBoolean string "yes" - analog for "true"static final charCharacter for "\"static final charCharacter for "."static final charCharacter for "/"static final charTab characterstatic final StringString constant for "&" signstatic final StringString constant for "," signstatic final StringString constant for "=" signstatic final StringString constant for "?" signstatic final StringString constant for ";" signstatic final StringString constant for " " sign -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringReplaces the specified substring with the new substring in the given input.static StringFast 2 string concatenation usingStringBuffer.static StringevaluateRegexWithCallback(String text, String regEx, StringTools.RegexAppendCallback callback) Analyze a string and invoke a callback when a match is found.static String[]Parses comma (",") delimited string to string array.static StringgetCsvFromCollection(Collection collection) Constructs string from a collectiongetDelimitedList(String value, String delims) GetListof tokens from delimited original stringstatic StringgetFirstSegment(String value, String separator) Get first string segment separated by passed separatorstatic int[]getIntArrayFromDelimitedString(String data, String delimiter) Parses string with the specified delimiter and returns array of ints as a result of parsing.static StringgetLastSegment(String value, String separator) Get last string segment separated by passed separatorstatic StringgetLastSegment(String value, String separator, boolean includeSeparator) Get last string segment separated by passed separatorgetListFromCsv(String value) getListFromDelimitedString(String data, String delimiter) Parses data with the specified delimitergetLongsListFromCsv(String value) static StringgetSegment(String str, String separator, int segment) Returns the segment, null if not found, first segment is segment 0static StringgetValueOrDefault(String value, String defaultValue) Checks the value and returns a non-null value or the default valuestatic booleanisEmpty(char[] array) Verifies whether passed character array is empty/null or not.static booleanisEmpty(CharSequence sequence) Verifies whether passed character sequence is empty/null or not.static booleanVerifies whether passed string is empty/null or not.static booleanTest if the value of a string is considered true.static StringreplaceChars(String orig, String chars, char replace) Replaces all chars with the replacement charstatic StringreplaceParams(String source, String[] params) Replace placeholders, or parameters, in a string that are of the format {number}static StringstripFirstSegment(String value, String separator) Strips string first segment, defined by separator and returns stripped stringstatic StringstripLastSegment(String value, String separator) Strips string last segment, defined by separator and returns stripped stringstatic booleanConverts string to boolean.static StringConvert array of objects to comma-separated stringstatic StringConvertListof strings to comma-separated stringstatic StringUnwraps string using selected prefix and postfixstatic StringWrap string value with prefix and postfix.static StringwrapIfRequired(String value, String prefix, String postfix) Wrap the string value with prefix and postfix, but only if the prefix and/or postfix does not exist in the value.
-
Field Details
-
BOOLEAN_ON
Boolean string "on" - analog for "true"- See Also:
-
BOOLEAN_OFF
Boolean string "off" - analog for "false"- See Also:
-
BOOLEAN_YES
Boolean string "yes" - analog for "true"- See Also:
-
BOOLEAN_NO
Boolean string "no" - analog for "false"- See Also:
-
BOOLEAN_FALSE
Boolean string "false"- See Also:
-
BOOLEAN_TRUE
Boolean string "true"- See Also:
-
STR_COMMA
String constant for "," sign- See Also:
-
STR_SEMICOLON
String constant for ";" sign- See Also:
-
STR_QUESTION
String constant for "?" sign- See Also:
-
STR_EQUALS
String constant for "=" sign- See Also:
-
STR_AND
String constant for "&" sign- See Also:
-
STR_SPACE
String constant for " " sign- See Also:
-
CHR_DOT
public static final char CHR_DOTCharacter for "."- See Also:
-
CHR_FORWARD_SLASH
public static final char CHR_FORWARD_SLASHCharacter for "/"- See Also:
-
CHR_BACK_SLASH
public static final char CHR_BACK_SLASHCharacter for "\"- See Also:
-
CHR_TAB
public static final char CHR_TABTab character- See Also:
-
-
Constructor Details
-
StringTools
public StringTools()
-
-
Method Details
-
getListFromDelimitedString
Parses data with the specified delimiter- Parameters:
data- Original data to parsedelimiter- Delimiter to use for data parsing- Returns:
LinkedListof tokens parsed, delimiters are not returned
-
getIntArrayFromDelimitedString
Parses string with the specified delimiter and returns array of ints as a result of parsing. Of course this is applicable only when you do know that string contains integers- Parameters:
data- Original data to parsedelimiter- Delimiter to use for data parsing- Returns:
- array of integers
-
getArrayFromCsvString
Parses comma (",") delimited string to string array. No quotes (") supported- Parameters:
csv- Comma separated values- Returns:
- array of
Stringextracted from line
-
getListFromCsv
-
getLongsListFromCsv
-
getCsvFromCollection
Constructs string from a collection- Parameters:
collection- source collection of values- Returns:
- Comma-separated string as a result of values concatenation
-
getFirstSegment
Get first string segment separated by passed separator- Parameters:
value- initial stringseparator- is separator string- Returns:
- stripped segment or null
-
getLastSegment
Get last string segment separated by passed separator- Parameters:
value- initial stringseparator- is separator string- Returns:
- stripped segment or null
-
getLastSegment
Get last string segment separated by passed separator- Parameters:
value- initial stringseparator- is separator stringincludeSeparator- true to include the separator character in the result, false otherwise- Returns:
- stripped segment or null
-
getSegment
Returns the segment, null if not found, first segment is segment 0- Parameters:
str- Source stringseparator- Parsing separatorsegment- String segment number- Returns:
- Specified segment of the string extracted
-
stripFirstSegment
Strips string first segment, defined by separator and returns stripped string- Parameters:
value- initial stringseparator- is separator string- Returns:
- stripped value string
-
stripLastSegment
Strips string last segment, defined by separator and returns stripped string- Parameters:
value- initial stringseparator- is separator string- Returns:
- stripped value string
-
isEmpty
Verifies whether passed string is empty/null or not.- Parameters:
str- Source string to analyze- Returns:
- True, if string is empty or null, False - otherwise
-
isEmpty
Verifies whether passed character sequence is empty/null or not.- Parameters:
sequence- Source sequence to analyze- Returns:
- True, if sequence is empty or null, False - otherwise
-
isEmpty
public static boolean isEmpty(char[] array) Verifies whether passed character array is empty/null or not.- Parameters:
array- Source array to analyze- Returns:
- True, if array is empty or null, False - otherwise
-
change
Replaces the specified substring with the new substring in the given input.- Parameters:
input- the string to examineoldPattern- a substring representing a pattern to be replacednewPattern- a substring representing the pattern to replace the old- Returns:
- a string with the oldPattern replaced by the newPattern
-
replaceChars
Replaces all chars with the replacement char- Parameters:
orig- Original stringchars- Characters we want to replacereplace- Replacement character- Returns:
- Modified original string with all chars replaced with replacement character
-
toBoolean
Converts string to boolean. The difference is that is understands "on" and "off" values as true and false respectively- Parameters:
value- Source string value to convert- Returns:
- true or false depending on string content. If string is empty - false is returned
-
isTrue
Test if the value of a string is considered true. '1', case agnostic versions of "t", "y", "true","yes" and "on"- Parameters:
value- String to be tested- Returns:
- true if string matches criteria, otherwise false
-
wrap
Wrap string value with prefix and postfix. Result looks as follows:result := prefix + value + postfix
- Parameters:
value- Source string value to wrapprefix- Prefix to usepostfix- Postfix to use- Returns:
- Original string with specified prefix and postfix
-
wrapIfRequired
Wrap the string value with prefix and postfix, but only if the prefix and/or postfix does not exist in the value.- Parameters:
value- string value to wrapprefix- the string to prependpostfix- the string to append- Returns:
- wrapped string
-
unwrap
Unwraps string using selected prefix and postfix- Parameters:
value- Previously wrapped stringprefix- Prefix to usepostfix- Postfix to use- Returns:
- Original value used inside wrap call
-
toCsv
ConvertListof strings to comma-separated string- Parameters:
strings- Original strings container- Returns:
- Comma-separated list of values taken from original container
-
toCsv
Convert array of objects to comma-separated string- Parameters:
objects- array of objects (each will converted by calling toString())- Returns:
- a comma-seperated list of the toString() values of each object
-
getDelimitedList
GetListof tokens from delimited original string- Parameters:
value- Original string valuedelims- Delimiters used to make tokens- Returns:
- list of tokens produced as a result of string parsing
-
replaceParams
Replace placeholders, or parameters, in a string that are of the format {number}Example: Calling on string "Error locating resource {0} for user {1}" with array {"root", "admin"} would result in "Error locating resource root for user admin"- Parameters:
source- a string with parameters, starting with 0params- the values for the parameters, the index corresponding to the parameter value + 1- Returns:
- the string with the values in place
-
concat
Fast 2 string concatenation usingStringBuffer.- Parameters:
s1- source string #1s2- source string #2- Returns:
- 2 strings concatenated
-
evaluateRegexWithCallback
public static String evaluateRegexWithCallback(String text, String regEx, StringTools.RegexAppendCallback callback) Analyze a string and invoke a callback when a match is found.- Parameters:
text- the text to analyzeregEx- the regular expression to matchcallback- the callback to invoke when a match is found- Returns:
- the modified string
-
getValueOrDefault
Checks the value and returns a non-null value or the default value- Parameters:
value- String to test for nulldefaultValue- value to return if value is null- Returns:
- a non-null value
-