reschke commented on code in PR #2182: URL: https://github.com/apache/jackrabbit-oak/pull/2182#discussion_r2000701644
########## oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/impl/OrderedChildnameIterable.java: ########## @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.jackrabbit.oak.plugins.tree.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +/** + * Return the childrenNames in the order defined by the orderedChildren iterator, and merges it Review Comment: ```suggestion * Return the childrenNames in the order defined by the orderedChildren iterator, and merge it ``` ########## oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/impl/OrderedChildnameIterable.java: ########## @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.jackrabbit.oak.plugins.tree.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +/** + * Return the childrenNames in the order defined by the orderedChildren iterator, and merges it + * with the existing children defined by allChildren. + * Review Comment: ```suggestion * <p> ``` ########## oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/impl/OrderedChildnameIterable.java: ########## @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.jackrabbit.oak.plugins.tree.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +/** + * Return the childrenNames in the order defined by the orderedChildren iterator, and merges it + * with the existing children defined by allChildren. + * + * This implementation focuses on being as lazy as possible; especially consuming the + * allChildren iterator can be slow. + */ + +public class OrderedChildnameIterable implements Iterable<String> { + + final OrderedChildnameIterator iter; + + /** + * Create an iterator, which returns all children in the correct order + * @param orderedChildren the children defined by the :childrenOrder property + * @param allChildren all children + */ + public OrderedChildnameIterable (Iterable<String> orderedChildren, Iterable<String> allChildren) { + iter = new OrderedChildnameIterator(orderedChildren,allChildren); Review Comment: ```suggestion iter = new OrderedChildnameIterator(orderedChildren, allChildren); ``` ########## oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/impl/OrderedChildnameIterable.java: ########## @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.jackrabbit.oak.plugins.tree.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +/** + * Return the childrenNames in the order defined by the orderedChildren iterator, and merges it + * with the existing children defined by allChildren. + * + * This implementation focuses on being as lazy as possible; especially consuming the + * allChildren iterator can be slow. + */ + +public class OrderedChildnameIterable implements Iterable<String> { + + final OrderedChildnameIterator iter; + + /** + * Create an iterator, which returns all children in the correct order + * @param orderedChildren the children defined by the :childrenOrder property + * @param allChildren all children + */ + public OrderedChildnameIterable (Iterable<String> orderedChildren, Iterable<String> allChildren) { + iter = new OrderedChildnameIterator(orderedChildren,allChildren); + } + + @Override + public Iterator<String> iterator() { + return iter; + } + + public class OrderedChildnameIterator implements Iterator<String> { + + final Iterator<String> orderedChildren; + final Iterator<String> allChildren; + + private String nextResult; + + private final List<String> nonOrderedChildren = new ArrayList<>(); + private Iterator<String> nonOrderedChildrenIterator = null; + + public OrderedChildnameIterator (Iterable<String> orderedChildren, Iterable<String> allChildren) { Review Comment: ```suggestion public OrderedChildnameIterator(Iterable<String> orderedChildren, Iterable<String> allChildren) { ``` ########## oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/impl/AbstractTree.java: ########## @@ -125,17 +120,7 @@ protected Iterable<String> getChildNames() { NodeBuilder nodeBuilder = getNodeBuilder(); PropertyState order = nodeBuilder.getProperty(OAK_CHILD_ORDER); if (order != null && order.getType() == NAMES) { - Set<String> names = SetUtils.toLinkedSet(nodeBuilder.getChildNodeNames()); - List<String> ordered = new ArrayList<>(names.size()); - for (String name : order.getValue(NAMES)) { - // only include names of child nodes that actually exist - if (names.remove(name)) { - ordered.add(name); - } - } - // add names of child nodes that are not explicitly ordered - ordered.addAll(names); - return ordered; + return new OrderedChildnameIterable(order.getValue(NAMES), nodeBuilder.getChildNodeNames()); Review Comment: You can use `IteratorUtils.toIterable()` and avoid the wrapper class. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
