org.crosswire.common.diff
Class PatchEntry

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

public class PatchEntry
extends Object

A PatchEntry is a single "instruction" in a Patch, consisting of a interval over which differences are applied and the differences that should be applied. 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  List diffs
           
private static int margin
           
private static int MARGIN
          Chunk size for context length.
private static Pattern newlinePattern
           
private static Pattern patchPattern
           
private  int sourceLength
           
private  int sourceStart
           
private  int targetLength
           
private  int targetStart
           
 
Constructor Summary
PatchEntry()
           
PatchEntry(String patchText)
           
 
Method Summary
 void addContext(String text)
           
 void addDifference(Difference diff)
           
 void adjustSourceLength(int adjustment)
           
 void adjustSourceStart(int adjustment)
           
 void adjustTargetLength(int adjustment)
           
 void adjustTargetStart(int adjustment)
           
private  String decode(String str)
          Undo encoding
private  String encode(String str)
          This algorithm allows for \n to be included in a difference.
 PatchEntry fromText(String input)
          Parse a textual representation of a patch entry and populate this patch entry.
private  String getCoordinates(int start, int length)
           
 int getDifferenceCount()
           
 Difference getFirstDifference()
           
 Difference getLastDifference()
           
static int getMargin()
           
 int getSourceLength()
           
 int getSourceStart()
           
 String getSourceText()
           
 int getTargetLength()
           
 int getTargetStart()
           
 String getTargetText()
           
 boolean hasDifferences()
           
 Iterator iterator()
           
 Difference removeFirstDifference()
           
protected  void setDifferences(List newDiffs)
           
static void setMargin(int newMargin)
           
 void setSourceLength(int length)
           
 void setSourceStart(int start)
           
 void setTargetLength(int length)
           
 void setTargetStart(int start)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MARGIN

private static final int MARGIN
Chunk size for context length.

See Also:
Constant Field Values

margin

private static int margin

newlinePattern

private static Pattern newlinePattern

patchPattern

private static Pattern patchPattern

diffs

private List diffs

sourceStart

private int sourceStart

targetStart

private int targetStart

sourceLength

private int sourceLength

targetLength

private int targetLength
Constructor Detail

PatchEntry

public PatchEntry()

PatchEntry

public PatchEntry(String patchText)
Method Detail

getSourceStart

public int getSourceStart()
Returns:
the sourceStart

setSourceStart

public void setSourceStart(int start)
Parameters:
start - the sourceStart to set

adjustSourceStart

public void adjustSourceStart(int adjustment)
Parameters:
adjustment - the adjustment to sourceStart

getTargetStart

public int getTargetStart()
Returns:
the targetStart

setTargetStart

public void setTargetStart(int start)
Parameters:
start - the targetStart to set

adjustTargetStart

public void adjustTargetStart(int adjustment)
Parameters:
adjustment - the adjustment to targetStart

getSourceLength

public int getSourceLength()
Returns:
the sourceLength

setSourceLength

public void setSourceLength(int length)
Parameters:
length - the sourceLength to set

adjustSourceLength

public void adjustSourceLength(int adjustment)
Parameters:
adjustment - the adjustment to sourceLength

getTargetLength

public int getTargetLength()
Returns:
the targetLength

setTargetLength

public void setTargetLength(int length)
Parameters:
length - the targetLength to set

adjustTargetLength

public void adjustTargetLength(int adjustment)
Parameters:
adjustment - the adjustment to targetLength

toString

public String toString()
Overrides:
toString in class Object

fromText

public PatchEntry fromText(String input)
Parse a textual representation of a patch entry and populate this patch entry.

Parameters:
input - Text representation of this patch entry
Returns:
this patch entry

getSourceText

public String getSourceText()

getTargetText

public String getTargetText()

addContext

public void addContext(String text)

addDifference

public void addDifference(Difference diff)

getDifferenceCount

public int getDifferenceCount()

hasDifferences

public boolean hasDifferences()

iterator

public Iterator iterator()

getFirstDifference

public Difference getFirstDifference()

removeFirstDifference

public Difference removeFirstDifference()

getLastDifference

public Difference getLastDifference()

setDifferences

protected void setDifferences(List newDiffs)

setMargin

public static void setMargin(int newMargin)
Parameters:
newMargin - the margin to set

getMargin

public static int getMargin()
Returns:
the margin

getCoordinates

private String getCoordinates(int start,
                              int length)

encode

private String encode(String str)
This algorithm allows for \n to be included in a difference. Thus it needs to be escaped. We will use URL encoding of \n. But this makes % a meta-character, thus it needs to be encoded too.

Parameters:
str - the un-encoded string
Returns:
the encoded string

decode

private String decode(String str)
Undo encoding

Parameters:
str - the encoded string
Returns:
the un-encoded string

Copyright ยจ 2003-2007