com.mwc.sqld.db
Class Soundex

java.lang.Object
  |
  +--com.mwc.sqld.db.Soundex

public class Soundex
extends java.lang.Object


Field Summary
protected  boolean DropLastSBoolean
          If true, the final 's' of the word being encoded is dropped.
protected  int LengthInt
          Length of code to build.
static int NO_MAX
          Possible code length.
protected  boolean PadBoolean
          If true, codes are padded to the LengthInt with zeros.
protected  int[] SoundexInts
          Soundex code table.
 
Constructor Summary
Soundex()
           
 
Method Summary
protected static int[] createArray()
          Creates the Soundex code table.
 java.lang.String encode(java.lang.String word)
          Returns the soundex code for the specified word.
 int getCode(char ch)
          Returns the Soundex code for the specified character.
 boolean getDropLastS()
          If true, a final char of 's' or 'S' of the word being encoded will be dropped.
 int getLength()
          The length of code strings to build, 4 by default.
 boolean getPad()
          If true, appends zeros to a soundex code if the code is less than Soundex.getLength().
static void main(java.lang.String[] strings)
          Encodes the args to stdout.
protected  java.lang.String reduce(java.lang.String word)
          Removes adjacent sounds.
 void setCode(char ch, int code)
          Allows you to modify the default code table
 void setDropLastS(boolean bool)
          If true, a final char of 's' or 'S' of the word being encoded will be dropped.
 void setLength(int length)
          Sets the length of code strings to build.
 void setPad(boolean bool)
          If true, appends zeros to a soundex code if the code is less than Soundex.getLength().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_MAX

public static final transient int NO_MAX
Possible code length.
See Also:
setLength(int)

DropLastSBoolean

protected boolean DropLastSBoolean
If true, the final 's' of the word being encoded is dropped.

LengthInt

protected int LengthInt
Length of code to build.

PadBoolean

protected boolean PadBoolean
If true, codes are padded to the LengthInt with zeros.

SoundexInts

protected int[] SoundexInts
Soundex code table.
Constructor Detail

Soundex

public Soundex()
Method Detail

encode

public java.lang.String encode(java.lang.String word)
Returns the soundex code for the specified word.
Parameters:
string - The word to encode.

getCode

public int getCode(char ch)
Returns the Soundex code for the specified character.
Parameters:
ch - Should be between A-Z or a-z
Returns:
-1 if the character has no phonetic code.

getDropLastS

public boolean getDropLastS()
If true, a final char of 's' or 'S' of the word being encoded will be dropped. By dropping the last s, lady and ladies for example, will encode the same. False by default.

getLength

public int getLength()
The length of code strings to build, 4 by default. If negative, length is unlimited.
See Also:
NO_MAX

getPad

public boolean getPad()
If true, appends zeros to a soundex code if the code is less than Soundex.getLength(). True by default.

main

public static void main(java.lang.String[] strings)
Encodes the args to stdout.

setCode

public void setCode(char ch,
                    int code)
Allows you to modify the default code table
Parameters:
ch - The character to specify the code for.
code - The code to represent ch with, must be -1, or 1 thru 9

setDropLastS

public void setDropLastS(boolean bool)
If true, a final char of 's' or 'S' of the word being encoded will be dropped.

setLength

public void setLength(int length)
Sets the length of code strings to build. 4 by default.
Parameters:
Length - of code to produce, must be >= 1

setPad

public void setPad(boolean bool)
If true, appends zeros to a soundex code if the code is less than Soundex.getLength(). True by default.

createArray

protected static int[] createArray()
Creates the Soundex code table.

reduce

protected java.lang.String reduce(java.lang.String word)
Removes adjacent sounds.