19package org.openoffice.xmerge.merger.diff;
21import java.util.ArrayList;
50 ArrayList<Difference> diffResult =
new ArrayList<Difference>();
57 diffResult.toArray(diffArray);
69 for (
int i = 0;
i < diffTable.length;
i++) {
70 StringBuilder sb =
new StringBuilder();
71 for (
int j = 0; j < diffTable[
i].length; j++) {
72 sb.append(
" ").append(diffTable[
i][j]).append(
" ");
95 diffTable =
new int[orgSeqlen][];
96 for (
int i = 0;
i < orgSeqlen;
i++) {
97 diffTable[
i] =
new int[modSeqlen];
105 Object orgSeqObject, modSeqObject;
107 for (orgSeqObject = orgSeq.
start(),
i = 1;
108 orgSeqObject !=
null;
109 orgSeqObject = orgSeq.
next(),
i++) {
111 for (modSeqObject = modSeq.
start(), j = 1;
112 modSeqObject !=
null;
113 modSeqObject = modSeq.
next(), j++) {
115 if (orgSeq.
equivalent(orgSeqObject, modSeqObject)) {
116 diffTable[
i][j] = diffTable[
i-1][j-1]+1;
118 if (diffTable[
i-1][j] >= diffTable[
i][j-1]) {
119 diffTable[
i][j] = diffTable[
i-1][j];
121 diffTable[
i][j] = diffTable[
i][j-1];
148 int i,
int j, ArrayList<Difference> diffVector) {
151 if (
i == 0 && j == 0) {
155 for (
int cnt = 0; cnt <
i; cnt++) {
158 diffVector.add(diff);
163 for (
int cnt = 0; cnt < j; cnt++) {
166 diffVector.add(diff);
173 if ((diffTable[
i-1][j-1] == diffTable[
i][j] -1) &&
174 (diffTable[
i-1][j-1] == diffTable[
i-1][j]) &&
175 (diffTable[
i-1][j-1] == diffTable[
i][j-1])) {
180 if (diffTable[
i-1][j] > diffTable[
i][j-1]) {
188 diffVector.add(diff);
189 }
else if (diffTable[
i-1][j] < diffTable[
i][j-1]) {
197 diffVector.add(diff);
205 diffVector.add(diff);
This is the Difference basic unit.
static final int CHANGE
Change operation.
static final int DELETE
Delete operation.
static final int ADD
Add operation.
This is one of the implementations of DiffAlgorithm interface.
void printDiffTable(int[][] diffTable)
Debug function used to print out the nicely formatted difference table.
int[][] createDiffTable(Iterator orgSeq, Iterator modSeq)
Create the difference table.
Difference[] computeDiffs(Iterator orgSeq, Iterator modSeq)
Returns a Difference array.
void generateResult(int[][] diffTable, int i, int j, ArrayList< Difference > diffVector)
Generate the Difference object result vector.
This class is used for logging debug messages.
static final int INFO
Informational messages.
static boolean isFlagSet(int f)
Checks if flag is set.
static void log(int flag, String msg)
Log message based on the flag type.
This is the difference algorithm interface.
This is an interface used by the DiffAlgorithm and MergeAlgorithm to access a Document.
int elementCount()
Return the total element count in the sequence.
boolean equivalent(Object obj1, Object obj2)
A method to allow the difference algorithm to test whether the obj1 and obj2 in the Iterator are cons...
Object start()
Move to the beginning of the sequence.
Object next()
Move to next element in the sequence.
The DiffAlgorithm and MergeAlgorithm are used to provide the merge capabilities of this project.
Provides general purpose utilities.
Provides interfaces for converting between two Document formats, and supports a "merge" interface for...