com.generationjava.lang
Class StringW

java.lang.Object
  |
  +--com.generationjava.lang.StringW

public final class StringW
extends java.lang.Object

A set of String library static methods. While extending String or StringBuffer would have been the nicest solution, that is not possible, so a simple set of static methods seems the most workable. Method ideas have so far been taken from the PHP4, Ruby and .NET languages.


Constructor Summary
StringW()
           
 
Method Summary
static int getLevenshteinDistance(java.lang.String s, java.lang.String t)
          Find the Levenshtein distance between two strings.
static java.lang.String interpolate(java.lang.String text, java.util.Map map)
          Interpolate variables into a String.
static boolean isMetaphoneEqual(java.lang.String str1, java.lang.String str2)
          Are the metaphones of two strings the same.
static java.lang.String join(java.lang.Object[] objs, java.lang.String sep, java.lang.String pre, java.lang.String post)
           
static java.lang.String metaphone(java.lang.String str)
          Find the metaphone value of a String.
static java.lang.String quoteRegularExpression(java.lang.String str)
          Quote a string so that it may be used in a regular expression without any parts of the string being considered as a part of the regular expression's control characters.
static java.lang.String soundex(java.lang.String str)
          Get the SoundEx value of a string.
static java.lang.String wordWrap(java.lang.String str)
          Create a word-wrapped version of a String.
static java.lang.String wordWrap(java.lang.String str, int width)
          Create a word-wrapped version of a String.
static java.lang.String wordWrap(java.lang.String str, int width, java.lang.String delim, java.lang.String split)
          Word-wrap a string.
static java.lang.String wordWrap(java.lang.String str, java.lang.String width, java.lang.String delim, java.lang.String split)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringW

public StringW()
Method Detail

join

public static java.lang.String join(java.lang.Object[] objs,
                                    java.lang.String sep,
                                    java.lang.String pre,
                                    java.lang.String post)

getLevenshteinDistance

public static int getLevenshteinDistance(java.lang.String s,
                                         java.lang.String t)
Find the Levenshtein distance between two strings. This is the number of changes needed to change one string into another. Where each change is a single character modification. This implemmentation of the levenshtein distance algorithm is from http://www.merriampark.com/ld.htm


soundex

public static java.lang.String soundex(java.lang.String str)
Get the SoundEx value of a string. This implementation is taken from the code-snippers on http://www.sourceforge.net/


metaphone

public static java.lang.String metaphone(java.lang.String str)
Find the metaphone value of a String. This is similar to the soundex algorithm, but better at finding similar sounding words.


isMetaphoneEqual

public static boolean isMetaphoneEqual(java.lang.String str1,
                                       java.lang.String str2)
Are the metaphones of two strings the same.


quoteRegularExpression

public static java.lang.String quoteRegularExpression(java.lang.String str)
Quote a string so that it may be used in a regular expression without any parts of the string being considered as a part of the regular expression's control characters.


wordWrap

public static java.lang.String wordWrap(java.lang.String str)
Create a word-wrapped version of a String. Wrap at 80 characters and use newlines as the delimiter. If a word is over 80 characters long use a - sign to split it.


wordWrap

public static java.lang.String wordWrap(java.lang.String str,
                                        int width)
Create a word-wrapped version of a String. Wrap at a specified width and use newlines as the delimiter. If a word is over the width in lenght use a - sign to split it.


wordWrap

public static java.lang.String wordWrap(java.lang.String str,
                                        java.lang.String width,
                                        java.lang.String delim,
                                        java.lang.String split)

wordWrap

public static java.lang.String wordWrap(java.lang.String str,
                                        int width,
                                        java.lang.String delim,
                                        java.lang.String split)
Word-wrap a string.

Parameters:
str - String to word-wrap
width - int to wrap at
delim - String to use to separate lines
split - String to use to split a word greater than width long
Returns:
String that has been word wrapped

interpolate

public static java.lang.String interpolate(java.lang.String text,
                                           java.util.Map map)
Interpolate variables into a String.



Copyright © 2000-2003 GenerationJava. All Rights Reserved.