Skip to content

Commit fe0f21a

Browse files
committed
DiffOperation: arguments rename, add comments
1 parent 01ea638 commit fe0f21a

File tree

2 files changed

+43
-39
lines changed

2 files changed

+43
-39
lines changed

src/main/java/com/github/fge/jsonpatch/diff2/DiffOperation.java

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,79 +31,83 @@
3131
final class DiffOperation
3232
{
3333
private final Type type;
34-
private final JsonPointer oldPointer;
34+
/* An op's "from", if any */
35+
private final JsonPointer from;
36+
/* Value displaced by this operation, if any */
3537
private final JsonNode oldValue;
36-
private final JsonPointer newPointer;
37-
private final JsonNode newValue;
38+
/* An op's "path", if any */
39+
private final JsonPointer path;
40+
/* An op's "value", if any */
41+
private final JsonNode value;
3842

39-
static DiffOperation add(final JsonPointer newPointer,
40-
final JsonNode newValue)
43+
static DiffOperation add(final JsonPointer path,
44+
final JsonNode value)
4145
{
42-
return new DiffOperation(Type.ADD, null, null, newPointer, newValue);
46+
return new DiffOperation(Type.ADD, null, null, path, value);
4347
}
4448

45-
static DiffOperation copy(final JsonPointer oldPointer,
46-
final JsonPointer newPointer, final JsonNode newValue)
49+
static DiffOperation copy(final JsonPointer from,
50+
final JsonPointer path, final JsonNode value)
4751
{
48-
return new DiffOperation(Type.COPY, oldPointer, null, newPointer,
49-
newValue);
52+
return new DiffOperation(Type.COPY, from, null, path,
53+
value);
5054
}
5155

52-
static DiffOperation move(final JsonPointer oldPointer,
53-
final JsonNode oldValue, final JsonPointer newPointer,
54-
final JsonNode newValue)
56+
static DiffOperation move(final JsonPointer from,
57+
final JsonNode oldValue, final JsonPointer path,
58+
final JsonNode value)
5559
{
56-
return new DiffOperation(Type.MOVE, oldPointer, oldValue, newPointer,
57-
newValue);
60+
return new DiffOperation(Type.MOVE, from, oldValue, path,
61+
value);
5862
}
5963

60-
static DiffOperation remove(final JsonPointer oldPointer,
64+
static DiffOperation remove(final JsonPointer from,
6165
final JsonNode oldValue)
6266
{
63-
return new DiffOperation(Type.REMOVE, oldPointer, oldValue, null, null);
67+
return new DiffOperation(Type.REMOVE, from, oldValue, null, null);
6468
}
6569

66-
static DiffOperation replace(final JsonPointer oldPointer,
67-
final JsonNode oldValue, final JsonNode newValue)
70+
static DiffOperation replace(final JsonPointer from,
71+
final JsonNode oldValue, final JsonNode value)
6872
{
69-
return new DiffOperation(Type.REPLACE, oldPointer, oldValue, null,
70-
newValue);
73+
return new DiffOperation(Type.REPLACE, from, oldValue, null,
74+
value);
7175
}
7276

73-
private DiffOperation(final Type type, final JsonPointer oldPointer,
74-
final JsonNode oldValue, final JsonPointer newPointer,
75-
final JsonNode newValue)
77+
private DiffOperation(final Type type, final JsonPointer from,
78+
final JsonNode oldValue, final JsonPointer path,
79+
final JsonNode value)
7680
{
7781
this.type = type;
78-
this.oldPointer = oldPointer;
82+
this.from = from;
7983
this.oldValue = oldValue;
80-
this.newPointer = newPointer;
81-
this.newValue = newValue;
84+
this.path = path;
85+
this.value = value;
8286
}
8387

8488
Type getType()
8589
{
8690
return type;
8791
}
8892

89-
JsonPointer getOldPointer()
93+
JsonPointer getFrom()
9094
{
91-
return oldPointer;
95+
return from;
9296
}
9397

9498
JsonNode getOldValue()
9599
{
96100
return oldValue;
97101
}
98102

99-
JsonPointer getNewPointer()
103+
JsonPointer getPath()
100104
{
101-
return newPointer;
105+
return path;
102106
}
103107

104-
JsonNode getNewValue()
108+
JsonNode getValue()
105109
{
106-
return newValue;
110+
return value;
107111
}
108112

109113
JsonPatchOperation asJsonPatchOperation()
@@ -117,39 +121,39 @@ enum Type {
117121
@Override
118122
JsonPatchOperation toOperation(final DiffOperation op)
119123
{
120-
return new AddOperation(op.newPointer, op.newValue);
124+
return new AddOperation(op.path, op.value);
121125
}
122126
},
123127
COPY
124128
{
125129
@Override
126130
JsonPatchOperation toOperation(final DiffOperation op)
127131
{
128-
return new CopyOperation(op.oldPointer, op.newPointer);
132+
return new CopyOperation(op.from, op.path);
129133
}
130134
},
131135
MOVE
132136
{
133137
@Override
134138
JsonPatchOperation toOperation(final DiffOperation op)
135139
{
136-
return new MoveOperation(op.oldPointer, op.newPointer);
140+
return new MoveOperation(op.from, op.path);
137141
}
138142
},
139143
REMOVE
140144
{
141145
@Override
142146
JsonPatchOperation toOperation(final DiffOperation op)
143147
{
144-
return new RemoveOperation(op.oldPointer);
148+
return new RemoveOperation(op.from);
145149
}
146150
},
147151
REPLACE
148152
{
149153
@Override
150154
JsonPatchOperation toOperation(final DiffOperation op)
151155
{
152-
return new ReplaceOperation(op.oldPointer, op.newValue);
156+
return new ReplaceOperation(op.from, op.value);
153157
}
154158
},
155159
;

src/main/java/com/github/fge/jsonpatch/diff2/DiffProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void valueAdded(final JsonPointer pointer, final JsonNode value)
6464
if (removalIndex != -1) {
6565
final DiffOperation removed = diffs.get(removalIndex);
6666
diffs.remove(removalIndex);
67-
diffs.add(DiffOperation.move(removed.getOldPointer(),
67+
diffs.add(DiffOperation.move(removed.getFrom(),
6868
value, pointer, value));
6969
return;
7070
}

0 commit comments

Comments
 (0)