LibreOffice Module xmerge (master) 1
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
org.openoffice.xmerge.merger.Difference Class Reference

This is the Difference basic unit. More...

Public Member Functions

 Difference (int operation, int orgPosition, int modPosition)
 Constructor. More...
 
int getOperation ()
 Get the operation of the Difference. More...
 
int getOrgPosition ()
 Get the original Iterator position. More...
 
int getModPosition ()
 Get the modified Iterator position. More...
 
boolean equals (Object obj)
 Two Difference objects will equal if and only if all operation, orgPosition, modPosition and content are equal. More...
 
int hashCode ()
 
String debug ()
 Display debug information. More...
 
String toString ()
 Returns position and operation values as a single string. More...
 

Static Public Attributes

static final int ADD = 1
 Add operation. More...
 
static final int DELETE = 2
 Delete operation. More...
 
static final int CHANGE = 3
 Change operation. More...
 
static final int UNCHANGE = 4
 Unchange operation (i.e. More...
 

Private Attributes

final int operation
 The action of the diff - either ADD or DELETE. More...
 
final int orgPosition
 The position of the content that should be operated on (original iterator). More...
 
final int modPosition
 The position of the content that should be operated (modified iterator). More...
 

Detailed Description

This is the Difference basic unit.

Used by the DiffAlgorithm as a set of difference between two Iterators (the original and modified Iterators).

Definition at line 27 of file Difference.java.

Constructor & Destructor Documentation

◆ Difference()

org.openoffice.xmerge.merger.Difference.Difference ( int  operation,
int  orgPosition,
int  modPosition 
)
inline

Constructor.

This is the standard way to create a Difference object.

Parameters
operationEither ADD or DELETE.
orgPositionThe position in the original (first) Iterator.
modPositionThe position in the modified (second) Iterator.

Definition at line 120 of file Difference.java.

References org.openoffice.xmerge.merger.Difference.modPosition, org.openoffice.xmerge.merger.Difference.operation, and org.openoffice.xmerge.merger.Difference.orgPosition.

Referenced by org.openoffice.xmerge.merger.Difference.equals().

Member Function Documentation

◆ debug()

String org.openoffice.xmerge.merger.Difference.debug ( )
inline

◆ equals()

boolean org.openoffice.xmerge.merger.Difference.equals ( Object  obj)
inline

Two Difference objects will equal if and only if all operation, orgPosition, modPosition and content are equal.

Parameters
objObject to compare.
Returns
true if equal, false otherwise.

Definition at line 165 of file Difference.java.

References org.openoffice.xmerge.merger.Difference.Difference(), org.openoffice.xmerge.merger.Difference.modPosition, org.openoffice.xmerge.merger.Difference.operation, and org.openoffice.xmerge.merger.Difference.orgPosition.

◆ getModPosition()

int org.openoffice.xmerge.merger.Difference.getModPosition ( )
inline

Get the modified Iterator position.

Returns
The position in the modified (second) Iterator.

Definition at line 151 of file Difference.java.

References org.openoffice.xmerge.merger.Difference.modPosition.

Referenced by org.openoffice.xmerge.merger.merge.CharacterBaseParagraphMerge.coreMerge().

◆ getOperation()

int org.openoffice.xmerge.merger.Difference.getOperation ( )
inline

Get the operation of the Difference.

Returns
the operation of the Difference, either ADD or DELETE.

Definition at line 133 of file Difference.java.

References org.openoffice.xmerge.merger.Difference.operation.

Referenced by org.openoffice.xmerge.merger.merge.CharacterBaseParagraphMerge.coreMerge().

◆ getOrgPosition()

int org.openoffice.xmerge.merger.Difference.getOrgPosition ( )
inline

Get the original Iterator position.

Returns
The position in the original (first) Iterator.

Definition at line 142 of file Difference.java.

References org.openoffice.xmerge.merger.Difference.orgPosition.

Referenced by org.openoffice.xmerge.merger.merge.CharacterBaseParagraphMerge.applyDifference(), and org.openoffice.xmerge.merger.merge.CharacterBaseParagraphMerge.coreMerge().

◆ hashCode()

int org.openoffice.xmerge.merger.Difference.hashCode ( )
inline

Definition at line 179 of file Difference.java.

◆ toString()

String org.openoffice.xmerge.merger.Difference.toString ( )
inline

Returns position and operation values as a single string.

Returns
orgPosition, modPosition and operation as a single String.

Definition at line 219 of file Difference.java.

References org.openoffice.xmerge.merger.Difference.modPosition, org.openoffice.xmerge.merger.Difference.operation, org.openoffice.xmerge.merger.Difference.orgPosition, and String.

Member Data Documentation

◆ ADD

final int org.openoffice.xmerge.merger.Difference.ADD = 1
static

◆ CHANGE

final int org.openoffice.xmerge.merger.Difference.CHANGE = 3
static

◆ DELETE

final int org.openoffice.xmerge.merger.Difference.DELETE = 2
static

◆ modPosition

final int org.openoffice.xmerge.merger.Difference.modPosition
private

◆ operation

final int org.openoffice.xmerge.merger.Difference.operation
private

◆ orgPosition

final int org.openoffice.xmerge.merger.Difference.orgPosition
private

The position of the content that should be operated on (original iterator).

For ADD, the orgPosition is the position of the original sequence where the diff will insert (the element count is starting from 0, and always insert before the element). The modPosition is the position of the diff in the modified sequence (also starting from 0).

example:

diff - <B D> and <A B C D E F>
note: <B D> is original sequence and <A B C D E F>
is the modified one.

and here is the position of those sequence:
<B D> <A B C D E F>
0 1 0 1 2 3 4 5

result:
<diff orgPos=0 modPos=0 operation=ADD> <-- element A
<diff orgPos=1 modPos=2 operation=ADD> <-- element C
<diff orgPos=2 modPos=4 operation=ADD> <-- element E
<diff orgPos=2 modPos=5 operation=ADD> <-- element F

One can notice the add operation is inserted before the position. Hence, in order to append an element, we will have a position of original sequence length + 1 to denote an append.

For DELETE, orgPosition is the position that the element will be deleted (starting from 0) and modPosition is the position where the deleted element should be (consider as an ADD).

The modPosition is less useful and it is difficult to understand how the position is calculated. One can just skip this piece of information. It is useful if one wants to reverse the role of original sequence and modified sequence and find out the diff easily (just change add to delete and delete to add for operation and swap the orgPosition and modPosition).

example:

diff - <A B C D E F> and <B D>
note: <A B C D E F> is original sequence and <B D>
is the modified one.

and here is the position of those sequence:
<A B C D E F> <B D>
0 1 2 3 4 5 0 1

result:
<diff orgPos=0 modPos=0 operation=DELETE> <-- element A
<diff orgPos=2 modPos=1 operation=DELETE> <-- element C
<diff orgPos=4 modPos=2 operation=DELETE> <-- element E
<diff orgPos=5 modPos=2 operation=DELETE> <-- element F

Definition at line 102 of file Difference.java.

Referenced by org.openoffice.xmerge.merger.Difference.debug(), org.openoffice.xmerge.merger.Difference.Difference(), org.openoffice.xmerge.merger.Difference.equals(), org.openoffice.xmerge.merger.Difference.getOrgPosition(), and org.openoffice.xmerge.merger.Difference.toString().

◆ UNCHANGE

final int org.openoffice.xmerge.merger.Difference.UNCHANGE = 4
static

The documentation for this class was generated from the following file: