net.ontopia.utils
Class StringUtils

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

public class StringUtils
extends java.lang.Object

INTERNAL: Class that contains useful string operation methods.


Field Summary
static java.lang.String VERY_UNLIKELY_STRING
          INTERNAL: A string used internally for various control flow purposes.
 
Constructor Summary
StringUtils()
           
 
Method Summary
static int compare(java.lang.String s1, java.lang.String s2)
          INTERNAL: Compare two string values lexically.
static int compareToIgnoreCase(java.lang.String s1, java.lang.String s2)
          INTERNAL: Compare two string values lexically ignoring case.
static void downCaseAscii(char[] ch, int start, int length)
          INTERNAL: Convert the A-Z characters in the array region to a-z.
static java.lang.String escapeHTMLEntities(java.lang.String value)
          INTERNAL: Filters the specified string for characters that are senstive to HTML interpreters, returning the string with these characters replaced by the corresponding character entities.
static void escapeHTMLEntities(java.lang.String value, java.io.Writer out)
          INTERNAL: Filters the specified string for characters that are senstive to HTML interpreters, writing the string with these characters replaced by the corresponding character entities to the given writer.
static boolean isInteger(java.lang.String candidate)
          INTERNAL: Returns true if the string is a valid integer.
static java.lang.String join(boolean[] vals, java.lang.String separator)
          INTERNAL: Joins the booleans in an array (turned into strings by toString) with a separator string.
static java.lang.String join(byte[] vals, java.lang.String separator)
          INTERNAL: Joins the bytes in an array (turned into strings by toString) with a separator string.
static java.lang.String join(char[] vals, java.lang.String separator)
          INTERNAL: Joins the characters in an array (turned into strings by toString) with a separator string.
static java.lang.String join(java.util.Collection objects, java.lang.String separator)
          INTERNAL: Joins the objects in a collection (turned into strings by toString) with a separator string.
static void join(java.util.Collection objects, java.lang.String separator, java.lang.StringBuffer sb)
          INTERNAL: Joins the objects in a collection (turned into strings by toString) with a separator string.
static java.lang.String join(java.util.Collection objects, java.lang.String separator, StringifierIF stringifier)
          INTERNAL: Joins the objects in a collection (turned into strings by the stringifier) with a separator string.
static java.lang.String join(int[] vals, java.lang.String separator)
          INTERNAL: Joins the ints in an array (turned into strings by toString) with a separator string.
static java.lang.String join(long[] vals, java.lang.String separator)
          INTERNAL: Joins the longs in an array (turned into strings by toString) with a separator string.
static java.lang.String join(java.lang.Object[] objects, char separator)
          INTERNAL: Joins the objects in an array (turned into strings by toString) with a separator string.
static java.lang.String join(java.lang.Object[] objects, java.lang.String separator)
          INTERNAL: Joins the objects in an array (turned into strings by toString) with a separator string.
static java.lang.String join(java.lang.Object[] objects, java.lang.String separator, boolean remove_nulls)
          INTERNAL: Joins the non-null objects in an array (turned into strings by toString) with a separator string.
static void join(java.lang.Object[] objects, java.lang.String separator, java.lang.StringBuffer sb)
          INTERNAL: Joins the objects in an array (turned into strings by toString) with a separator string.
static java.lang.String makeRandomId(int length)
          INTERNAL: Make a random ID-like string of the given number of characters.
static java.lang.String md5_32(java.lang.String value)
          INTERNAL: Returns a 32 character long hex encoded MD5 digest of the given string.
static java.lang.String normalizeId(java.lang.String name)
          INTERNAL: Creates a candidate ID from an input string.
static java.lang.String normalizeIsWhitespace(java.lang.String source)
          INTERNAL: Replaces sequences of one or more characters that report as whitespace through Character.isWhitespace(char) by a single space, returning the new string.
static java.lang.String normalizeWhitespace(java.lang.String source)
          INTERNAL: Replaces sequences of one or more ' ', \t, \n, \r by a single space, returning the new string.
static java.lang.String pad(int number, char ch, int length)
          INTERNAL: Pad characters to the given length.
static java.lang.String pad(java.lang.String str, char ch, int length)
          INTERNAL: Pad with filler characters in front of a base string to get the given length.
static boolean regionEquals(java.lang.String str, char[] ch, int start, int length)
          INTERNAL: Test whether the string is equal to the given region of the character array.
static java.lang.String replace(java.lang.String str, char oldvalue, java.lang.String newvalue)
          INTERNAL: Replaces occurrences of a char within a string, returning a new string where the substitutions have been performed.
static java.lang.String replace(java.lang.String str, java.lang.String oldvalue, java.lang.String newvalue)
          INTERNAL: Replaces occurrences of a string within a string, returning a new string where the substitutions have been performed.
static java.lang.String[] split(java.lang.String str)
          INTERNAL: Splits a string on occurrences of a given substring.
static java.lang.String[] split(java.lang.String str, java.lang.String separator)
          INTERNAL: Splits a string on occurrences of a given substring.
static java.lang.String[] tokenize(java.lang.String str, java.lang.String delimiters)
          INTERNAL: Tokenizes a string on occurrences of a delimiters.
static java.lang.String transcode(java.lang.String original, java.lang.String encoding)
          INTERNAL: Transcode a string mistakenly interpreted as ISO 8859-1 to one interpreted as something else.
static java.lang.String transcodeUTF8(java.lang.String original)
          INTERNAL: Transcode a string mistakenly interpreted as ISO 8859-1 to one interpreted as UTF-8.
static java.lang.String[] trim(java.lang.String[] str)
          INTERNAL: Trims each individual string in the array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERY_UNLIKELY_STRING

public static final java.lang.String VERY_UNLIKELY_STRING
INTERNAL: A string used internally for various control flow purposes. It is a string that is extremely unlikely to occur in real-world data.

See Also:
Constant Field Values
Constructor Detail

StringUtils

public StringUtils()
Method Detail

replace

public static java.lang.String replace(java.lang.String str,
                                       java.lang.String oldvalue,
                                       java.lang.String newvalue)
INTERNAL: Replaces occurrences of a string within a string, returning a new string where the substitutions have been performed.


replace

public static java.lang.String replace(java.lang.String str,
                                       char oldvalue,
                                       java.lang.String newvalue)
INTERNAL: Replaces occurrences of a char within a string, returning a new string where the substitutions have been performed.

Since:
2.0

split

public static java.lang.String[] split(java.lang.String str)
INTERNAL: Splits a string on occurrences of a given substring. The separator is " ".


split

public static java.lang.String[] split(java.lang.String str,
                                       java.lang.String separator)
INTERNAL: Splits a string on occurrences of a given substring.


tokenize

public static java.lang.String[] tokenize(java.lang.String str,
                                          java.lang.String delimiters)
INTERNAL: Tokenizes a string on occurrences of a delimiters. This method is effectively using a java.util.StringTokenizer underneath.

Since:
3.1

trim

public static java.lang.String[] trim(java.lang.String[] str)
INTERNAL: Trims each individual string in the array. Note that this method will effectively replace the strings in the array. The string array is returned just for convenience.

Since:
3.1

join

public static java.lang.String join(java.util.Collection objects,
                                    java.lang.String separator)
INTERNAL: Joins the objects in a collection (turned into strings by toString) with a separator string.


join

public static java.lang.String join(java.util.Collection objects,
                                    java.lang.String separator,
                                    StringifierIF stringifier)
INTERNAL: Joins the objects in a collection (turned into strings by the stringifier) with a separator string.

Since:
2.0

join

public static java.lang.String join(java.lang.Object[] objects,
                                    java.lang.String separator)
INTERNAL: Joins the objects in an array (turned into strings by toString) with a separator string.


join

public static java.lang.String join(java.lang.Object[] objects,
                                    char separator)
INTERNAL: Joins the objects in an array (turned into strings by toString) with a separator string.

Since:
3.1

join

public static java.lang.String join(int[] vals,
                                    java.lang.String separator)
INTERNAL: Joins the ints in an array (turned into strings by toString) with a separator string.

Since:
1.3.4

join

public static java.lang.String join(long[] vals,
                                    java.lang.String separator)
INTERNAL: Joins the longs in an array (turned into strings by toString) with a separator string.

Since:
2.0

join

public static java.lang.String join(boolean[] vals,
                                    java.lang.String separator)
INTERNAL: Joins the booleans in an array (turned into strings by toString) with a separator string.

Since:
2.0

join

public static java.lang.String join(byte[] vals,
                                    java.lang.String separator)
INTERNAL: Joins the bytes in an array (turned into strings by toString) with a separator string.

Since:
2.0

join

public static java.lang.String join(char[] vals,
                                    java.lang.String separator)
INTERNAL: Joins the characters in an array (turned into strings by toString) with a separator string.

Since:
2.0

join

public static void join(java.util.Collection objects,
                        java.lang.String separator,
                        java.lang.StringBuffer sb)
INTERNAL: Joins the objects in a collection (turned into strings by toString) with a separator string. The result is appended to the specified StringBuffer.

Since:
1.3.2

join

public static void join(java.lang.Object[] objects,
                        java.lang.String separator,
                        java.lang.StringBuffer sb)
INTERNAL: Joins the objects in an array (turned into strings by toString) with a separator string. The result is appended to the specified StringBuffer.

Since:
1.3.2

join

public static java.lang.String join(java.lang.Object[] objects,
                                    java.lang.String separator,
                                    boolean remove_nulls)
INTERNAL: Joins the non-null objects in an array (turned into strings by toString) with a separator string. Note that nulls in the array are ignored.

Since:
1.2.5

compare

public static int compare(java.lang.String s1,
                          java.lang.String s2)
INTERNAL: Compare two string values lexically. This method can handle nulls values. Nulls sort lower than non-nulls.

Since:
3.1

compareToIgnoreCase

public static int compareToIgnoreCase(java.lang.String s1,
                                      java.lang.String s2)
INTERNAL: Compare two string values lexically ignoring case. This method can handle nulls values. Nulls sort lower than non-nulls.

Since:
3.1

normalizeWhitespace

public static java.lang.String normalizeWhitespace(java.lang.String source)
INTERNAL: Replaces sequences of one or more ' ', \t, \n, \r by a single space, returning the new string.


normalizeIsWhitespace

public static java.lang.String normalizeIsWhitespace(java.lang.String source)
INTERNAL: Replaces sequences of one or more characters that report as whitespace through Character.isWhitespace(char) by a single space, returning the new string.

Since:
3.3.0

regionEquals

public static boolean regionEquals(java.lang.String str,
                                   char[] ch,
                                   int start,
                                   int length)
INTERNAL: Test whether the string is equal to the given region of the character array.


downCaseAscii

public static void downCaseAscii(char[] ch,
                                 int start,
                                 int length)
INTERNAL: Convert the A-Z characters in the array region to a-z.


transcodeUTF8

public static java.lang.String transcodeUTF8(java.lang.String original)
INTERNAL: Transcode a string mistakenly interpreted as ISO 8859-1 to one interpreted as UTF-8.


transcode

public static java.lang.String transcode(java.lang.String original,
                                         java.lang.String encoding)
                                  throws java.io.UnsupportedEncodingException
INTERNAL: Transcode a string mistakenly interpreted as ISO 8859-1 to one interpreted as something else.

Throws:
java.io.UnsupportedEncodingException

escapeHTMLEntities

public static java.lang.String escapeHTMLEntities(java.lang.String value)
INTERNAL: Filters the specified string for characters that are senstive to HTML interpreters, returning the string with these characters replaced by the corresponding character entities.

Parameters:
value - The string to be filtered and returned
Since:
1.3.1

escapeHTMLEntities

public static void escapeHTMLEntities(java.lang.String value,
                                      java.io.Writer out)
                               throws java.io.IOException
INTERNAL: Filters the specified string for characters that are senstive to HTML interpreters, writing the string with these characters replaced by the corresponding character entities to the given writer.

Parameters:
value - The string to be filtered and written.
Throws:
java.io.IOException
Since:
3.0

makeRandomId

public static java.lang.String makeRandomId(int length)
INTERNAL: Make a random ID-like string of the given number of characters.


pad

public static java.lang.String pad(int number,
                                   char ch,
                                   int length)
INTERNAL: Pad characters to the given length.


pad

public static java.lang.String pad(java.lang.String str,
                                   char ch,
                                   int length)
INTERNAL: Pad with filler characters in front of a base string to get the given length.


md5_32

public static java.lang.String md5_32(java.lang.String value)
INTERNAL: Returns a 32 character long hex encoded MD5 digest of the given string. Hex letters are returned in lower case.


isInteger

public static boolean isInteger(java.lang.String candidate)
INTERNAL: Returns true if the string is a valid integer.


normalizeId

public static java.lang.String normalizeId(java.lang.String name)
INTERNAL: Creates a candidate ID from an input string. The algorithm discards characters above U+00FF, strips accents off remaining characters, then discards everything that doesn't match the LTM NAME production (except leading characters, which turn into underscores). Whitespace is normalized, and turns into a hyphen when internal to the string. Letters are lowercased.



Copyright © 2000-2012 Ontopia.