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:
for license details.
The copyright to this program is held by it's authors.

Field Summary
private  String source
          The baseline text.
private  String target
          The changed text.
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.
 void setSource(String newSource)
           
 void setTarget(String newTarget)
           
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 String source
The baseline text.


target

private String target
The changed text.

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

setSource

public void setSource(String newSource)
Parameters:
newSource - the source to set

setTarget

public void setTarget(String newTarget)
Parameters:
newTarget - the target to set

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 -

Copyright ? 2003-2011