@@ -327,11 +327,13 @@ public boolean equals(Comparator<JsonNode> comparator, JsonNode o)
327
327
@ Override
328
328
public JsonNode findValue (String propertyName )
329
329
{
330
- for (Map .Entry <String , JsonNode > entry : _children .entrySet ()) {
331
- if (propertyName .equals (entry .getKey ())) {
332
- return entry .getValue ();
333
- }
334
- JsonNode value = entry .getValue ().findValue (propertyName );
330
+ JsonNode jsonNode = _children .get (propertyName );
331
+ if (jsonNode != null ) {
332
+ return jsonNode ;
333
+ }
334
+
335
+ for (JsonNode child : _children .values ()) {
336
+ JsonNode value = child .findValue (propertyName );
335
337
if (value != null ) {
336
338
return value ;
337
339
}
@@ -342,44 +344,50 @@ public JsonNode findValue(String propertyName)
342
344
@ Override
343
345
public List <JsonNode > findValues (String propertyName , List <JsonNode > foundSoFar )
344
346
{
345
- for (Map .Entry <String , JsonNode > entry : _children .entrySet ()) {
346
- if (propertyName .equals (entry .getKey ())) {
347
- if (foundSoFar == null ) {
348
- foundSoFar = new ArrayList <JsonNode >();
349
- }
350
- foundSoFar .add (entry .getValue ());
351
- } else { // only add children if parent not added
352
- foundSoFar = entry .getValue ().findValues (propertyName , foundSoFar );
347
+ JsonNode jsonNode = _children .get (propertyName );
348
+ if (jsonNode != null ) {
349
+ if (foundSoFar == null ) {
350
+ foundSoFar = new ArrayList <>();
353
351
}
352
+ foundSoFar .add (jsonNode );
353
+ return foundSoFar ;
354
+ }
355
+
356
+ // only add children if parent not added
357
+ for (JsonNode child : _children .values ()) {
358
+ foundSoFar = child .findValues (propertyName , foundSoFar );
354
359
}
355
360
return foundSoFar ;
356
361
}
357
362
358
363
@ Override
359
364
public List <String > findValuesAsText (String propertyName , List <String > foundSoFar )
360
365
{
361
- for (Map .Entry <String , JsonNode > entry : _children .entrySet ()) {
362
- if (propertyName .equals (entry .getKey ())) {
363
- if (foundSoFar == null ) {
364
- foundSoFar = new ArrayList <String >();
365
- }
366
- foundSoFar .add (entry .getValue ().asText ());
367
- } else { // only add children if parent not added
368
- foundSoFar = entry .getValue ().findValuesAsText (propertyName ,
369
- foundSoFar );
366
+ JsonNode jsonNode = _children .get (propertyName );
367
+ if (jsonNode != null ) {
368
+ if (foundSoFar == null ) {
369
+ foundSoFar = new ArrayList <>();
370
370
}
371
+ foundSoFar .add (jsonNode .asText ());
372
+ return foundSoFar ;
373
+ }
374
+
375
+ // only add children if parent not added
376
+ for (JsonNode child : _children .values ()) {
377
+ foundSoFar = child .findValuesAsText (propertyName , foundSoFar );
371
378
}
372
379
return foundSoFar ;
373
380
}
374
381
375
382
@ Override
376
383
public ObjectNode findParent (String propertyName )
377
384
{
378
- for (Map .Entry <String , JsonNode > entry : _children .entrySet ()) {
379
- if (propertyName .equals (entry .getKey ())) {
380
- return this ;
381
- }
382
- JsonNode value = entry .getValue ().findParent (propertyName );
385
+ JsonNode jsonNode = _children .get (propertyName );
386
+ if (jsonNode != null ) {
387
+ return this ;
388
+ }
389
+ for (JsonNode child : _children .values ()) {
390
+ JsonNode value = child .findParent (propertyName );
383
391
if (value != null ) {
384
392
return (ObjectNode ) value ;
385
393
}
@@ -390,16 +398,18 @@ public ObjectNode findParent(String propertyName)
390
398
@ Override
391
399
public List <JsonNode > findParents (String propertyName , List <JsonNode > foundSoFar )
392
400
{
393
- for (Map .Entry <String , JsonNode > entry : _children .entrySet ()) {
394
- if (propertyName .equals (entry .getKey ())) {
395
- if (foundSoFar == null ) {
396
- foundSoFar = new ArrayList <JsonNode >();
397
- }
398
- foundSoFar .add (this );
399
- } else { // only add children if parent not added
400
- foundSoFar = entry .getValue ()
401
- .findParents (propertyName , foundSoFar );
401
+ JsonNode jsonNode = _children .get (propertyName );
402
+ if (jsonNode != null ) {
403
+ if (foundSoFar == null ) {
404
+ foundSoFar = new ArrayList <>();
402
405
}
406
+ foundSoFar .add (this );
407
+ return foundSoFar ;
408
+ }
409
+
410
+ // only add children if parent not added
411
+ for (JsonNode child : _children .values ()) {
412
+ foundSoFar = child .findParents (propertyName , foundSoFar );
403
413
}
404
414
return foundSoFar ;
405
415
}
0 commit comments