org.apache.lucene.util
Class StringUtil

Object
  extended by StringUtil

public class StringUtil
extends Object

Provides some handy utilities missing from the Java String class, such as splitting on spaces, and joining with spaces, as well as case mapping.

Author:
Martin Haye

Field Summary
private static Pattern spacePat
          Used for splitting strings on spaces
 
Constructor Summary
StringUtil()
           
 
Method Summary
static String copyCase(String pattern, String in)
          Examines the pattern string to see whether it's lowercase, uppercase, or title case, and then applies that case to the given input string.
static String escapeHTMLChars(String in)
          Replaces 'special' HTML characters with their corresponding character entity references.
static boolean isLowerCase(String in)
          Check if the given string is all lower-case
static boolean isTitleCase(String in)
          Checks if the given string is "title case", i.e. the first letter is uppercase and the rest are lower case.
static boolean isUpperCase(String in)
          Check if the given string is all upper-case
static String join(Object[] in)
          Join a number of strings (or other objects) into a single string, separated by spaces.
static String join(Object[] in, String separator)
          Join a number of strings (or other objects) into a single string.
static String justifyLeft(String in, int len)
          Same as padEnd(String, int)
static String justifyRight(String in, int len)
          Same as padStart(String, int)
static String padEnd(String in, int len)
          Pad the end of a string with spaces to make its final length >= len
static String padEnd(String in, int len, char padChar)
          Pad the end of a string with the given character to make its final length >= len
static String padStart(String in, int len)
          Pad the start of a string with spaces to make its final length >= len
static String padStart(String in, int len, char padChar)
          Pad the start of a string with the given character to make its final length >= len
static String[] splitWords(String in)
          Break a string up into words, defined by whitespace boundaries.
static String toTitleCase(String in)
          Convert a string to "title case", i.e. making the first letter of each word uppercase, and the rest of the letters lowercase.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

spacePat

private static final Pattern spacePat
Used for splitting strings on spaces

Constructor Detail

StringUtil

public StringUtil()
Method Detail

join

public static String join(Object[] in)
Join a number of strings (or other objects) into a single string, separated by spaces. Each object's toString() method will be used.

Parameters:
in - array of Strings or objects to join
Returns:
the joined string

join

public static String join(Object[] in,
                          String separator)
Join a number of strings (or other objects) into a single string. Each object's toString() method will be used.

Parameters:
in - array of Strings or objects to join
separator - a string to put between them
Returns:
the joined string

padEnd

public static String padEnd(String in,
                            int len)
Pad the end of a string with spaces to make its final length >= len


justifyLeft

public static String justifyLeft(String in,
                                 int len)
Same as padEnd(String, int)


padEnd

public static String padEnd(String in,
                            int len,
                            char padChar)
Pad the end of a string with the given character to make its final length >= len


padStart

public static String padStart(String in,
                              int len)
Pad the start of a string with spaces to make its final length >= len


justifyRight

public static String justifyRight(String in,
                                  int len)
Same as padStart(String, int)


padStart

public static String padStart(String in,
                              int len,
                              char padChar)
Pad the start of a string with the given character to make its final length >= len


copyCase

public static String copyCase(String pattern,
                              String in)
Examines the pattern string to see whether it's lowercase, uppercase, or title case, and then applies that case to the given input string. If the pattern doesn't match any of the categories, we return the input string unchanged.

Parameters:
pattern - string to examine for case
in - string to convert to the same case as 'pattern'
Returns:
resulting converted form of 'in'

isUpperCase

public static boolean isUpperCase(String in)
Check if the given string is all upper-case


isLowerCase

public static boolean isLowerCase(String in)
Check if the given string is all lower-case


isTitleCase

public static boolean isTitleCase(String in)
Checks if the given string is "title case", i.e. the first letter is uppercase and the rest are lower case. If the string has multiple words, checks if *each* word is title case.


toTitleCase

public static String toTitleCase(String in)
Convert a string to "title case", i.e. making the first letter of each word uppercase, and the rest of the letters lowercase.


splitWords

public static String[] splitWords(String in)
Break a string up into words, defined by whitespace boundaries.

Parameters:
in - a string to break up
Returns:
an array of the words in the string

escapeHTMLChars

public static String escapeHTMLChars(String in)
Replaces 'special' HTML characters with their corresponding character entity references. For instance, '<' is replaced by '&lt;'.

Parameters:
in - The string to work on
Returns:
A modified version with special characters replaced