use of com.sksamuel.diffpatch.DiffMatchPatch.Patch in project muikku by otavanopisto.
the class CoOpsDmpDiffAlgorithm method createUnpatch.
private LinkedList<Patch> createUnpatch(LinkedList<Patch> patches) {
LinkedList<Patch> result = new LinkedList<>();
for (int patchIndex = 0, patchesLength = patches.size(); patchIndex < patchesLength; patchIndex++) {
Patch patch = patches.get(patchIndex);
Patch unpatch = new Patch();
unpatch.length1 = patch.length1;
unpatch.length2 = patch.length2;
unpatch.start1 = patch.start1;
unpatch.start2 = patch.start2;
for (int diffIndex = 0, diffsLength = patch.diffs.size(); diffIndex < diffsLength; diffIndex++) {
Diff diff = patch.diffs.get(diffIndex);
switch(diff.operation) {
case DELETE:
patch.diffs.add(new Diff(Operation.INSERT, diff.text));
break;
case INSERT:
patch.diffs.add(new Diff(Operation.DELETE, diff.text));
break;
case EQUAL:
patch.diffs.add(new Diff(diff.operation, diff.text));
break;
}
}
result.add(unpatch);
}
return result;
}
use of com.sksamuel.diffpatch.DiffMatchPatch.Patch in project muikku by otavanopisto.
the class CoOpsDmpDiffAlgorithm method unpatch.
@Override
public String unpatch(String data, String patch) throws CoOpsConflictException {
DiffMatchPatch diffMatchPatch = new DiffMatchPatch();
LinkedList<Patch> patches = createUnpatch(new LinkedList<Patch>(diffMatchPatch.patch_fromText(patch)));
Object[] patchResult = diffMatchPatch.patch_apply(patches, data);
for (boolean applied : (boolean[]) patchResult[1]) {
if (!applied) {
throw new CoOpsConflictException();
}
}
return (String) patchResult[0];
}
use of com.sksamuel.diffpatch.DiffMatchPatch.Patch in project muikku by otavanopisto.
the class CoOpsDmpDiffAlgorithm method patch.
@Override
public String patch(String data, String patch) throws CoOpsConflictException {
DiffMatchPatch diffMatchPatch = new DiffMatchPatch();
LinkedList<Patch> patches = new LinkedList<Patch>(diffMatchPatch.patch_fromText(patch));
Object[] patchResult = diffMatchPatch.patch_apply(patches, data);
for (boolean applied : (boolean[]) patchResult[1]) {
if (!applied) {
throw new CoOpsConflictException();
}
}
return (String) patchResult[0];
}
use of com.sksamuel.diffpatch.DiffMatchPatch.Patch in project muikku by otavanopisto.
the class HtmlMaterialCleaner method createPatch.
private String createPatch(String oldHtml, String newHtml) {
DiffMatchPatch diffMatchPatch = new DiffMatchPatch();
LinkedList<Diff> diffs = diffMatchPatch.diff_main(oldHtml, newHtml);
diffMatchPatch.diff_cleanupEfficiency(diffs);
LinkedList<Patch> patch = diffMatchPatch.patch_make(diffs);
return diffMatchPatch.patch_toText(patch);
}
Aggregations