de.hunsicker.util
Class Lcs

java.lang.Object
  |
  +--de.hunsicker.util.Lcs

public final class Lcs
extends java.lang.Object

Implementation of the Longest Common Subsequence algorithm.

Version:
1.0
Author:
Caitlin Howell
See Also:
http://www.ics.uci.edu/~eppstein/161/960229.html, http://hissa.nist.gov/dads/HTML/longestcommn.html

Constructor Summary
Lcs()
          Creates a new Lcs object.
Lcs(java.lang.String string1, java.lang.String string2)
          Creates a new Lcs object for the two given strings.
 
Method Summary
 void compute()
          Computes the longest common subsequence for the two given strings.
static Lcs compute(java.lang.String s1, java.lang.String s2)
          Computes the longest common subsequence for the two given strings.
 int getLength()
          Returns the longest common subsequence length.
 double getPercentage()
          Returns the similarity of the strings in percent.
 java.lang.String getString()
          Returns the longest common subsequence.
 void init(java.lang.String s1, java.lang.String s2)
          Sets the two strings to compute the longest common subsequence for and initializes the processing table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Lcs

public Lcs()
Creates a new Lcs object.


Lcs

public Lcs(java.lang.String string1,
           java.lang.String string2)
Creates a new Lcs object for the two given strings.

Parameters:
string1 - first string.
string2 - second string.
Method Detail

compute

public static Lcs compute(java.lang.String s1,
                          java.lang.String s2)
Computes the longest common subsequence for the two given strings.

Parameters:
s1 - first string.
s2 - second string.
Returns:
Lcs object with the computed information. Use the accessor methods to get the piece of information you need.
See Also:
getString(), getLength(), getPercentage()

getLength

public int getLength()
Returns the longest common subsequence length.

Returns:
the longest common subsequence length.

getPercentage

public double getPercentage()
Returns the similarity of the strings in percent.

Returns:
the similarity of the strings in percent.

getString

public java.lang.String getString()
Returns the longest common subsequence.

Returns:
the longest common subsequence.

compute

public void compute()
Computes the longest common subsequence for the two given strings.

See Also:
init(String, String), getString(), getLength(), getPercentage()

init

public void init(java.lang.String s1,
                 java.lang.String s2)
Sets the two strings to compute the longest common subsequence for and initializes the processing table.

Parameters:
s1 - first string.
s2 - second string.


Copyright © 1997-2005 Jalopy. All Rights Reserved.