@@ -382,37 +382,32 @@ public JsonNode findValue(String propertyName)
382382 @ Override
383383 public List <JsonNode > findValues (String propertyName , List <JsonNode > foundSoFar )
384384 {
385- JsonNode jsonNode = _children .get (propertyName );
386- if (jsonNode != null ) {
387- if (foundSoFar == null ) {
388- foundSoFar = new ArrayList <>();
385+ for (Map .Entry <String , JsonNode > entry : _children .entrySet ()) {
386+ if (propertyName .equals (entry .getKey ())) {
387+ if (foundSoFar == null ) {
388+ foundSoFar = new ArrayList <JsonNode >();
389+ }
390+ foundSoFar .add (entry .getValue ());
391+ } else { // only add children if parent not added
392+ foundSoFar = entry .getValue ().findValues (propertyName , foundSoFar );
389393 }
390- foundSoFar .add (jsonNode );
391- return foundSoFar ;
392- }
393-
394- // only add children if parent not added
395- for (JsonNode child : _children .values ()) {
396- foundSoFar = child .findValues (propertyName , foundSoFar );
397394 }
398395 return foundSoFar ;
399396 }
400397
401398 @ Override
402399 public List <String > findValuesAsText (String propertyName , List <String > foundSoFar )
403400 {
404- JsonNode jsonNode = _children .get (propertyName );
405- if (jsonNode != null ) {
406- if (foundSoFar == null ) {
407- foundSoFar = new ArrayList <>();
401+ for (Map .Entry <String , JsonNode > entry : _children .entrySet ()) {
402+ if (propertyName .equals (entry .getKey ())) {
403+ if (foundSoFar == null ) {
404+ foundSoFar = new ArrayList <String >();
405+ }
406+ foundSoFar .add (entry .getValue ().asText ());
407+ } else { // only add children if parent not added
408+ foundSoFar = entry .getValue ().findValuesAsText (propertyName ,
409+ foundSoFar );
408410 }
409- foundSoFar .add (jsonNode .asText ());
410- return foundSoFar ;
411- }
412-
413- // only add children if parent not added
414- for (JsonNode child : _children .values ()) {
415- foundSoFar = child .findValuesAsText (propertyName , foundSoFar );
416411 }
417412 return foundSoFar ;
418413 }
@@ -436,18 +431,16 @@ public ObjectNode findParent(String propertyName)
436431 @ Override
437432 public List <JsonNode > findParents (String propertyName , List <JsonNode > foundSoFar )
438433 {
439- JsonNode jsonNode = _children .get (propertyName );
440- if (jsonNode != null ) {
441- if (foundSoFar == null ) {
442- foundSoFar = new ArrayList <>();
434+ for (Map .Entry <String , JsonNode > entry : _children .entrySet ()) {
435+ if (propertyName .equals (entry .getKey ())) {
436+ if (foundSoFar == null ) {
437+ foundSoFar = new ArrayList <JsonNode >();
438+ }
439+ foundSoFar .add (this );
440+ } else { // only add children if parent not added
441+ foundSoFar = entry .getValue ()
442+ .findParents (propertyName , foundSoFar );
443443 }
444- foundSoFar .add (this );
445- return foundSoFar ;
446- }
447-
448- // only add children if parent not added
449- for (JsonNode child : _children .values ()) {
450- foundSoFar = child .findParents (propertyName , foundSoFar );
451444 }
452445 return foundSoFar ;
453446 }
0 commit comments