org.znerd.util.text
Class TextUtils

java.lang.Object
  extended by org.znerd.util.text.TextUtils

public class TextUtils
extends Object

Text string utility functions.


Method Summary
static boolean fuzzyEquals(String s1, String s2)
          Compares the specified strings for equality, after normalizing whitespace and ignoring case.
static boolean isEmpty(String s)
          Checks if the specified string is either null or empty or contains only whitespace.
static boolean matches(String s, String regex)
          Checks if the specified string matches the specified regular expression.
static String normalizeWhitespace(String s)
          Removes all leading and trailing whitespace from a string, and replaces all internal whitespace with a single space character.
static String quote(Object o)
          Puts quote characters around the string representation of an object, escaping all backslash and quote characters inside the string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

quote

public static final String quote(Object o)
Puts quote characters around the string representation of an object, escaping all backslash and quote characters inside the string. Returns "(null)" if the object is null or if the object's toString() method returns null.


isEmpty

public static final boolean isEmpty(String s)
Checks if the specified string is either null or empty or contains only whitespace.


matches

public static final boolean matches(String s,
                                    String regex)
Checks if the specified string matches the specified regular expression.

This method differs from String.matches(String) in that this method also supports partial matches. To give an example:

 "bla bla".match("bla$"); // returns false
 TextUtils.matches("bla bla", "bla$"); // returns true
 


fuzzyEquals

public static boolean fuzzyEquals(String s1,
                                  String s2)
Compares the specified strings for equality, after normalizing whitespace and ignoring case.

Parameters:
s1 - the first string, or null.
s2 - the second string, or null.
Returns:
if s1 and s2 are considered equal, normalizing whitespace and ignoring case.

normalizeWhitespace

public static String normalizeWhitespace(String s)
Removes all leading and trailing whitespace from a string, and replaces all internal whitespace with a single space character. If null is passed, then "" is returned.

Parameters:
s - the string, or null.
Returns:
the string with all leading and trailing whitespace removed and all internal whitespace normalized, never null.


Copyright © 2011-2013. All Rights Reserved.