org.loom.util
Class StringUtils

java.lang.Object
  extended by org.apache.commons.lang.StringUtils
      extended by org.loom.util.StringUtils

public class StringUtils
extends org.apache.commons.lang.StringUtils


Field Summary
 
Fields inherited from class org.apache.commons.lang.StringUtils
EMPTY, INDEX_NOT_FOUND
 
Constructor Summary
StringUtils()
           
 
Method Summary
static void addReplaceChars(char from, char replacement)
           
static void addReplaceChars(char from, char to, char replacement)
           
static long alphaToNumber(java.lang.String text)
          Convert a short alphanumeric representation back to the original number using Base58
static java.lang.String calculateMD5(byte[] text)
          Calculate the MD5 hash for the given byte array
static java.lang.String calculateMD5(org.springframework.core.io.Resource resource)
          Calculate the MD5 hash for the given resource
static java.lang.String camelCase(java.lang.String... args)
           
static java.lang.String camelCaseWithSeparators(java.lang.String text, java.lang.String separators)
          Returns the camelCase result after using the provided separators array to split the string into words.
static boolean compare(java.lang.String s1, java.lang.String s2, int from, int to)
          Compares two Strings between the given chars
static java.lang.String dasherize(java.lang.String text)
          Converts a camelCase string to a dash-separated one.
static java.lang.String generateIdentifier(java.lang.String text)
          Transforms a text into an identifier candidate to be used in RESTful URLs.
static boolean hasDigits(java.lang.String s)
           
static boolean hasProtocolPrefix(java.lang.StringBuilder uri)
          Return true if the StringBuilder passed as parameter starts with a known web prefix.
static java.lang.String numberToAlpha(long number)
          Convert a number into its (shorter) alphanumeric representation using Base58 chars ([0-9a-zA-Z] omitting 0, O, I and 1)
static java.lang.String separate(java.lang.String text, char separator)
          Converts a camelCase string to a separated one.
static java.lang.String toMD5(java.lang.String text)
           
static java.lang.String toString(java.security.MessageDigest md)
          Transform a MessageDigest instance into its string representation
 
Methods inherited from class org.apache.commons.lang.StringUtils
abbreviate, abbreviate, capitalise, capitaliseAllWords, capitalize, center, center, center, chomp, chomp, chompLast, chompLast, chop, chopNewline, clean, concatenate, contains, contains, containsAny, containsAny, containsIgnoreCase, containsNone, containsNone, containsOnly, containsOnly, countMatches, defaultIfEmpty, defaultString, defaultString, deleteSpaces, deleteWhitespace, difference, endsWith, endsWithIgnoreCase, equals, equalsIgnoreCase, escape, getChomp, getCommonPrefix, getLevenshteinDistance, getNestedString, getNestedString, getPrechomp, indexOf, indexOf, indexOf, indexOf, indexOfAny, indexOfAny, indexOfAny, indexOfAnyBut, indexOfAnyBut, indexOfDifference, indexOfDifference, isAlpha, isAlphanumeric, isAlphanumericSpace, isAlphaSpace, isAsciiPrintable, isBlank, isEmpty, isNotBlank, isNotEmpty, isNumeric, isNumericSpace, isWhitespace, join, join, join, join, join, join, join, join, join, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOfAny, left, leftPad, leftPad, leftPad, length, lowerCase, mid, ordinalIndexOf, overlay, overlayString, prechomp, remove, remove, removeEnd, removeEndIgnoreCase, removeStart, removeStartIgnoreCase, repeat, replace, replace, replaceChars, replaceChars, replaceEach, replaceEachRepeatedly, replaceOnce, reverse, reverseDelimited, reverseDelimitedString, right, rightPad, rightPad, rightPad, split, split, split, split, splitByCharacterType, splitByCharacterTypeCamelCase, splitByWholeSeparator, splitByWholeSeparator, splitByWholeSeparatorPreserveAllTokens, splitByWholeSeparatorPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, startsWith, startsWithIgnoreCase, strip, strip, stripAll, stripAll, stripEnd, stripStart, stripToEmpty, stripToNull, substring, substring, substringAfter, substringAfterLast, substringBefore, substringBeforeLast, substringBetween, substringBetween, substringsBetween, swapCase, trim, trimToEmpty, trimToNull, uncapitalise, uncapitalize, upperCase
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtils

public StringUtils()
Method Detail

addReplaceChars

public static void addReplaceChars(char from,
                                   char to,
                                   char replacement)

addReplaceChars

public static void addReplaceChars(char from,
                                   char replacement)

camelCase

public static java.lang.String camelCase(java.lang.String... args)
Returns:
the camelcase concatenation of strings. Note: the first arg does not get uppercased. If needed, set the empty string as the first arg

camelCaseWithSeparators

public static java.lang.String camelCaseWithSeparators(java.lang.String text,
                                                       java.lang.String separators)
Returns the camelCase result after using the provided separators array to split the string into words. Example: camelCase("foo-bar.baz", "-.") = "fooBarBaz"


hasProtocolPrefix

public static boolean hasProtocolPrefix(java.lang.StringBuilder uri)
Return true if the StringBuilder passed as parameter starts with a known web prefix. This method will test for http://, https://, file:// and ://


compare

public static boolean compare(java.lang.String s1,
                              java.lang.String s2,
                              int from,
                              int to)
Compares two Strings between the given chars

Parameters:
s1 -
s2 -
from - the start index, inclusive
to - the end index, exclusive
Returns:
true if are equals, false otherwise

hasDigits

public static boolean hasDigits(java.lang.String s)
Returns:
true if the String passed as argument contains at least one digit

toMD5

public static java.lang.String toMD5(java.lang.String text)
Returns:
the MD5 hash of the provided String

calculateMD5

public static java.lang.String calculateMD5(byte[] text)
Calculate the MD5 hash for the given byte array

Parameters:
text - the text to hash
Returns:
the corresponding MD5

toString

public static java.lang.String toString(java.security.MessageDigest md)
Transform a MessageDigest instance into its string representation

Parameters:
md - the message digest to process
Returns:
the string representation of this digest

calculateMD5

public static java.lang.String calculateMD5(org.springframework.core.io.Resource resource)
                                     throws java.io.IOException
Calculate the MD5 hash for the given resource

Parameters:
resource - the resource to hash
Returns:
the corresponding MD5
Throws:
java.io.IOException

dasherize

public static java.lang.String dasherize(java.lang.String text)
Converts a camelCase string to a dash-separated one. Examples: myProperty ==> my-property MyProperty.something ==> my-property-something

Parameters:
text - the text to transform
Returns:
the dash-separated transformation of the provided text.

separate

public static java.lang.String separate(java.lang.String text,
                                        char separator)
Converts a camelCase string to a separated one. Receives the separator character

Parameters:
text - the text to transform
separator - the separator character to use
Returns:
the separated text.

generateIdentifier

public static java.lang.String generateIdentifier(java.lang.String text)
Transforms a text into an identifier candidate to be used in RESTful URLs. Spaces will be replaced by dashes, and everything that is not alphanumeric will be ignored Example: "My 2nd valentine (redux)" -> "my-second-valentine-redux"

Parameters:
text - the text to transform
Returns:
the transformed text
Throws:
java.lang.IllegalArgumentException - if the provided text cannot generate a valid identifier (that is, the generated identifier is empty or is '-')

numberToAlpha

public static java.lang.String numberToAlpha(long number)
Convert a number into its (shorter) alphanumeric representation using Base58 chars ([0-9a-zA-Z] omitting 0, O, I and 1)

Parameters:
number - the number to transform
Returns:
the text representation of this number

alphaToNumber

public static long alphaToNumber(java.lang.String text)
Convert a short alphanumeric representation back to the original number using Base58

Parameters:
text - the alphanumeric representation
Returns:
the original number