Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.crosswire.common.diff
Class Diff

    java.lang.Object
      org.crosswire.common.diff.Diff

    public class Diff

extends Object

Computes the difference between two texts to create a list of differences. Based on the LGPL Diff_Match_Patch v1.5 javascript of Neil Fraser, Copyright (C) 2006 http://neil.fraser.name/software/diff_match_patch/

Author:
  DM Smith [dmsmith555 at yahoo dot com]
See Also:
  `for license details.
  The copyright to this program is held by it's authors.`

Field Summary
`private boolean` | `checkLines` Whether a slightly faster less optimal diff should be run.
`private String` | `source` The baseline text.
`private String` | `target` The changed text.

Constructor Summary
`Diff(String source, String target)` Construct an object that can find the differences between two texts.
`Diff(String source, String target, boolean checkLines)` Construct an object that can find the differences between two texts.

Method Summary
`List` | `compare()` Find the differences between two texts.
`private List` | `compute()` Find the differences between two texts.
`String` | `prettyHtml(List diffs)` Convert a Difference list into a pretty HTML report.
`int` | `xIndex(List diffs, int loc)` loc is a location in source, compute and return the equivalent location in target.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### source

    private String source

  The baseline text.

### target

    private String target

  The changed text.

### checkLines

    private boolean checkLines

  Whether a slightly faster less optimal diff should be run.

Constructor Detail

### Diff

    public Diff(String source,
                String target)

  Construct an object that can find the differences between two texts. Run a faster slightly less optimal diff. This constructor allows the 'checkLines' to be optional. Most of the time checkLines is wanted, so default to true.

  Parameters:
    `source` - Old string to be diffed
    `target` - New string to be diffed

### Diff

    public Diff(String source,
                String target,
                boolean checkLines)

  Construct an object that can find the differences between two texts.

  Parameters:
    `source` - Old string to be diffed
    `target` - New string to be diffed
    `checkLines` - Speedup flag. If false, then don't run a line-level diff first to identify the changed areas. If true, then run a faster slightly less optimal diff

Method Detail

### compare

    public List compare()

  Find the differences between two texts. Simplifies the problem by stripping any common prefix or suffix off the texts before diffing.

  Returns:
    List of Difference objects

### compute

    private List compute()

  Find the differences between two texts.

  Returns:
    List of Difference objects

### xIndex

    public int xIndex(List diffs,
                      int loc)

  loc is a location in source, compute and return the equivalent location in target. e.g. "The cat" vs "The big cat", 1->1, 5->8

  Parameters:
    `diffs` - List of Difference objects
    `loc` - Location within source
  Returns:
    Location within target

### prettyHtml

    public String prettyHtml(List diffs)

  Convert a Difference list into a pretty HTML report.

  Parameters:
    `diffs` - List of Difference objects
  Returns:
    HTML representation

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Copyright ¨ 2003-2007
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD