19package org.openoffice.xmerge.merger.diff;
21import java.util.ArrayList;
47 int orgSeqlen = orgSeq.length;
48 int modSeqlen = modSeq.length;
54 ArrayList<Difference> diffResult =
new ArrayList<Difference>();
61 diffResult.toArray(diffArray);
78 int orgSeqlen = orgSeq.length + 1;
79 int modSeqlen = modSeq.length + 1;
84 diffTable =
new int[orgSeqlen][];
85 for (
int i = 0;
i < orgSeqlen;
i++) {
86 diffTable[
i] =
new int[modSeqlen];
91 for (
int i = 1;
i < orgSeqlen;
i++) {
92 for (
int j = 1; j < modSeqlen; j++) {
94 if (orgSeq[
i-1] == modSeq[j-1]) {
95 diffTable[
i][j] = diffTable[
i-1][j-1]+1;
97 if (diffTable[
i-1][j] >= diffTable[
i][j-1]) {
98 diffTable[
i][j] = diffTable[
i-1][j];
100 diffTable[
i][j] = diffTable[
i][j-1];
127 ArrayList<Difference> diffVector) {
130 if (
i == 0 || j == 0) {
131 if (
i == 0 && j == 0) {
134 for (
int cnt = 0; cnt <
i; cnt++) {
137 diffVector.add(diff);
140 for (
int cnt = 0; cnt < j; cnt++) {
143 diffVector.add(diff);
151 if ((diffTable[
i-1][j-1] == diffTable[
i][j] -1) &&
152 (diffTable[
i-1][j-1] == diffTable[
i-1][j]) &&
153 (diffTable[
i-1][j-1] == diffTable[
i][j-1])) {
158 if (diffTable[
i-1][j] > diffTable[
i][j-1]) {
166 diffVector.add(diff);
167 }
else if (diffTable[
i-1][j] < diffTable[
i][j-1]) {
175 diffVector.add(diff);
183 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 an implementations of DiffAlgorithm interface which will difference char arrays.
void generateResult(int[][] diffTable, int i, int j, ArrayList< Difference > diffVector)
Generate the Difference result vector.
int[][] createDiffTable(char[] orgSeq, char[] modSeq)
Create the difference table.
Difference[] computeDiffs(char[] orgSeq, char[] modSeq)
Return an Difference array.
The DiffAlgorithm and MergeAlgorithm are used to provide the merge capabilities of this project.
Provides interfaces for converting between two Document formats, and supports a "merge" interface for...