@@ -65,11 +65,9 @@ public OrderedChildnameIterator (Iterable<String> orderedChildren, Iterable<Stri
6565 nextResult = getNextElement ();
6666 }
6767
68- String getNextElement () {
69- String elem = null ;
70-
68+ private String getNextElement () {
7169 if (orderedChildren .hasNext ()) {
72- elem = getNextOrderedChild ();
70+ String elem = getNextOrderedChild ();
7371 if (elem != null ) {
7472 return elem ;
7573 }
@@ -83,7 +81,7 @@ String getNextElement() {
8381 if (nonOrderedChildrenIterator .hasNext ()) {
8482 return nonOrderedChildrenIterator .next ();
8583 }
86- // return all children which have not been consumed from the allChildren iterator yet
84+ // return all children which have not been consumed from the allChildren iterator
8785 if (allChildren .hasNext ()) {
8886 return allChildren .next ();
8987 }
@@ -92,8 +90,8 @@ String getNextElement() {
9290 }
9391
9492 /**
95- * Consume the next element from the orderedChild list
96- * @return null if no ordered child can be retrieved, otherwise the next ordered child name
93+ * Consume the next element from the orderedChild list and validates that it's actually present
94+ * @return the next ordered child or {code null} if all ordered children have already been returned
9795 */
9896 String getNextOrderedChild () {
9997 String current = null ;
@@ -102,6 +100,8 @@ String getNextOrderedChild() {
102100 current = orderedChildren .next ();
103101 if (isOrderedChildPresent (current )) {
104102 return current ;
103+ } else {
104+ current = null ; // skip this element, as it's not present in the allChildren iterator
105105 }
106106 }
107107 return null ;
0 commit comments