to.etc.util
Class Soundex

java.lang.Object
  extended by to.etc.util.Soundex

public class Soundex
extends java.lang.Object

Encodes words using the SOUNDEX algorithm.

Author:
Frits Jalvingh

Field Summary
protected  int[] m_soundexInts
          Table
static int NO_MAX
          Length,
 
Constructor Summary
Soundex()
          Creates the Soundex code table.
 
Method Summary
 int getCode(char c)
          Returns the Soundex code for the specified character.
 boolean getDropLastS()
          If true, the final 's' or 'S' of the word being encoded is dropped.
 int getLength()
          Returns the length of code strings to build, 4 by default.
 boolean getPad()
          If true and a word is coded to a shorter length than getLength(), the code will be padded with zeros.
static void main(java.lang.String[] strings)
          Displays the codes for the parameters.
protected  java.lang.String reduce(java.lang.String string)
          Removes adjacent sounds.
 void setCode(char c, int i)
          Allows you to modify the default code table
 void setDropLastS(boolean bool)
          If true, the final 's' of the word being encoded is dropped.
 void setLength(int lengthInt)
          Sets the length of code strings to build.
 void setPad(boolean bool)
          If true, pads code to getLength() with zeros.
 java.lang.String soundex(java.lang.String string)
          Returns the soundex code for the specified word.
 
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
Length,

See Also:
Constant Field Values

m_soundexInts

protected int[] m_soundexInts
Table

Constructor Detail

Soundex

public Soundex()
Creates the Soundex code table. You can over-ride to build your own default table.

Method Detail

getCode

public int getCode(char c)
Returns the Soundex code for the specified character. If the char is not in the range a-z or A-Z then -1 is returned.


getDropLastS

public boolean getDropLastS()
If true, the final 's' or 'S' of the word being encoded is dropped. False by default.


getLength

public int getLength()
Returns 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 and a word is coded to a shorter length than getLength(), the code will be padded with zeros. True by default.


soundex

public java.lang.String soundex(java.lang.String string)
Returns the soundex code for the specified word. Characters not in the range a-z or A-Z are dropped.

Parameters:
string - The word to code.

main

public static void main(java.lang.String[] strings)
Displays the codes for the parameters.


setCode

public void setCode(char c,
                    int i)
Allows you to modify the default code table

Parameters:
c - The character to specify the code for.
i - The code to represent c with, must -1, or 0 thru 9

setDropLastS

public void setDropLastS(boolean bool)
If true, the final 's' of the word being encoded is dropped.


setLength

public void setLength(int lengthInt)
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, pads code to getLength() with zeros. True, by default.


reduce

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