com.trendrr.oss
Class StringHelper

java.lang.Object
  extended by com.trendrr.oss.StringHelper

public class StringHelper
extends java.lang.Object

Author:
dustin

Field Summary
static char[] CHARACTERS
           
 
Constructor Summary
StringHelper()
           
 
Method Summary
static java.lang.String camelize(java.lang.String word)
           
static java.lang.String camelize(java.lang.String word, boolean lowercaseFirstLetter)
          camel cases the passed in string.
static java.lang.String capitalize(java.lang.String input)
          capitalizes the first letter.
static java.lang.String capitalizeWords(java.lang.String input)
           
static boolean contains(java.lang.String input, java.lang.String... delimiters)
          returns true if the input contains one or more of the delimiters.
static boolean contains(java.lang.String str1, java.lang.String str2, boolean wordBoundaries)
          Checks if str1 contains str2.
static boolean equals(java.lang.String input, boolean ignoreCase, java.lang.String... str)
          returns true if the input is equal to one of the passed in strs.
static java.lang.String getRandomNumberString(int length)
           
static java.lang.String getRandomString(int length)
          Generates a random string of length length, containing a-z, A-Z, 0-9
static java.lang.String javascriptEscape(java.lang.String input)
          escapes the string for use in javascript
static java.lang.String join(java.util.List lst, java.lang.String delim)
          joins a list into a string.
static boolean like(java.lang.String str1, java.lang.String str2)
          Does a simple string compare, ignoring case and punctuation.
static void main(java.lang.String... strings)
           
static boolean matches(java.lang.String input, java.lang.String... vals)
          returns true if input equals one of the passed in strings.
static java.lang.String maxChars(java.lang.String input, int max)
          will return a string with max nmber of characters
static java.lang.String randomString(int length)
          Generates a random string of length length, containing a-z, A-Z, 0-9
static java.lang.String removeAll(java.lang.String input, char... toRemove)
          removes all the requested characters.
static java.lang.String removeAll(java.lang.String input, java.lang.String... toRemove)
          removes all instances of the inputed strings.
static java.lang.String reverse(java.lang.String input)
           
static java.lang.String sanitizeUrl(java.lang.String url)
          Just strips any non allowed characters.
static byte[] secureId()
          Generates a cryptographically secure ID.
static byte[] sha1(byte[] bytes)
          returns a 20 byte sha1 hash
static java.lang.String singularize(java.lang.String input)
           
static java.util.List<java.lang.String> split(java.lang.String input, java.lang.String... delimiters)
          splits the string based on the given delimiters.
static java.lang.String toPrettyString(java.util.Map map)
           
static java.lang.String toPrettyString(java.lang.String[] array)
           
static java.lang.String trim(java.lang.String input, java.lang.String trim)
          will trim off the front and back of the string.
static java.lang.String trimChars(java.lang.String input, int num)
          trims the specified number of chars off the END of the string.
static java.lang.String uncamelize(java.lang.String input)
          uncamelizes the input string.
static java.lang.String uncapitalize(java.lang.String input)
          lower cases the first letter
static java.lang.String underscoreSpaces(java.lang.String input)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHARACTERS

public static final char[] CHARACTERS
Constructor Detail

StringHelper

public StringHelper()
Method Detail

main

public static void main(java.lang.String... strings)

join

public static java.lang.String join(java.util.List lst,
                                    java.lang.String delim)
joins a list into a string. similar to methods available IN ANY OTHER LANGUAGE

Parameters:
lst -
delim -
Returns:

underscoreSpaces

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

reverse

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

capitalize

public static java.lang.String capitalize(java.lang.String input)
capitalizes the first letter.

Parameters:
input -
Returns:

uncapitalize

public static java.lang.String uncapitalize(java.lang.String input)
lower cases the first letter

Parameters:
input -
Returns:

capitalizeWords

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

singularize

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

like

public static boolean like(java.lang.String str1,
                           java.lang.String str2)
Does a simple string compare, ignoring case and punctuation.

Parameters:
str1 -
str2 -
Returns:

contains

public static boolean contains(java.lang.String str1,
                               java.lang.String str2,
                               boolean wordBoundaries)
Checks if str1 contains str2. ignores case and punctuation and words 'the' 'a' 'to'. if wordBoundaries is true then it only returns true on word matches: ie. wordBoundaries = true : "jon johnson" matches "jon" or "johnson" wordBoundaries = false : matches all from above plus "john" "hnson" ect..

Parameters:
str1 -
str2 -
wordBoundaries -
Returns:

getRandomString

public static java.lang.String getRandomString(int length)
Generates a random string of length length, containing a-z, A-Z, 0-9


randomString

public static java.lang.String randomString(int length)
Generates a random string of length length, containing a-z, A-Z, 0-9


getRandomNumberString

public static java.lang.String getRandomNumberString(int length)

javascriptEscape

public static java.lang.String javascriptEscape(java.lang.String input)
escapes the string for use in javascript

Parameters:
input -
Returns:

camelize

public static java.lang.String camelize(java.lang.String word)

camelize

public static java.lang.String camelize(java.lang.String word,
                                        boolean lowercaseFirstLetter)
camel cases the passed in string. spaces and underscores are removed and trigger a capitalization.

Parameters:
word -
Returns:

uncamelize

public static java.lang.String uncamelize(java.lang.String input)
uncamelizes the input string. does not lowercase anything, just adds a space infront of any capitals

Parameters:
input -
Returns:

contains

public static boolean contains(java.lang.String input,
                               java.lang.String... delimiters)
returns true if the input contains one or more of the delimiters.

Parameters:
input -
delimiters -
Returns:

equals

public static boolean equals(java.lang.String input,
                             boolean ignoreCase,
                             java.lang.String... str)
returns true if the input is equal to one of the passed in strs.

Parameters:
input -
delimiters -
Returns:

toPrettyString

public static java.lang.String toPrettyString(java.util.Map map)

toPrettyString

public static java.lang.String toPrettyString(java.lang.String[] array)

trimChars

public static java.lang.String trimChars(java.lang.String input,
                                         int num)
trims the specified number of chars off the END of the string. If num > input.length then a zero length string is returned.

Parameters:
input -
num -
Returns:

trim

public static java.lang.String trim(java.lang.String input,
                                    java.lang.String trim)
will trim off the front and back of the string. if trim = " " then it is the same as str.trim()

Parameters:
input -
trim -
Returns:

maxChars

public static java.lang.String maxChars(java.lang.String input,
                                        int max)
will return a string with max nmber of characters

Parameters:
input -
max -
Returns:

removeAll

public static java.lang.String removeAll(java.lang.String input,
                                         java.lang.String... toRemove)
removes all instances of the inputed strings. strings are matches not regexes.

Parameters:
input -
strings -
Returns:

removeAll

public static java.lang.String removeAll(java.lang.String input,
                                         char... toRemove)
removes all the requested characters. Implemented to be optimally fast.

Parameters:
input -
toRemove -
Returns:

matches

public static boolean matches(java.lang.String input,
                              java.lang.String... vals)
returns true if input equals one of the passed in strings.

Parameters:
input -
val -
Returns:

split

public static java.util.List<java.lang.String> split(java.lang.String input,
                                                     java.lang.String... delimiters)
splits the string based on the given delimiters.

Parameters:
input -
delimiters -
Returns:

sanitizeUrl

public static java.lang.String sanitizeUrl(java.lang.String url)
Just strips any non allowed characters. currently allow letters, digits and $ - _ . + ! * ' ( ) , { } | \ ^ ~ [ ] ` " > < # % ; / ? & =

Parameters:
url -
Returns:

sha1

public static byte[] sha1(byte[] bytes)
returns a 20 byte sha1 hash

Parameters:
bytes -
Returns:

secureId

public static byte[] secureId()
Generates a cryptographically secure ID. Should reasonably be unique, though that is not guarenteed. result is 20 bytes long.