Class StringHelper
java.lang.Object
com.sun.jdo.spi.persistence.utility.StringHelper
NOTE: These utilities have been moved from another (more specific
package's) utility class so that more classes can have access to them.
There can be some refactoring work to combine these with some of the
methods in the StringScanner class.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringarrayToSeparatedList(List list) Convert an array of objects into a separated string using the default separator and the entire array.static StringarrayToSeparatedList(List list, int beginIndex, int endIndex) Convert an array of objects into a separated string using the default separator.static StringarrayToSeparatedList(List list, int beginIndex, int endIndex, String separator) Convert an array of objects into a separated string.static StringarrayToSeparatedList(List list, String separator) Convert an array of objects into a separated string using the specified separator and the entire array.static StringEscaping given string by " and \.static StringgetCapitalizedString(String aString) Gets a version of the specified string with the first letter capitalized.static StringintArrayToSeparatedList(int[] intArray, int beginIndex, int endIndex, String separator) Convert an array of int values into a separated string.static StringintArrayToSeparatedList(int[] intArray, String separator) Convert an array of int values into a separated string.static booleanChecks if a string is null or empty.static StringReplaces all occurences ofoldStringinstringwithnewString.static StringreplaceFirst(String string, String oldString, String newString) Replaces the first occurence ofoldStringinstringwithnewString.static StringTrims trailing spaces from input.static ListseparatedListToArray(String list) Convert a separated string to an array of strings using the default separator.static ListseparatedListToArray(String list, String separator) Convert a separated string to an array of strings
-
Constructor Details
-
StringHelper
public StringHelper()
-
-
Method Details
-
arrayToSeparatedList
public static String arrayToSeparatedList(List list, int beginIndex, int endIndex, String separator) Convert an array of objects into a separated string. This method assumes there is no instance of the separator in the strings of list.- Parameters:
list- The list of objects to be expanded.beginIndex- The index of the first element in the list to be used.endIndex- The index of the last element in the list to be used.separator- The separator to be used between strings.- Returns:
- a string representing the expanded list.
-
arrayToSeparatedList
Convert an array of objects into a separated string using the default separator. This method assumes there is no instance of the separator in the strings of list.- Parameters:
list- The list of objects to be expanded.beginIndex- The index of the first element in the list to be used.endIndex- The index of the last element in the list to be used.- Returns:
- a string representing the expanded list.
-
arrayToSeparatedList
Convert an array of objects into a separated string using the specified separator and the entire array. This method assumes there is no instance of the separator in the strings of list.- Parameters:
list- The list of objects to be expanded.separator- The separator to be used between strings.- Returns:
- a string representing the expanded list.
-
arrayToSeparatedList
Convert an array of objects into a separated string using the default separator and the entire array. This method assumes there is no instance of the separator in the strings of list.- Parameters:
list- The list of objects to be expanded.- Returns:
- a string representing the expanded list.
-
separatedListToArray
Convert a separated string to an array of strings- Parameters:
list- The string representing the list of objects.separator- The separator to be used to tokenize strings.- Returns:
- an array representing the tokenized list.
-
separatedListToArray
Convert a separated string to an array of strings using the default separator.- Parameters:
list- The string representing the list of objects.- Returns:
- an array representing the tokenized list.
-
intArrayToSeparatedList
Convert an array of int values into a separated string.- Parameters:
intArray- The array of int values to be expanded.separator- The separator to be used between strings.- Returns:
- a string representing the expanded array.
-
intArrayToSeparatedList
public static String intArrayToSeparatedList(int[] intArray, int beginIndex, int endIndex, String separator) Convert an array of int values into a separated string.- Parameters:
intArray- The array of int values to be expanded.beginIndex- The index of the first element in the array to be used.endIndex- The index of the last element in the array to be used.separator- The separator to be used between strings.- Returns:
- a string representing the expanded array.
-
isEmpty
Checks if a string is null or empty.- Returns:
trueif the string is null or empty after trim,falseotherwirse.
-
getCapitalizedString
Gets a version of the specified string with the first letter capitalized. This can be used to convert a field name to get and set method names.- Parameters:
aString- the string to be capitalized- Returns:
- a capitalized for the specified string
-
replaceFirst
Replaces the first occurence ofoldStringinstringwithnewString. The methods returns either a new string instance (in the caseoldStringis included in the string) or the origial string itself (in the caseoldStringis not included).- Parameters:
string- the original string.oldString- the string to be replaced.newString- the string the old value is replaced with.- Returns:
- a string derived from the specified this string by replacing the first occurence oldString with newString.
-
replace
Replaces all occurences ofoldStringinstringwithnewString. The methods returns either a new string instance (in the caseoldStringis included in the string) or the origial string itself (in the caseoldStringis not included).- Parameters:
string- the original string.oldString- the string to be replaced.newString- the string the old value is replaced with.- Returns:
- a string derived from the specified this string by replacing every occurrence of oldString with newString.
-
rtrim
Trims trailing spaces from input.- Parameters:
input- The input string.- Returns:
- A new string with trailing spaces trimmed. If there are no
trailing spaces, returns
input.
-
escape
Escaping given string by " and \.- Parameters:
str- String to be escaped- Returns:
- string escaped by " and \.
-