Skip to content

Commit

Permalink
Revert "Merge pull request jakartaee#65 from wdonne/#61"
Browse files Browse the repository at this point in the history
This reverts commit df8105c, reversing
changes made to 4474200.
  • Loading branch information
lukasj committed Nov 2, 2017
1 parent deca68d commit 1b7c786
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 70 deletions.
62 changes: 26 additions & 36 deletions impl/src/main/java/org/glassfish/json/JsonPatchImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,42 +289,32 @@ private void diffArray(String path, JsonArray source, JsonArray target) {
}
}

emit(path, source, target, c, m, n);
}

private void emit(final String path,
final JsonArray source,
final JsonArray target,
final int[][] c,
final int i,
final int j) {
if (i == 0) {
if (j > 0) {
emit(path, source, target, c, i, j - 1);
builder.add(path + '/' + (j - 1), target.get(j - 1));
}
} else if (j == 0) {
if (i > 0) {
builder.remove(path + '/' + (i - 1));
emit(path, source, target, c, i - 1, j);
}
} else if ((c[i][j] & 1) == 1) {
emit(path, source, target, c, i - 1, j - 1);
} else {
final int f = c[i][j-1] >> 1;
final int g = c[i-1][j] >> 1;
if (f > g) {
emit(path, source, target, c, i, j - 1);
builder.add(path + '/' + (j - 1), target.get(j - 1));
} else if (f < g) {
builder.remove(path + '/' + (i - 1));
emit(path, source, target, c, i - 1, j);
} else { // f == g) {
diff(path + '/' + (i - 1), source.get(i - 1),
target.get(j - 1));
emit(path, source, target, c, i - 1, j - 1);
}
}
int i = m;
int j = n;
while (i > 0 || j > 0) {
if (i == 0) {
j--;
builder.add(path + '/' + j, target.get(j));
} else if (j == 0) {
i--;
builder.remove(path + '/' + i);
} else if ((c[i][j] & 1) == 1) {
i--; j--;
} else {
int f = c[i][j-1] >> 1;
int g = c[i-1][j] >> 1;
if (f > g) {
j--;
builder.add(path + '/' + j, target.get(j));
} else if (f < g) {
i--;
builder.remove(path + '/' + i);
} else { // f == g) {
i--; j--;
diff(path + '/' + i, source.get(i), target.get(j));
}
}
}
}
}
}
Expand Down
40 changes: 6 additions & 34 deletions tests/src/test/resources/jsonpatchdiff.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"original": [ 1, 2, 3 ],
"target": [ 1, 2, 3, 4, 5 ],
"expected": [
{"op":"add","path":"/3","value":4},
{"op":"add","path":"/4","value":5}
{"op":"add","path":"/4","value":5},
{"op":"add","path":"/3","value":4}
]
},
{
Expand All @@ -25,8 +25,8 @@
"target": [1,7,3,4,8,5],
"expected": [
{ "op": "remove", "path": "/5"},
{ "op": "replace", "path": "/1", "value": 7},
{ "op": "add", "path": "/4", "value": 8}
{ "op": "add", "path": "/4", "value": 8},
{ "op": "replace", "path": "/1", "value": 7}
]
},
{
Expand Down Expand Up @@ -94,8 +94,8 @@
"a": [ "b", 2, 3, 4 ]
},
"expected": [
{ "op": "replace", "path": "/a/0", "value":"b" },
{ "op": "add", "path": "/a/3", "value":4 }
{ "op": "add", "path": "/a/3", "value": 4 },
{ "op": "replace", "path": "/a/0", "value": "b" }
]
},
{
Expand Down Expand Up @@ -128,33 +128,5 @@
"expected": [
{ "op": "add", "path": "/d", "value": "c" }
]
},
{
"original": [-1, 0, 1, 3, 4],
"target": [5, 0],
"expected": [
{ "path" : "/4", "op" : "remove"},
{ "path" : "/3", "op" : "remove"},
{ "path" : "/2", "op" : "remove"},
{ "value" : 5, "path" : "/0", "op" : "replace" }
]
},
{
"original": [0],
"target": [0, 1, 2, 3, 4],
"expected": [
{ "path" : "/1", "value" : 1, "op" : "add" },
{ "path" : "/2", "value" : 2, "op" : "add" },
{ "value" : 3, "path" : "/3", "op" : "add" },
{ "op" : "add", "path" : "/4", "value" : 4 }
]
},
{
"original": [0, 2, 4],
"target": [0, 1, 2, 3, 4],
"expected": [
{ "path" : "/1", "value" : 1, "op" : "add" },
{ "value" : 3, "op" : "add", "path" : "/3" }
]
}
]

0 comments on commit 1b7c786

Please sign in to comment.