com.scooterframework.common.util
Class StringUtil

java.lang.Object
  extended by com.scooterframework.common.util.StringUtil

public class StringUtil
extends java.lang.Object

StringUtil class has methods on string manipulation.


Constructor Summary
StringUtil()
           
 
Method Summary
static java.util.Map<java.lang.String,java.lang.Object> convertKeyToUpperCase(java.util.Map<java.lang.String,?> inputs)
          Converts all keys in a map to upper case.
static java.lang.String doubleSingleQuoteInString(java.lang.String input)
          Adds another single quote if there is already one in the input string.
 java.util.Map<java.lang.String,java.lang.String> explode(java.lang.String data, java.lang.String separator)
          Converts a string of name and value pairs, separated by a separator to map.
static java.lang.String flattenArray(java.lang.Object[] words)
          Converts object array to a big string separated by comma.
static java.lang.String flattenArray(java.lang.Object[] words, java.lang.String splitter)
          Converts object array to a big string separated by splitter.
static java.lang.String flattenArray(java.lang.String prefix, java.lang.Object[] words, java.lang.String splitter)
          Converts object array to a big string separated by splitter.
static java.lang.String getValuesAsSQLLikeString(java.lang.String field, java.util.List<java.lang.String> values, java.lang.String type)
           
static java.lang.String getValuesAsSQLNumber(java.util.Collection<java.lang.String> values)
           
static java.lang.String getValuesAsSQLString(java.util.Collection<java.lang.String> values)
           
static java.lang.String getValuesAsSQLString(java.lang.String value)
           
static java.lang.String implode(java.util.List<java.lang.String> data, java.lang.String glue)
          Converts a list of strings into a long string separated by glue.
static java.lang.String implode(java.util.Map<java.lang.String,?> data, java.lang.String glue)
          Converts map into a long string separated by glue.
static java.lang.String implode(java.lang.String[] data, java.lang.String glue)
          Converts a list of strings into a long string separated by glue.
static boolean isStringInArray(java.lang.String item, java.lang.String[] array)
          Check if the string array contains the item.
static boolean isStringInArray(java.lang.String item, java.lang.String[] array, boolean ignoreCase)
          Check if the string array contains the item.
static java.lang.String parseStringForDoubleQuote(java.lang.String input)
           
static java.lang.String preview(java.lang.String s, int length)
          Returns the first few characters of a string.
static java.lang.String preview(java.lang.String s, int length, java.lang.String tail)
          Returns the first few characters of a string.
static java.lang.String remove(java.lang.String message, java.lang.String charsToBeremoved)
          Removes all occurances of the characters in charsToBeremoved.
static java.lang.StringBuffer removeLastToken(java.lang.StringBuffer word, java.lang.String token)
           
static java.lang.StringBuilder removeLastToken(java.lang.StringBuilder word, java.lang.String token)
           
static java.lang.String removeLastToken(java.lang.String word, java.lang.String token)
           
static java.lang.String replace(java.lang.String data, java.lang.String oldSymbol)
          Replaces old symbols with an empty string.
static java.lang.String replace(java.lang.String s, java.lang.String oldSymbol, java.lang.String newSymbol)
          Replaces old symbols with new symbols in a string.
static java.lang.String replaceLast(java.lang.String s, java.lang.String oldSymbol, java.lang.String newSymbol)
          Replaces the last occurance of an old symbol with a new symbol.
static java.lang.String reverseMapping(java.lang.String mapping)
           
static java.util.List<java.lang.String> splitString(java.lang.String bigString, java.lang.String splitter)
          Split a string into a list of substrings separated by splitter.
static boolean startsWithLowerCaseChar(java.lang.String s)
          Checks if a string starts with lower case char.
static java.lang.String stripSlashes(java.lang.String s)
          Removes slash from a string.
static int strlen(java.lang.String data)
          Returns length of a string.
static java.lang.String toLowerCase(java.lang.String s)
          Returns a string with all alphabetic characters converted to lower case.
static java.lang.String toUpperCase(java.lang.String s)
          Returns a string with all alphabetic characters converted to upper case.
static java.lang.String translate(java.lang.String message, java.lang.String charsToBeReplaced, java.lang.String replacementChars)
          translate method replaces a sequence of characters in a string with another set of characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

preview

public static java.lang.String preview(java.lang.String s,
                                       int length)
Returns the first few characters of a string. The rest is replaced by "...".

Parameters:
s - the original string
length - the number of characters to be returned.
Returns:
the first length characters of a string

preview

public static java.lang.String preview(java.lang.String s,
                                       int length,
                                       java.lang.String tail)
Returns the first few characters of a string. The rest is replaced by tail.

Parameters:
s - the original string
length - the number of characters to be returned.
tail - the symbol of the remaining part of the string.
Returns:
the first length characters of a string

strlen

public static int strlen(java.lang.String data)
Returns length of a string. If the string is null, return 0.

Parameters:
data - input string
Returns:
0 if the data is null or the length of the data string.

toLowerCase

public static java.lang.String toLowerCase(java.lang.String s)
Returns a string with all alphabetic characters converted to lower case.

Parameters:
s - input string
Returns:
a string in lower case.

toUpperCase

public static java.lang.String toUpperCase(java.lang.String s)
Returns a string with all alphabetic characters converted to upper case.

Parameters:
s - input string
Returns:
a string in upper case.

startsWithLowerCaseChar

public static boolean startsWithLowerCaseChar(java.lang.String s)
Checks if a string starts with lower case char.

Parameters:
s - the string to check
Returns:
true if the string starts with lower case char.

replace

public static java.lang.String replace(java.lang.String data,
                                       java.lang.String oldSymbol)
Replaces old symbols with an empty string.
 Examples:
      replace("123te123ch123", "123");    would return "tech"
 

Parameters:
data - the original string
oldSymbol - the substring to be replaced
Returns:
a replaced string

replace

public static java.lang.String replace(java.lang.String s,
                                       java.lang.String oldSymbol,
                                       java.lang.String newSymbol)
Replaces old symbols with new symbols in a string.
 Examples:
      replace("123te123ch123", "123", "X"); would return "XteXchX"
 

Parameters:
s - the original string
oldSymbol - the substring to be replaced
newSymbol - the replacement substring
Returns:
a replaced string

replaceLast

public static java.lang.String replaceLast(java.lang.String s,
                                           java.lang.String oldSymbol,
                                           java.lang.String newSymbol)
Replaces the last occurance of an old symbol with a new symbol.

Parameters:
s - the original string
oldSymbol - the substring to be replaced
newSymbol - the replacement substring
Returns:
a replaced string

remove

public static java.lang.String remove(java.lang.String message,
                                      java.lang.String charsToBeremoved)
Removes all occurances of the characters in charsToBeremoved.
 Examples:
      remove("abcabc1234567", "abc");   would return "1234567"
 

Parameters:
message - the string to be processed
charsToBeremoved - a string containing characters to be removed
Returns:
a new string

translate

public static java.lang.String translate(java.lang.String message,
                                         java.lang.String charsToBeReplaced,
                                         java.lang.String replacementChars)
translate method replaces a sequence of characters in a string with another set of characters. However, it replaces a single character at a time. For example, it will replace the 1st character in the charsToBeReplaced with the 1st character in the replacementChars. Then it will replace the 2nd character in the charsToBeReplaced with the 2nd character in the replacementChars, and so on. The length of charsToBeReplaced should be the same as replacementChars. If the replacementChars string is empty, then all occurances of the characters in charsToBeReplaced are replaced with empty character.
 Examples:
      translate("Hello!", "eo", "oa");          would return "Holla!"
      translate("123456", "23", "98");          would return "198456"
      translate("abcabc1234567", "abc", "000");         would return "0000001234567".
 

Parameters:
message - the string to be translated
charsToBeReplaced - characters to be replaced
replacementChars - characters to be used as replacement
Returns:
a new translated string

stripSlashes

public static java.lang.String stripSlashes(java.lang.String s)
Removes slash from a string.

Parameters:
s - the original string
Returns:
a string without slash

explode

public java.util.Map<java.lang.String,java.lang.String> explode(java.lang.String data,
                                                                java.lang.String separator)
Converts a string of name and value pairs, separated by a separator to map. The separator could be comma, or vertical slash or space, etc.
 String data has the following format: 
          firstName=John, lastName=Doe, age=10,...
       or firstName=John|lastName=Doe|age=10|...
 

Parameters:
data -
separator -
Returns:
Map

implode

public static java.lang.String implode(java.lang.String[] data,
                                       java.lang.String glue)
Converts a list of strings into a long string separated by glue.

Parameters:
data - string array
glue -
Returns:
String

implode

public static java.lang.String implode(java.util.List<java.lang.String> data,
                                       java.lang.String glue)
Converts a list of strings into a long string separated by glue.

Parameters:
data - a list of strings
glue -
Returns:
String

implode

public static java.lang.String implode(java.util.Map<java.lang.String,?> data,
                                       java.lang.String glue)
Converts map into a long string separated by glue.

Parameters:
data - a map
glue -
Returns:
String

flattenArray

public static java.lang.String flattenArray(java.lang.Object[] words)
Converts object array to a big string separated by comma.

Parameters:
words -
Returns:
a flattened string

flattenArray

public static java.lang.String flattenArray(java.lang.Object[] words,
                                            java.lang.String splitter)
Converts object array to a big string separated by splitter.

Parameters:
words -
splitter -
Returns:
a flattened string

flattenArray

public static java.lang.String flattenArray(java.lang.String prefix,
                                            java.lang.Object[] words,
                                            java.lang.String splitter)
Converts object array to a big string separated by splitter.

Parameters:
prefix - prefix before each element
words - an array of elements
splitter - a string which separates each element
Returns:
a flattened string

splitString

public static java.util.List<java.lang.String> splitString(java.lang.String bigString,
                                                           java.lang.String splitter)
Split a string into a list of substrings separated by splitter.

Parameters:
bigString - The string to be split
splitter - The splitter
Returns:
a list of strings

isStringInArray

public static boolean isStringInArray(java.lang.String item,
                                      java.lang.String[] array)
Check if the string array contains the item. String case is ignored when doing the check.

Parameters:
item -
array -
Returns:
true if the string array contains the item.

isStringInArray

public static boolean isStringInArray(java.lang.String item,
                                      java.lang.String[] array,
                                      boolean ignoreCase)
Check if the string array contains the item.

Parameters:
item -
array -
ignoreCase - true if case is ignored when doing comparison.
Returns:
true if the string array contains the item.

removeLastToken

public static java.lang.StringBuffer removeLastToken(java.lang.StringBuffer word,
                                                     java.lang.String token)

removeLastToken

public static java.lang.StringBuilder removeLastToken(java.lang.StringBuilder word,
                                                      java.lang.String token)

removeLastToken

public static java.lang.String removeLastToken(java.lang.String word,
                                               java.lang.String token)

reverseMapping

public static java.lang.String reverseMapping(java.lang.String mapping)

getValuesAsSQLNumber

public static java.lang.String getValuesAsSQLNumber(java.util.Collection<java.lang.String> values)

getValuesAsSQLString

public static java.lang.String getValuesAsSQLString(java.util.Collection<java.lang.String> values)

getValuesAsSQLString

public static java.lang.String getValuesAsSQLString(java.lang.String value)

getValuesAsSQLLikeString

public static java.lang.String getValuesAsSQLLikeString(java.lang.String field,
                                                        java.util.List<java.lang.String> values,
                                                        java.lang.String type)

doubleSingleQuoteInString

public static java.lang.String doubleSingleQuoteInString(java.lang.String input)
Adds another single quote if there is already one in the input string.


parseStringForDoubleQuote

public static java.lang.String parseStringForDoubleQuote(java.lang.String input)

convertKeyToUpperCase

public static java.util.Map<java.lang.String,java.lang.Object> convertKeyToUpperCase(java.util.Map<java.lang.String,?> inputs)
Converts all keys in a map to upper case.

Parameters:
inputs - the original map
Returns:
a new map with keys in upper case.