@@ -64,8 +64,8 @@ private FixPath(final String[] path) {
64
64
}
65
65
66
66
/*package-private*/ Value findIn (final Array array ) {
67
-
68
67
final Value result ;
68
+
69
69
if (path .length == 0 ) {
70
70
result = new Value (array );
71
71
}
@@ -96,8 +96,8 @@ else if (isReference(currentSegment)) {
96
96
result = Value .newArray (a -> array .forEach (v -> a .add (findInValue (v , path ))));
97
97
}
98
98
}
99
- return result ;
100
99
100
+ return result ;
101
101
}
102
102
103
103
private Value findInValue (final Value value , final String [] p ) {
@@ -124,6 +124,7 @@ public String toString() {
124
124
125
125
/*package-private*/ FixPath to (final Value value , final int i ) {
126
126
final FixPath result ;
127
+
127
128
// One *, no matching path: replace with index of current result
128
129
if (countAsterisks () == 1 && !matches (value .getPath ())) {
129
130
result = new FixPath (replaceInPath (ASTERISK , i ));
@@ -135,6 +136,7 @@ else if (value.getPath() != null && hasWildcard()) {
135
136
else {
136
137
result = this ;
137
138
}
139
+
138
140
return result ;
139
141
}
140
142
@@ -154,7 +156,7 @@ private long countAsterisks() {
154
156
return Arrays .asList (path ).stream ().filter (s -> s .equals (ASTERISK )).count ();
155
157
}
156
158
157
- /* package-private */ enum InsertMode {
159
+ /*package-private*/ enum InsertMode {
158
160
159
161
REPLACE {
160
162
@ Override
@@ -246,10 +248,10 @@ private void removeNestedFrom(final Value value) {
246
248
}
247
249
}
248
250
249
- /*package-private*/ private Value insertInto (final Array array , final InsertMode mode , final Value newValue ) {
251
+ private Value insertInto (final Array array , final InsertMode mode , final Value newValue ) {
250
252
// basic idea: reuse findIn logic here? setIn(findIn(array), newValue)
251
-
252
253
final String field = path [0 ];
254
+
253
255
if (path .length == 1 ) {
254
256
mode .apply (array , field , newValue );
255
257
}
@@ -261,12 +263,14 @@ else if (isReference(field)) {
261
263
insertInto (getReferencedValue (array , field , newValue .getPath ()), mode , newValue , field , tail (path ));
262
264
}
263
265
}
266
+
264
267
return new Value (array );
265
268
}
266
269
267
270
/*package-private*/ Value insertInto (final Hash hash , final InsertMode mode , final Value newValue ) {
268
271
// basic idea: reuse findIn logic here? setIn(findIn(hash), newValue)
269
272
final String field = path [0 ];
273
+
270
274
if (path .length == 1 ) {
271
275
mode .apply (hash , field , newValue );
272
276
}
@@ -276,11 +280,11 @@ else if (isReference(field)) {
276
280
}
277
281
insertInto (hash .get (field ), mode , newValue , field , tail (path ));
278
282
}
283
+
279
284
return new Value (hash );
280
285
}
281
286
282
- private Value insertInto (final Value value , final InsertMode mode , final Value newValue , final String field ,
283
- final String [] tail ) {
287
+ private Value insertInto (final Value value , final InsertMode mode , final Value newValue , final String field , final String [] tail ) {
284
288
if (value != null ) {
285
289
final FixPath fixPath = new FixPath (tail );
286
290
newValue .withPathSet (value .getPath ());
@@ -320,10 +324,12 @@ private boolean isReference(final String field) {
320
324
// TODO replace switch, extract to method on array?
321
325
private Value getReferencedValue (final Array array , final String field , final String p ) {
322
326
Value referencedValue = null ;
327
+
323
328
if (Value .isNumber (field )) {
324
329
final int index = Integer .valueOf (field ) - 1 ;
325
330
return 0 <= index && index < array .size () ? array .get (index ) : null ;
326
331
}
332
+
327
333
final ReservedField reservedField = ReservedField .fromString (field );
328
334
if (reservedField != null ) {
329
335
switch (reservedField ) {
@@ -341,6 +347,7 @@ private Value getReferencedValue(final Array array, final String field, final St
341
347
break ;
342
348
}
343
349
}
350
+
344
351
return referencedValue ;
345
352
}
346
353
0 commit comments