Skip to content

Commit 4116c55

Browse files
committed
OAK-11607 minor fixes
1 parent d6b5132 commit 4116c55

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/impl/AbstractTree.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,12 @@
2424
import static org.apache.jackrabbit.oak.api.Type.NAMES;
2525
import static org.apache.jackrabbit.oak.plugins.tree.TreeConstants.OAK_CHILD_ORDER;
2626

27-
import java.util.ArrayList;
2827
import java.util.Iterator;
29-
import java.util.List;
3028
import java.util.Objects;
31-
import java.util.Set;
32-
3329
import org.apache.jackrabbit.oak.api.PropertyState;
3430
import org.apache.jackrabbit.oak.api.Tree;
3531
import org.apache.jackrabbit.oak.commons.PathUtils;
3632
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
37-
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
3833
import org.apache.jackrabbit.oak.commons.conditions.Validate;
3934
import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
4035
import org.apache.jackrabbit.oak.plugins.index.reference.NodeReferenceConstants;

oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/impl/OrderedChildnameIterable.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public class OrderedChildnameIterable implements Iterable<String> {
3737

3838
final OrderedChildnameIterator iter;
3939

40+
/**
41+
* Create an iterator, which returns all children in the correct order
42+
* @param orderedChildren the children defined by the :childrenOrder property
43+
* @param allChildren all children
44+
*/
4045
public OrderedChildnameIterable (Iterable<String> orderedChildren, Iterable<String> allChildren) {
4146
iter = new OrderedChildnameIterator(orderedChildren,allChildren);
4247
}
@@ -53,9 +58,6 @@ public class OrderedChildnameIterator implements Iterator<String> {
5358

5459
private String nextResult;
5560

56-
// lazily populated by elements from the allChildren iterable
57-
private final Set<String> allChildrenSet = new HashSet<>();
58-
5961
private final List<String> nonOrderedChildren = new ArrayList<>();
6062
private Iterator<String> nonOrderedChildrenIterator = null;
6163

@@ -93,7 +95,7 @@ private String getNextElement() {
9395
* Consume the next element from the orderedChild list and validates that it's actually present
9496
* @return the next ordered child or {code null} if all ordered children have already been returned
9597
*/
96-
String getNextOrderedChild() {
98+
private String getNextOrderedChild() {
9799
String current = null;
98100
// check that this element is actually present in the allChildren iterable
99101
while (current == null && orderedChildren.hasNext()) {
@@ -107,7 +109,12 @@ String getNextOrderedChild() {
107109
return null;
108110
}
109111

110-
boolean isOrderedChildPresent(String orderedChildName) {
112+
/**
113+
* Check if the provided childname is also provided by the allChildren iterator.
114+
* @param orderedChildName
115+
* @return true if childname is a valid child, false otherwise
116+
*/
117+
private boolean isOrderedChildPresent(String orderedChildName) {
111118
// read from the allChildren iterator until it's a hit or exhausted
112119
while (!nonOrderedChildren.contains(orderedChildName) && allChildren.hasNext()) {
113120
nonOrderedChildren.add(allChildren.next());

oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/OrderedChildnameIterableTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,18 @@ public void orderedChildren() {
9090

9191
@Test
9292
public void orderedChildrenWithNonExistingOrderedChild() {
93-
// the ordered list contains a non-existing childname, which is not part of children list
93+
// the ordered list contains non-existing childnames, which are not part of children list
9494
OrderedChildnameIterable iterable = new OrderedChildnameIterable(List.of("4","nonexisting1","5","nonexisting2"),ALL_CHILDREN);
9595
Assert.assertEquals(List.of("4","5","1","2","3"), iterableToList(iterable));
9696
}
9797

98+
@Test
99+
public void orderedChildrenWithOnlyNonExistingOrderedChild() {
100+
// the ordered list contains non-existing childnames, which are not part of children list
101+
OrderedChildnameIterable iterable = new OrderedChildnameIterable(List.of("nonexisting"),ALL_CHILDREN);
102+
Assert.assertEquals(List.of("1","2","3","4","5"), iterableToList(iterable));
103+
}
104+
98105
@Test
99106
public void onlyOrderedChildrenAvailable() {
100107
// the orderedChildren property is populated, but no children are available
@@ -109,8 +116,7 @@ public void testLazyLoading() {
109116

110117
OrderedChildnameIterable iterable = new OrderedChildnameIterable(
111118
List.of("4", "1"),
112-
trackingAllChildren
113-
);
119+
trackingAllChildren);
114120

115121
Iterator<String> iterator = iterable.iterator();
116122

0 commit comments

Comments
 (0)