com.scooterframework.common.util
Class Converters

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

public class Converters
extends java.lang.Object

Converters class has all kinds of convert methods.


Constructor Summary
Converters()
           
 
Method Summary
static java.util.List<java.lang.String> convertArrayToList(java.lang.String[] values)
          Converts a string array to list.
static java.lang.String convertCharSet(java.lang.String s, java.lang.String fromCharSet, java.lang.String toCharSet)
          convertCharSet converts a string from one character set to another.
static
<T> T[]
convertListToArray(java.util.List<T> values)
          Converts a list to an array.
static
<T> java.lang.String[]
convertListToStringArray(java.util.List<T> values)
          Converts a list to a string array.
static java.util.Map<java.lang.String,java.lang.String> convertMapToMapSS(java.util.Map<java.lang.String,?> map)
           
static java.lang.String convertMapToString(java.util.Map<java.lang.String,java.lang.String> map, java.lang.String pairSpliter, java.lang.String separator)
          Converts a Map object to string.
static
<T> java.lang.String
convertMapToString(java.util.Map<java.lang.String,T> map, java.util.List<java.lang.String> filters, java.lang.String pairSpliter, java.lang.String separator, boolean doubleQuoteValue)
          Converts a Map object to string.
static
<T> java.lang.String
convertMapToUrlString(java.util.Map<java.lang.String,T> map)
          converts a Map object to URL-like string.
static java.lang.String convertObjectArrayToString(java.lang.Object[] objs, java.lang.String separator)
           
static java.util.Map<java.lang.String,java.lang.String> convertSqlOptionStringToMap(java.lang.String options)
          Converts SQL option string which contains name and value pairs to a Map object.
static java.util.List<java.lang.String> convertStringToList(java.lang.String nameString)
          Converts name list string to List object The default delimiter string to separate name-value pairs is ",|&".
static java.util.List<java.lang.String> convertStringToList(java.lang.String nameString, boolean allowTrim)
          Converts name list string to List object The default delimiter string to separate name-value pairs is ",|&".
static java.util.List<java.lang.String> convertStringToList(java.lang.String nameString, java.lang.String delimiter)
          Converts name list string separated by a delimiter to List object String name list string has the following format: firstName, lastName, age,...
static java.util.List<java.lang.String> convertStringToList(java.lang.String nameString, java.lang.String delimiter, boolean allowTrim)
          Converts name list string separated by a delimiter to List object String name list string has the following format: firstName, lastName, age,...
static java.util.Map<java.lang.String,java.lang.String> convertStringToMap(java.lang.String nameValuePairs)
          Converts a string of name and value pairs, separated by either comma, or vertical slash or space, to a Map object.
static java.util.Map<java.lang.String,java.lang.String> convertStringToMap(java.lang.String nameValuePairs, java.lang.String propertyDelimiter)
          Converts a string of name and value pairs separated by delimiter string to a Map object.
static java.util.Map<java.lang.String,java.lang.String> convertStringToMap(java.lang.String nameValuePairs, java.lang.String nameValueSpliter, java.lang.String propertyDelimiter)
           Converts a string of name and value pairs separated by delimiter string to a Map object.
static java.util.Properties convertStringToProperties(java.lang.String nameValuePairs, java.lang.String nameValueSpliter, java.lang.String propertyDelimiter)
           Converts a string of name and value pairs separated by delimiter string to a Properties object.
static java.util.Set<java.lang.String> convertStringToSet(java.lang.String nameString)
          Converts name list string to Set object The default delimiter string to separate name-value pairs is ",|&".
static java.util.Set<java.lang.String> convertStringToSet(java.lang.String nameString, boolean allowTrim)
          Converts name list string to Set object The default delimiter string to separate name-value pairs is ",|&".
static java.util.Set<java.lang.String> convertStringToSet(java.lang.String nameString, java.lang.String delimiter)
          Converts name list string separated by a delimiter to Set object String name set string has the following format: firstName, lastName, age,...
static java.util.Set<java.lang.String> convertStringToSet(java.lang.String nameString, java.lang.String delimiter, boolean allowTrim)
          Converts name list string separated by a delimiter to Set object String name set string has the following format: firstName, lastName, age,...
static java.lang.String[] convertStringToStringArray(java.lang.String s, java.lang.String delimiter)
          Converts a string separated by a delimiter to a string array.
static java.lang.String[] convertStringToStringArray(java.lang.String s, java.lang.String delimiter, boolean allowTrim)
          Converts a string separated by a delimiter to a string array.
static java.util.List<java.lang.String> convertStringToUniqueList(java.lang.String nameString)
          Converts name list string to List object which only retains unique items.
static java.util.List<java.lang.String> convertStringToUniqueList(java.lang.String nameString, java.lang.String delimiter)
          Converts name list string separated by a delimiter to List object which only retains unique items.
static java.lang.String convertToJavaClassLikeString(java.lang.String word)
          Returns a Java class-name-like string.
static
<K,V> java.util.Map<V,K>
reverseMap(java.util.Map<K,V> m)
          Reverses key/value pairs of a map.
static java.util.Collection<java.lang.String> toUpperCase(java.util.Collection<java.lang.String> items)
          Converts to upper case.
static java.lang.String toUpperCase(java.lang.Object object)
          Converts a string to upper case.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Converters

public Converters()
Method Detail

convertStringToList

public static java.util.List<java.lang.String> convertStringToList(java.lang.String nameString)
Converts name list string to List object The default delimiter string to separate name-value pairs is ",|&". String name list string has the following format: firstName, lastName, age,... or firstName|lastName|age|... or firstName&lastName&age&...


convertStringToList

public static java.util.List<java.lang.String> convertStringToList(java.lang.String nameString,
                                                                   boolean allowTrim)
Converts name list string to List object The default delimiter string to separate name-value pairs is ",|&". String name list string has the following format: firstName, lastName, age,... or firstName|lastName|age|... or firstName&lastName&age&...


convertStringToList

public static java.util.List<java.lang.String> convertStringToList(java.lang.String nameString,
                                                                   java.lang.String delimiter)
Converts name list string separated by a delimiter to List object String name list string has the following format: firstName, lastName, age,... or firstName|lastName|age|...


convertStringToList

public static java.util.List<java.lang.String> convertStringToList(java.lang.String nameString,
                                                                   java.lang.String delimiter,
                                                                   boolean allowTrim)
Converts name list string separated by a delimiter to List object String name list string has the following format: firstName, lastName, age,... or firstName|lastName|age|...


convertStringToUniqueList

public static java.util.List<java.lang.String> convertStringToUniqueList(java.lang.String nameString)
Converts name list string to List object which only retains unique items. The default delimiter string to separate name-value pairs is ",|&". String name list string has the following format: firstName, lastName, age,... or firstName|lastName|age|... or firstName&lastName&age&...


convertStringToUniqueList

public static java.util.List<java.lang.String> convertStringToUniqueList(java.lang.String nameString,
                                                                         java.lang.String delimiter)
Converts name list string separated by a delimiter to List object which only retains unique items. String name list string has the following format: firstName, lastName, age,... or firstName|lastName|age|...


convertStringToSet

public static java.util.Set<java.lang.String> convertStringToSet(java.lang.String nameString)
Converts name list string to Set object The default delimiter string to separate name-value pairs is ",|&". String name list string has the following format: firstName, lastName, age,... or firstName|lastName|age|... or firstName&lastName&age&...


convertStringToSet

public static java.util.Set<java.lang.String> convertStringToSet(java.lang.String nameString,
                                                                 boolean allowTrim)
Converts name list string to Set object The default delimiter string to separate name-value pairs is ",|&". String name list string has the following format: firstName, lastName, age,... or firstName|lastName|age|... or firstName&lastName&age&...


convertStringToSet

public static java.util.Set<java.lang.String> convertStringToSet(java.lang.String nameString,
                                                                 java.lang.String delimiter)
Converts name list string separated by a delimiter to Set object String name set string has the following format: firstName, lastName, age,... or firstName|lastName|age|...


convertStringToSet

public static java.util.Set<java.lang.String> convertStringToSet(java.lang.String nameString,
                                                                 java.lang.String delimiter,
                                                                 boolean allowTrim)
Converts name list string separated by a delimiter to Set object String name set string has the following format: firstName, lastName, age,... or firstName|lastName|age|...


convertStringToMap

public static java.util.Map<java.lang.String,java.lang.String> convertStringToMap(java.lang.String nameValuePairs)
Converts a string of name and value pairs, separated by either comma, or vertical slash or space, to a Map object. Name and value strings are separated by "=" sign. The default delimiter string to separate name-value pairs is ",|&". String nameValuePairs has the following format: firstName=John, lastName=Doe, age=10,... or firstName=John|lastName=Doe|age=10|... or firstName=John&lastName=Doe&age=10&...


convertStringToMap

public static java.util.Map<java.lang.String,java.lang.String> convertStringToMap(java.lang.String nameValuePairs,
                                                                                  java.lang.String propertyDelimiter)
Converts a string of name and value pairs separated by delimiter string to a Map object. Name and value strings are separated by "=" sign. String nameValuePairs has the following format: firstName=John, lastName=Doe, age=10,... or firstName=John|lastName=Doe|age=10|...


convertStringToMap

public static java.util.Map<java.lang.String,java.lang.String> convertStringToMap(java.lang.String nameValuePairs,
                                                                                  java.lang.String nameValueSpliter,
                                                                                  java.lang.String propertyDelimiter)

Converts a string of name and value pairs separated by delimiter string to a Map object.

Example: An example property string may be like the following:
 condition : role_type = 1, id = 100; order_by : first_name DESC
 

Here the nameValueSpliter is ":", and the propertyDelimiter is ";".

Parameters:
nameValuePairs - a string of properties
nameValueSpliter - a short string that separates name and value elements in a pair
propertyDelimiter - a char that separates pairs in a string line
Returns:
properties

convertStringToProperties

public static java.util.Properties convertStringToProperties(java.lang.String nameValuePairs,
                                                             java.lang.String nameValueSpliter,
                                                             java.lang.String propertyDelimiter)

Converts a string of name and value pairs separated by delimiter string to a Properties object.

Example: An example property string may be like the following:
 condition : role_type = 1, id = 100; order_by : first_name DESC
 

Here the nameValueSpliter is ":", and the propertyDelimiter is ";".

Parameters:
nameValuePairs - a string of properties
nameValueSpliter - a short string that separates name and value elements in a pair
propertyDelimiter - a char that separates pairs in a string line
Returns:
properties

convertStringToStringArray

public static java.lang.String[] convertStringToStringArray(java.lang.String s,
                                                            java.lang.String delimiter)
Converts a string separated by a delimiter to a string array.


convertStringToStringArray

public static java.lang.String[] convertStringToStringArray(java.lang.String s,
                                                            java.lang.String delimiter,
                                                            boolean allowTrim)
Converts a string separated by a delimiter to a string array.


convertSqlOptionStringToMap

public static java.util.Map<java.lang.String,java.lang.String> convertSqlOptionStringToMap(java.lang.String options)
Converts SQL option string which contains name and value pairs to a Map object. In an option string, each name-value pair is separated by ';' character, while within each name-value pair, name and value strings are separated by ':' character. For example, an option string like the following
      conditions_sql: id in (1, 2, 3); include: category, user; 
      order_by: first_name, salary DESC; cascade: delete
 
will be converted to a HashMap with the following entries:
      key                 value
      --------------      -----
      conditions_sql  =>  id in (1, 2, 3)
      include         =>  category, user
      order_by        =>  first_name, salary DESC
      cascade         =>  delete
 


convertMapToString

public static java.lang.String convertMapToString(java.util.Map<java.lang.String,java.lang.String> map,
                                                  java.lang.String pairSpliter,
                                                  java.lang.String separator)
Converts a Map object to string. For example, if the key/value pairs in the map are {title=test page, shape=rect}, and the pairSpliter = ":", and the separator = ";", the converted string will be title:test page;shape:rect


convertMapToString

public static <T> java.lang.String convertMapToString(java.util.Map<java.lang.String,T> map,
                                                      java.util.List<java.lang.String> filters,
                                                      java.lang.String pairSpliter,
                                                      java.lang.String separator,
                                                      boolean doubleQuoteValue)
Converts a Map object to string. The list filters contains allowable keys. If filters is null, all keys are allowed. For example, if the key/value pairs in the map are {title=test page, shape=rect}, and the pairSpliter = ":", and the separator = ";", the converted string will be title:"test page";shape:"rect" if doubleQuoteValue = true or title:test page;shape:rect if doubleQuoteValue = false


convertMapToUrlString

public static <T> java.lang.String convertMapToUrlString(java.util.Map<java.lang.String,T> map)
converts a Map object to URL-like string. The final URL-like string has the following format: firstName=John&lastName=Doe&age=10...


convertArrayToList

public static java.util.List<java.lang.String> convertArrayToList(java.lang.String[] values)
Converts a string array to list.

Parameters:
values - string array
Returns:
a list of string values

convertListToStringArray

public static <T> java.lang.String[] convertListToStringArray(java.util.List<T> values)
Converts a list to a string array. Each item in the list is converted to a string if the item is not null.

Parameters:
values - list of objects
Returns:
array of strings

convertListToArray

public static <T> T[] convertListToArray(java.util.List<T> values)
Converts a list to an array.

Parameters:
values - list of objects
Returns:
array of objects

convertToJavaClassLikeString

public static java.lang.String convertToJavaClassLikeString(java.lang.String word)
Returns a Java class-name-like string.
 Examples: 
   "admin/posts"  --> "admin.Posts"
   "posts"        --> "Posts"
   "/posts"       --> "Posts"
   "role_users"   --> "RoleUsers"
 

Parameters:
word -
Returns:
a Java class-name-like string

convertCharSet

public static java.lang.String convertCharSet(java.lang.String s,
                                              java.lang.String fromCharSet,
                                              java.lang.String toCharSet)
convertCharSet converts a string from one character set to another.

Parameters:
s - the string to be converted.
fromCharSet - the character set to convert from.
toCharSet - the character set to convert to.
Returns:
a new string in a new character char set.

toUpperCase

public static java.lang.String toUpperCase(java.lang.Object object)
Converts a string to upper case.

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

toUpperCase

public static java.util.Collection<java.lang.String> toUpperCase(java.util.Collection<java.lang.String> items)
Converts to upper case.

Parameters:
items - a collection

reverseMap

public static <K,V> java.util.Map<V,K> reverseMap(java.util.Map<K,V> m)
Reverses key/value pairs of a map. A new map instance is returned with the value field of the original map as key and the key field of the original map as value.

Parameters:
m - the original map
Returns:
a new map

convertMapToMapSS

public static java.util.Map<java.lang.String,java.lang.String> convertMapToMapSS(java.util.Map<java.lang.String,?> map)

convertObjectArrayToString

public static java.lang.String convertObjectArrayToString(java.lang.Object[] objs,
                                                          java.lang.String separator)