kenhuuu commented on code in PR #3241: URL: https://github.com/apache/tinkerpop/pull/3241#discussion_r2437317856
########## gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/NL_SL_Traverser.java: ########## @@ -0,0 +1,249 @@ +/* + * 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.tinkerpop.gremlin.process.traversal.traverser; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.Stack; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.commons.collections.map.ReferenceMap; +import org.apache.tinkerpop.gremlin.process.traversal.Traverser; +import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.LabelledCounter; + +import static org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement.NESTED_LOOP; +import static org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement.SINGLE_LOOP; + +/** + * Intermediate helper interface for {@link Traverser}s that support single OR nested loops (but not both). + * Implementations are expected to override either the single or nested loop functions depending on the type of loop + * they are supporting. + * <p> + * Note: it would be nice to separate the {@link TraverserRequirement#SINGLE_LOOP} vs {@link TraverserRequirement#NESTED_LOOP} + * logic into different traverser interfaces in the future however the current {@link Traverser} class hierarchy makes + * that difficult as {@link Traverser}s that support nested loops extend from {@link Traverser}s that support single + * loops but override all single loop logic with nested loop logic. + */ +public interface NL_SL_Traverser<T> extends Traverser.Admin<T> { + /** + * @return the supported loop type - either {@link TraverserRequirement#NESTED_LOOP} or {@link TraverserRequirement#SINGLE_LOOP} + */ + TraverserRequirement getLoopRequirement(); + + // NESTED LOOPS + + /** + * Override this method to support nested loops. + * + * @return the {@link Stack} of {@link LabelledCounter} which holds the nested loops. + */ + default Stack<LabelledCounter> getNestedLoops() { + throw new UnsupportedOperationException(); + } + + /** + * Override this method to support nested loops. + * + * @return the {@link ReferenceMap} where key=loop name and value=reference to the {@link LabelledCounter}. + */ + default ReferenceMap getNestedLoopNames() { + throw new UnsupportedOperationException(); + } + + // SINGLE LOOPS + + /** + * Override this method to support single loop. + * + * @return the single loop count. + */ + default short getSingleLoopCount() { + throw new UnsupportedOperationException(); + } + + /** + * Override this method to support single loop. Sets the single loop count. + */ + default void setSingleLoopCount(short loops) { Review Comment: Nit: check for places `final` can be added in this interface -- 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]
