Search in sources :

Example 1 with DiffMatchPatch

use of com.sksamuel.diffpatch.DiffMatchPatch 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];
}
Also used : DiffMatchPatch(com.sksamuel.diffpatch.DiffMatchPatch) CoOpsConflictException(fi.foyt.coops.CoOpsConflictException) DiffMatchPatch(com.sksamuel.diffpatch.DiffMatchPatch) Patch(com.sksamuel.diffpatch.DiffMatchPatch.Patch)

Example 2 with DiffMatchPatch

use of com.sksamuel.diffpatch.DiffMatchPatch 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];
}
Also used : DiffMatchPatch(com.sksamuel.diffpatch.DiffMatchPatch) CoOpsConflictException(fi.foyt.coops.CoOpsConflictException) DiffMatchPatch(com.sksamuel.diffpatch.DiffMatchPatch) Patch(com.sksamuel.diffpatch.DiffMatchPatch.Patch) LinkedList(java.util.LinkedList)

Example 3 with DiffMatchPatch

use of com.sksamuel.diffpatch.DiffMatchPatch 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);
}
Also used : Diff(com.sksamuel.diffpatch.DiffMatchPatch.Diff) DiffMatchPatch(com.sksamuel.diffpatch.DiffMatchPatch) Patch(com.sksamuel.diffpatch.DiffMatchPatch.Patch) DiffMatchPatch(com.sksamuel.diffpatch.DiffMatchPatch)

Aggregations

DiffMatchPatch (com.sksamuel.diffpatch.DiffMatchPatch)3 Patch (com.sksamuel.diffpatch.DiffMatchPatch.Patch)3 CoOpsConflictException (fi.foyt.coops.CoOpsConflictException)2 Diff (com.sksamuel.diffpatch.DiffMatchPatch.Diff)1 LinkedList (java.util.LinkedList)1