Class WordDiffer

java.lang.Object
generic.algorithms.WordDiffer

public class WordDiffer NEW extends Object
Finds differences between two words (any two Strings). The results are available via getParts().
  • Constructor Details

    • WordDiffer

      public WordDiffer(String oldWord, String newWord)
      Diffs the text between the old and new word. The new word is the current version of two Strings, the old word is the previous version.
      Parameters:
      oldWord - the previous version of the text
      newWord - the current version of the text
  • Method Details

    • getParts

      public List<WordDiffer.WordPart> getParts()
      Returns the 'new word' broken into Strings with offsets, with each part being the same text or different text.
      Returns:
      the parts; empty if the LCS could not be created
    • getMergedParts

      public List<WordDiffer.WordPart> getMergedParts(int maxSize)
      The same as getParts() except that this method will merge differences that are separated only by maxSize or less characters. This method allows clients to combine many smaller differences into larger differences that span similar characters. Merging parts can reduce visual clutter when displaying the differences, at the expense of accuracy.
      Parameters:
      maxSize - the maximum span of characters past which not to merge two differences
      Returns:
      the parts
    • toString

      public String toString()
      Overrides:
      toString in class Object