andreachild commented on code in PR #3157:
URL: https://github.com/apache/tinkerpop/pull/3157#discussion_r2277611025


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/GValueManager.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * 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;
+
+import org.apache.tinkerpop.gremlin.process.traversal.step.GValue;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * The {@code GValueManager} class is responsible for managing the state of 
{@link GValue} instances and their
+ * associations with `Step` objects in a traversal. This class ensures that 
`GValue` instances are properly extracted
+ * and stored in a registry, allowing for dynamic query optimizations and 
state management during traversal execution.
+ * Note that the manager can be locked, at which point it becomes immutable, 
and any attempt to modify it will result
+ * in an exception.
+ */
+public final class GValueManager implements Serializable, Cloneable {
+
+    private final Map<String, GValue<?>> gValueRegistry = new HashMap<>();
+    private final Map<String, GValue<?>> pinnedGValues = new HashMap<>();
+
+    public GValueManager() {
+        this(Collections.EMPTY_MAP, Collections.EMPTY_MAP);
+    }
+
+    private GValueManager(final Map<String, GValue<?>> gValueRegistry, final 
Map<String, GValue<?>> pinnedGValues) {
+        this.gValueRegistry.putAll(gValueRegistry);
+        this.pinnedGValues.putAll(pinnedGValues);
+    }
+
+    /**
+     * Merges the internal registries of the current {@code GValueManager} 
into another {@code GValueManager}.
+     * Transfers the state of the {@code gValueRegistry} and {@code 
stepRegistry} from the current instance to the
+     * specified target instance.
+     *
+     * @param other the target {@code GValueManager} into which the current 
instance's registries will be merged
+     */
+    public void mergeInto(final GValueManager other) {
+        //TODO needs test
+        other.register(gValueRegistry.values());
+        other.pinGValues(pinnedGValues.values());
+    }
+
+    /**
+     * Gets the set of variable names used in this traversal.
+     */
+    public Set<String> getVariableNames() {
+        return Collections.unmodifiableSet(gValueRegistry.keySet());

Review Comment:
   Nit:
   ```suggestion
           return Set.copyOf(gValueRegistry.keySet());
   ```



-- 
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: commits-unsubscr...@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to