org.crosswire.common.diff
Class DifferenceEngine

java.lang.Object
  extended by org.crosswire.common.diff.DifferenceEngine

public class DifferenceEngine
extends Object

Builds a map of a baseline/source text and a changed/target text, navigating it to determine 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
See Also:
The GNU Lesser General Public License for details.

Field Summary
private  String source
          Made final because we now rely on caching the string lengths (they could be cached at method level if require non-final in future) The baseline text.
private  int sourceLength
           
private  String target
          The changed text.
private  int targetLength
           
private static float timeout
           
private static float TIMEOUT
          Number of seconds to map a diff before giving up.
 
Constructor Summary
DifferenceEngine()
          Empty Difference Engine, which won't find anything.
DifferenceEngine(String source, String target)
          Find the differences between two texts.
 
Method Summary
 List<Difference> generate()
          Explore the intersection points between the two texts.
protected  List<Difference> path1(List<Set<String>> vMap, String newSource, String newTarget)
          Work from the middle back to the start to determine the path.
protected  List<Difference> path2(List<Set<String>> vMap, String newSource, String newTarget)
          Work from the middle back to the end to determine the path.
static void setTimeout(float newTimeout)
          Set the timeout for the diff operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMEOUT

private static final float TIMEOUT
Number of seconds to map a diff before giving up. Use 0 for infinity.

See Also:
Constant Field Values

timeout

private static float timeout

source

private final String source
Made final because we now rely on caching the string lengths (they could be cached at method level if require non-final in future) The baseline text.


target

private final String target
The changed text.


targetLength

private final int targetLength

sourceLength

private final int sourceLength
Constructor Detail

DifferenceEngine

public DifferenceEngine()
Empty Difference Engine, which won't find anything.


DifferenceEngine

public DifferenceEngine(String source,
                        String target)
Find the differences between two texts. Simplifies the problem by stripping any common prefix or suffix off the texts before diffing.

Parameters:
source - Old string to be diffed
target - New string to be diffed
Method Detail

generate

public List<Difference> generate()
Explore the intersection points between the two texts.

Returns:
List of Difference objects or null if no diff available

path1

protected List<Difference> path1(List<Set<String>> vMap,
                                 String newSource,
                                 String newTarget)
Work from the middle back to the start to determine the path.

Parameters:
vMap - List of path sets.
newSource - Old string fragment to be diffed
newTarget - New string fragment to be diffed
Returns:
List of Difference objects

path2

protected List<Difference> path2(List<Set<String>> vMap,
                                 String newSource,
                                 String newTarget)
Work from the middle back to the end to determine the path.

Parameters:
vMap - List of path sets.
newSource - Old string fragment to be diffed
newTarget - New string fragment to be diffed
Returns:
List of Difference objects

setTimeout

public static void setTimeout(float newTimeout)
Set the timeout for the diff operation. The default is 1 second. Use 0 for infinity.

Parameters:
newTimeout - the new timeout

Copyright ยจ 2003-2015