net.protempore.utils
Class StringUtils

java.lang.Object
  extended by net.protempore.utils.StringUtils

public final class StringUtils
extends java.lang.Object

A string utility class.


Method Summary
static java.lang.String capitalize(java.lang.String str)
          Capitalize the first letter of the given string, if necessary, returning str if it is null or empty or already capitalized.
static java.lang.String capitalizeInitials(java.lang.String str, char sep)
          Capitalize the first word of a given string, using the given sep character to determine word boundaries, and returning the original string if it was null or empty.
static java.lang.String closestAscii(java.lang.String str)
          Return closest ascii representation of a non-null string, or null for a null reference.
static boolean isEmpty(java.lang.String s)
          A null-safe method that returns true if and only if the given string reference is null or refers to an empty string.
static java.lang.String makeRandomString(char[] validChars, int strLen)
          Create a random string consisting of strLen characters randomly drawn from the given array of valid characters, which must be a non-null array containing at least 1 character.
static java.lang.String nullSafeTrim(java.lang.String s)
          A trim method that handles null references by returning null and otherwise performing the normal String.trim().
static java.lang.String uncapitalize(java.lang.String str)
          Uncapitalize the first letter of the given string, if necessary, returning str if it is null or empty or already uncapitalized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

closestAscii

public static java.lang.String closestAscii(java.lang.String str)
Return closest ascii representation of a non-null string, or null for a null reference. This method converts something like "café" into "cafe". It handles commonly found letters in European languages, as well as the fancy single- and double-quote symbols.

Parameters:
str - A string.
Returns:
A non-null string if input was non-null, with all non-ascii characters replaced with the closest ascii equivalent.

uncapitalize

public static java.lang.String uncapitalize(java.lang.String str)
Uncapitalize the first letter of the given string, if necessary, returning str if it is null or empty or already uncapitalized.

Parameters:
str - A string reference.
Returns:
The string, uncapitalized if necessary, or null of str was null.

capitalize

public static java.lang.String capitalize(java.lang.String str)
Capitalize the first letter of the given string, if necessary, returning str if it is null or empty or already capitalized.

Parameters:
str - A string reference.
Returns:
The string, capitalized if necessary, or null of str was null.

capitalizeInitials

public static java.lang.String capitalizeInitials(java.lang.String str,
                                                  char sep)
Capitalize the first word of a given string, using the given sep character to determine word boundaries, and returning the original string if it was null or empty.

Parameters:
str - A string.
sep - The separator character to use for determining word boundaries (e.g., ' ' for space-delimited, ',' for comma-delimited).
Returns:
The original string if given str was null or empty, or else a new string with each initial letter of a word capitalized.

nullSafeTrim

public static java.lang.String nullSafeTrim(java.lang.String s)
A trim method that handles null references by returning null and otherwise performing the normal String.trim().

Parameters:
s - A reference to a string, possibly null.
Returns:
Null if s is null, otherwise the trimmed string.

isEmpty

public static boolean isEmpty(java.lang.String s)
A null-safe method that returns true if and only if the given string reference is null or refers to an empty string.

Parameters:
s - A string reference, or null.
Returns:
True iff s is null or empty.

makeRandomString

public static java.lang.String makeRandomString(char[] validChars,
                                                int strLen)
Create a random string consisting of strLen characters randomly drawn from the given array of valid characters, which must be a non-null array containing at least 1 character.

Parameters:
validChars - A non-null array of 1 or more characters, from which will be drawn the characters of the string to be created.
strLen - The length of the string to be created, which must be non-negative.
Returns:
A non-empty string of length strLen containing only characters drawn from the validChars array.
Throws:
ValidationException - If validChars is null or empty or strLen is negative.