You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2015/03/19 19:26:39 UTC
[21/40] incubator-tinkerpop git commit: the traversal steps provided
by TinkerPop are the foundation for all dsl. GraphTraversal is just a dsl of
traversal. Refactored the process API to reflect this concept. Fixed #592.
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_PA_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_PA_S_SE_SL_Traverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_PA_S_SE_SL_Traverser.java
deleted file mode 100644
index ee601a7..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_PA_S_SE_SL_Traverser.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.traverser;
-
-
-import org.apache.tinkerpop.gremlin.process.Path;
-import org.apache.tinkerpop.gremlin.process.Step;
-import org.apache.tinkerpop.gremlin.process.TraversalSideEffects;
-import org.apache.tinkerpop.gremlin.process.Traverser;
-import org.apache.tinkerpop.gremlin.process.traverser.util.AbstractPathTraverser;
-import org.apache.tinkerpop.gremlin.process.util.path.SparsePath;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-
-import java.util.Map;
-import java.util.Optional;
-import java.util.WeakHashMap;
-import java.util.function.UnaryOperator;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class B_O_PA_S_SE_SL_Traverser<T> extends AbstractPathTraverser<T> {
-
- protected B_O_PA_S_SE_SL_Traverser() {
- }
-
- public B_O_PA_S_SE_SL_Traverser(final T t, final Step<T, ?> step) {
- super(t, step);
- final Optional<String> stepLabel = step.getLabel();
- this.path = stepLabel.isPresent() ?
- getOrCreateFromCache(this.sideEffects).extend(t, stepLabel.get()) :
- getOrCreateFromCache(this.sideEffects).extend(t);
- }
-
- @Override
- public int hashCode() {
- return this.t.hashCode() + this.future.hashCode() + this.loops;
- }
-
- @Override
- public boolean equals(final Object object) {
- return object instanceof B_O_PA_S_SE_SL_Traverser
- && ((B_O_PA_S_SE_SL_Traverser) object).get().equals(this.t)
- && ((B_O_PA_S_SE_SL_Traverser) object).getStepId().equals(this.getStepId())
- && ((B_O_PA_S_SE_SL_Traverser) object).loops() == this.loops()
- && (null == this.sack);
- }
-
- @Override
- public Traverser.Admin<T> attach(final Vertex vertex) {
- super.attach(vertex);
- final Path newSparsePath = getOrCreateFromCache(this.sideEffects);
- this.path.forEach((object, labels) -> newSparsePath.extend(object, labels.toArray(new String[labels.size()])));
- this.path = newSparsePath;
- return this;
- }
-
- //////////////////////
-
- private static final Map<TraversalSideEffects, SparsePath> PATH_CACHE = new WeakHashMap<>();
-
- private static SparsePath getOrCreateFromCache(final TraversalSideEffects sideEffects) {
- SparsePath path = PATH_CACHE.get(sideEffects);
- if (null == path) {
- path = SparsePath.make();
- PATH_CACHE.put(sideEffects, path);
- }
- return path;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_PA_S_SE_SL_TraverserGenerator.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_PA_S_SE_SL_TraverserGenerator.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_PA_S_SE_SL_TraverserGenerator.java
deleted file mode 100644
index 4a2d8e1..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_PA_S_SE_SL_TraverserGenerator.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.traverser;
-
-import org.apache.tinkerpop.gremlin.process.Step;
-import org.apache.tinkerpop.gremlin.process.Traverser;
-import org.apache.tinkerpop.gremlin.process.TraverserGenerator;
-
-import java.util.EnumSet;
-import java.util.Set;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class B_O_PA_S_SE_SL_TraverserGenerator implements TraverserGenerator {
-
- private static final B_O_PA_S_SE_SL_TraverserGenerator INSTANCE = new B_O_PA_S_SE_SL_TraverserGenerator();
-
- private static final Set<TraverserRequirement> REQUIREMENTS = EnumSet.of(
- TraverserRequirement.OBJECT,
- TraverserRequirement.BULK,
- TraverserRequirement.SINGLE_LOOP,
- TraverserRequirement.PATH_ACCESS,
- TraverserRequirement.SACK,
- TraverserRequirement.SIDE_EFFECTS);
-
-
- private B_O_PA_S_SE_SL_TraverserGenerator() {
- }
-
- @Override
- public <S> Traverser.Admin<S> generate(final S start, final Step<S, ?> startStep, final long initialBulk) {
- final B_O_PA_S_SE_SL_Traverser<S> traverser = new B_O_PA_S_SE_SL_Traverser<>(start, startStep);
- traverser.setBulk(initialBulk);
- return traverser;
- }
-
- @Override
- public Set<TraverserRequirement> getProvidedRequirements() {
- return REQUIREMENTS;
- }
-
- public static B_O_PA_S_SE_SL_TraverserGenerator instance() {
- return INSTANCE;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_P_PA_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_P_PA_S_SE_SL_Traverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_P_PA_S_SE_SL_Traverser.java
deleted file mode 100644
index 4ea4a2f..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_P_PA_S_SE_SL_Traverser.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.traverser;
-
-import org.apache.tinkerpop.gremlin.process.Step;
-import org.apache.tinkerpop.gremlin.process.traverser.util.AbstractPathTraverser;
-import org.apache.tinkerpop.gremlin.process.util.path.ImmutablePath;
-
-import java.util.Optional;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class B_O_P_PA_S_SE_SL_Traverser<T> extends AbstractPathTraverser<T> {
-
- protected B_O_P_PA_S_SE_SL_Traverser() {
- }
-
- public B_O_P_PA_S_SE_SL_Traverser(final T t, final Step<T, ?> step) {
- super(t, step);
- final Optional<String> stepLabel = step.getLabel();
- this.path = stepLabel.isPresent() ?
- ImmutablePath.make().extend(t, stepLabel.get()) :
- ImmutablePath.make().extend(t);
- }
-
- @Override
- public int hashCode() {
- return super.hashCode() + this.path.hashCode();
- }
-
- @Override
- public boolean equals(final Object object) {
- return (object instanceof B_O_P_PA_S_SE_SL_Traverser)
- && ((B_O_P_PA_S_SE_SL_Traverser) object).path().equals(this.path) // TODO: path equality
- && ((B_O_P_PA_S_SE_SL_Traverser) object).get().equals(this.t)
- && ((B_O_P_PA_S_SE_SL_Traverser) object).getStepId().equals(this.getStepId())
- && ((B_O_P_PA_S_SE_SL_Traverser) object).loops() == this.loops()
- && (null == this.sack);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_P_PA_S_SE_SL_TraverserGenerator.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_P_PA_S_SE_SL_TraverserGenerator.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_P_PA_S_SE_SL_TraverserGenerator.java
deleted file mode 100644
index caf3ab9..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_P_PA_S_SE_SL_TraverserGenerator.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.traverser;
-
-import org.apache.tinkerpop.gremlin.process.Step;
-import org.apache.tinkerpop.gremlin.process.Traverser;
-import org.apache.tinkerpop.gremlin.process.TraverserGenerator;
-
-import java.util.EnumSet;
-import java.util.Set;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class B_O_P_PA_S_SE_SL_TraverserGenerator implements TraverserGenerator {
-
- private static final B_O_P_PA_S_SE_SL_TraverserGenerator INSTANCE = new B_O_P_PA_S_SE_SL_TraverserGenerator();
- private static final Set<TraverserRequirement> REQUIREMENTS = EnumSet.of(
- TraverserRequirement.OBJECT,
- TraverserRequirement.BULK,
- TraverserRequirement.SINGLE_LOOP,
- TraverserRequirement.PATH_ACCESS,
- TraverserRequirement.PATH,
- TraverserRequirement.SACK,
- TraverserRequirement.SIDE_EFFECTS);
-
- private B_O_P_PA_S_SE_SL_TraverserGenerator() {
- }
-
- @Override
- public <S> Traverser.Admin<S> generate(final S start, final Step<S, ?> startStep, final long initialBulk) {
- final B_O_P_PA_S_SE_SL_Traverser<S> traverser = new B_O_P_PA_S_SE_SL_Traverser<>(start, startStep);
- traverser.setBulk(initialBulk);
- return traverser;
- }
-
- @Override
- public Set<TraverserRequirement> getProvidedRequirements() {
- return REQUIREMENTS;
- }
-
- public static B_O_P_PA_S_SE_SL_TraverserGenerator instance() {
- return INSTANCE;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_Traverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_Traverser.java
deleted file mode 100644
index 4a2be92..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_Traverser.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.traverser;
-
-import org.apache.tinkerpop.gremlin.process.Traverser;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class B_O_Traverser<T> extends O_Traverser<T> {
-
- protected long bulk = 1l;
- protected String future = HALT;
-
- protected B_O_Traverser() {
- }
-
- public B_O_Traverser(final T t, final long initialBulk) {
- super(t);
- this.bulk = initialBulk;
- }
-
- @Override
- public void setBulk(final long count) {
- this.bulk = count;
- }
-
- @Override
- public long bulk() {
- return this.bulk;
- }
-
- @Override
- public void merge(final Traverser.Admin<?> other) {
- this.bulk = this.bulk + other.bulk();
- }
-
- @Override
- public String getStepId() {
- return this.future;
- }
-
- @Override
- public void setStepId(final String stepId) {
- this.future = stepId;
- }
-
- @Override
- public boolean equals(final Object object) {
- return object instanceof B_O_Traverser &&
- ((B_O_Traverser) object).t.equals(this.t) &&
- ((B_O_Traverser) object).future.equals(this.future);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_TraverserGenerator.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_TraverserGenerator.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_TraverserGenerator.java
deleted file mode 100644
index 6c6aa1f..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/B_O_TraverserGenerator.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.traverser;
-
-import org.apache.tinkerpop.gremlin.process.Step;
-import org.apache.tinkerpop.gremlin.process.Traverser;
-import org.apache.tinkerpop.gremlin.process.TraverserGenerator;
-
-import java.util.EnumSet;
-import java.util.Set;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class B_O_TraverserGenerator implements TraverserGenerator {
-
- private static final Set<TraverserRequirement> REQUIREMENTS = EnumSet.of(
- TraverserRequirement.OBJECT,
- TraverserRequirement.BULK);
-
- private static final B_O_TraverserGenerator INSTANCE = new B_O_TraverserGenerator();
-
- private B_O_TraverserGenerator() {
- }
-
- @Override
- public <S> Traverser.Admin<S> generate(final S start, final Step<S, ?> startStep, final long initialBulk) {
- return new B_O_Traverser<>(start, initialBulk);
- }
-
- @Override
- public Set<TraverserRequirement> getProvidedRequirements() {
- return REQUIREMENTS;
- }
-
- public static B_O_TraverserGenerator instance() {
- return INSTANCE;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/O_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/O_Traverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/O_Traverser.java
deleted file mode 100644
index b28d9b8..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/O_Traverser.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.traverser;
-
-import org.apache.tinkerpop.gremlin.process.traverser.util.AbstractTraverser;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class O_Traverser<T> extends AbstractTraverser<T> {
-
- protected O_Traverser() {
- }
-
- public O_Traverser(final T t) {
- super(t);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/O_TraverserGenerator.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/O_TraverserGenerator.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/O_TraverserGenerator.java
deleted file mode 100644
index e0c7dd3..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/O_TraverserGenerator.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.traverser;
-
-import org.apache.tinkerpop.gremlin.process.Step;
-import org.apache.tinkerpop.gremlin.process.Traverser;
-import org.apache.tinkerpop.gremlin.process.TraverserGenerator;
-
-import java.util.Collections;
-import java.util.Set;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class O_TraverserGenerator implements TraverserGenerator {
-
- private static final Set<TraverserRequirement> REQUIREMENTS = Collections.singleton(TraverserRequirement.OBJECT);
- private static final O_TraverserGenerator INSTANCE = new O_TraverserGenerator();
-
- private O_TraverserGenerator() {
- }
-
- @Override
- public <S> Traverser.Admin<S> generate(final S start, final Step<S, ?> startStep, final long initialBulk) {
- return new O_Traverser<>(start);
- }
-
- @Override
- public Set<TraverserRequirement> getProvidedRequirements() {
- return REQUIREMENTS;
- }
-
- public static O_TraverserGenerator instance() {
- return INSTANCE;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/TraverserGeneratorFactory.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/TraverserGeneratorFactory.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/TraverserGeneratorFactory.java
deleted file mode 100644
index ce29b87..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/TraverserGeneratorFactory.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.traverser;
-
-import org.apache.tinkerpop.gremlin.process.Traversal;
-import org.apache.tinkerpop.gremlin.process.TraverserGenerator;
-
-import java.io.Serializable;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public interface TraverserGeneratorFactory extends Serializable {
-
- public TraverserGenerator getTraverserGenerator(final Traversal.Admin<?, ?> traversal);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/TraverserRequirement.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/TraverserRequirement.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/TraverserRequirement.java
deleted file mode 100644
index e37f83d..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/TraverserRequirement.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.traverser;
-
-/**
- * A {@link TraverserRequirement} is a list of requirements that a {@link org.apache.tinkerpop.gremlin.process.Traversal} requires of a {@link org.apache.tinkerpop.gremlin.process.Traverser}.
- * The less requirements, the simpler the traverser can be (both in terms of space and time constraints).
- * Every {@link org.apache.tinkerpop.gremlin.process.Step} provides its specific requirements via {@link org.apache.tinkerpop.gremlin.process.Step#getRequirements()}.
- *
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public enum TraverserRequirement {
-
- OBJECT,
- BULK,
- SINGLE_LOOP,
- NESTED_LOOP,
- PATH,
- PATH_ACCESS,
- SACK,
- SIDE_EFFECTS,
- // NESTED_TRAVERSALS
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/AbstractPathTraverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/AbstractPathTraverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/AbstractPathTraverser.java
deleted file mode 100644
index 82608c0..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/AbstractPathTraverser.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * 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.traverser.util;
-
-import org.apache.tinkerpop.gremlin.process.Path;
-import org.apache.tinkerpop.gremlin.process.Step;
-import org.apache.tinkerpop.gremlin.process.TraversalSideEffects;
-import org.apache.tinkerpop.gremlin.process.Traverser;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedElement;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedProperty;
-
-import java.util.Optional;
-import java.util.function.UnaryOperator;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public abstract class AbstractPathTraverser<T> implements Traverser<T>, Traverser.Admin<T> {
-
- protected T t;
- protected Object sack = null;
- protected String future = HALT;
- protected short loops = 0; // an optimization hack to use a short internally to save bits :)
- protected transient TraversalSideEffects sideEffects;
- protected long bulk = 1l;
- protected Path path;
-
- protected AbstractPathTraverser() {
-
- }
-
- public AbstractPathTraverser(final T t, final Step<T, ?> step) {
- this.t = t;
- this.sideEffects = step.getTraversal().getSideEffects();
- this.sideEffects.getSackInitialValue().ifPresent(supplier -> this.sack = supplier.get());
- }
-
- /////////////////
-
- @Override
- public T get() {
- return this.t;
- }
-
- @Override
- public void set(final T t) {
- this.t = t;
- }
-
- /////////////////
-
- @Override
- public Path path() {
- return this.path;
- }
-
- /////////////////
-
- @Override
- public <S> S sack() {
- return (S) this.sack;
- }
-
- @Override
- public <S> void sack(final S object) {
- this.sack = object;
- }
-
- /////////////////
-
- @Override
- public void setBulk(final long count) {
- this.bulk = count;
- }
-
- @Override
- public long bulk() {
- return this.bulk;
- }
-
- /////////////////
-
- @Override
- public int loops() {
- return this.loops;
- }
-
- @Override
- public void incrLoops(final String stepLabel) {
- this.loops++;
- }
-
- @Override
- public void resetLoops() {
- this.loops = 0;
- }
-
- /////////////////
-
- @Override
- public String getStepId() {
- return this.future;
- }
-
- @Override
- public void setStepId(final String stepId) {
- this.future = stepId;
- }
-
- /////////////////
-
- @Override
- public TraversalSideEffects getSideEffects() {
- return this.sideEffects;
- }
-
-
- @Override
- public void setSideEffects(final TraversalSideEffects sideEffects) {
- this.sideEffects = sideEffects;
- }
-
- /////////////////
-
- @Override
- public Traverser.Admin<T> detach() {
- this.t = DetachedFactory.detach(this.t, false);
- this.path = DetachedFactory.detach(this.path, true);
- return this;
- }
-
- @Override
- public Traverser.Admin<T> attach(final Vertex vertex) {
- if (this.t instanceof DetachedElement)
- this.t = (T) ((DetachedElement) this.t).attach(vertex);
- else if (this.t instanceof DetachedProperty)
- this.t = (T) ((DetachedProperty) this.t).attach(vertex);
- // you do not want to attach a path because it will reference graph objects not at the current vertex
- return this;
- }
-
- /////////////////
-
- @Override
- public void merge(final Traverser.Admin<?> other) {
- this.bulk = this.bulk + other.bulk();
- }
-
- @Override
- public <R> Traverser.Admin<R> split(final R r, final Step<T, R> step) {
- try {
- final AbstractPathTraverser<R> clone = (AbstractPathTraverser<R>) super.clone();
- clone.t = r;
- final Optional<String> stepLabel = step.getLabel();
- clone.path = stepLabel.isPresent() ? clone.path.clone().extend(r, stepLabel.get()) : clone.path.clone().extend(r);
- clone.sack = null == clone.sack ? null : clone.sideEffects.getSackSplitOperator().orElse(UnaryOperator.identity()).apply(clone.sack);
- return clone;
- } catch (final CloneNotSupportedException e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- @Override
- public Traverser.Admin<T> split() {
- try {
- final AbstractPathTraverser<T> clone = (AbstractPathTraverser<T>) super.clone();
- clone.sack = null == clone.sack ? null : clone.sideEffects.getSackSplitOperator().orElse(UnaryOperator.identity()).apply(clone.sack);
- return clone;
- } catch (final CloneNotSupportedException e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- /////////////////
-
- @Override
- @SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
- public AbstractPathTraverser<T> clone() {
- try {
- return (AbstractPathTraverser<T>) super.clone();
- } catch (final CloneNotSupportedException e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- @Override
- public int hashCode() {
- return this.t.hashCode() + this.future.hashCode() + this.loops;
- }
-
- @Override
- public String toString() {
- return this.t.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/AbstractTraverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/AbstractTraverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/AbstractTraverser.java
deleted file mode 100644
index 34022cc..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/AbstractTraverser.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * 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.traverser.util;
-
-import org.apache.tinkerpop.gremlin.process.Path;
-import org.apache.tinkerpop.gremlin.process.Step;
-import org.apache.tinkerpop.gremlin.process.TraversalSideEffects;
-import org.apache.tinkerpop.gremlin.process.Traverser;
-import org.apache.tinkerpop.gremlin.process.traversal.util.EmptyTraversalSideEffects;
-import org.apache.tinkerpop.gremlin.process.util.path.EmptyPath;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedElement;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedProperty;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public abstract class AbstractTraverser<T> implements Traverser<T>, Traverser.Admin<T> {
-
- protected T t;
-
- protected AbstractTraverser() {
-
- }
-
- public AbstractTraverser(final T t) {
- this.t = t;
- }
-
- /////////////
-
- @Override
- public void merge(final Admin<?> other) {
- throw new UnsupportedOperationException("This traverser does not support merging: " + this.getClass().getCanonicalName());
- }
-
- @Override
- public <R> Admin<R> split(final R r, final Step<T, R> step) {
- try {
- final AbstractTraverser<R> clone = (AbstractTraverser<R>) super.clone();
- clone.t = r;
- return clone;
- } catch (final CloneNotSupportedException e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- @Override
- public Admin<T> split() {
- try {
- return (AbstractTraverser<T>) super.clone();
- } catch (final CloneNotSupportedException e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- @Override
- public void set(final T t) {
- this.t = t;
- }
-
- @Override
- public void incrLoops(final String stepLabel) {
-
- }
-
- @Override
- public void resetLoops() {
-
- }
-
- @Override
- public String getStepId() {
- throw new UnsupportedOperationException("This traverser does not support futures: " + this.getClass().getCanonicalName());
- }
-
- @Override
- public void setStepId(final String stepId) {
-
- }
-
- @Override
- public void setBulk(final long count) {
-
- }
-
- @Override
- public Admin<T> detach() {
- this.t = DetachedFactory.detach(this.t, false);
- return this;
- }
-
- @Override
- public Admin<T> attach(final Vertex hostVertex) {
- if (this.t instanceof DetachedElement)
- this.t = (T) ((DetachedElement) this.t).attach(hostVertex);
- else if (this.t instanceof DetachedProperty)
- this.t = (T) ((DetachedProperty) this.t).attach(hostVertex);
- // you do not want to attach a path because it will reference graph objects not at the current vertex
- return this;
- }
-
- @Override
- public void setSideEffects(final TraversalSideEffects sideEffects) {
-
- }
-
- @Override
- public TraversalSideEffects getSideEffects() {
- return EmptyTraversalSideEffects.instance();
- //throw new UnsupportedOperationException("This traverser does not support sideEffects: " + this.getClass().getCanonicalName());
- }
-
- @Override
- public T get() {
- return this.t;
- }
-
- @Override
- public <S> S sack() {
- throw new UnsupportedOperationException("This traverser does not support sacks: " + this.getClass().getCanonicalName());
- }
-
- @Override
- public <S> void sack(final S object) {
-
- }
-
- @Override
- public Path path() {
- return EmptyPath.instance();
- }
-
- @Override
- public int loops() {
- throw new UnsupportedOperationException("This traverser does not support loops: " + this.getClass().getCanonicalName());
- }
-
- @Override
- public long bulk() {
- return 1l;
- }
-
- @Override
- @SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
- public AbstractTraverser<T> clone() {
- try {
- return (AbstractTraverser<T>) super.clone();
- } catch (final CloneNotSupportedException e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- ///////////
-
- @Override
- public int hashCode() {
- return this.t.hashCode();
- }
-
- @Override
- public boolean equals(final Object object) {
- return object instanceof AbstractTraverser && ((AbstractTraverser) object).get().equals(this.t);
- }
-
- @Override
- public String toString() {
- return this.t.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/DefaultTraverserGeneratorFactory.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/DefaultTraverserGeneratorFactory.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/DefaultTraverserGeneratorFactory.java
deleted file mode 100644
index 341fcd5..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/DefaultTraverserGeneratorFactory.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.traverser.util;
-
-import org.apache.tinkerpop.gremlin.process.Traversal;
-import org.apache.tinkerpop.gremlin.process.TraverserGenerator;
-import org.apache.tinkerpop.gremlin.process.traverser.B_O_PA_S_SE_SL_TraverserGenerator;
-import org.apache.tinkerpop.gremlin.process.traverser.B_O_P_PA_S_SE_SL_TraverserGenerator;
-import org.apache.tinkerpop.gremlin.process.traverser.B_O_TraverserGenerator;
-import org.apache.tinkerpop.gremlin.process.traverser.O_TraverserGenerator;
-import org.apache.tinkerpop.gremlin.process.traverser.TraverserGeneratorFactory;
-import org.apache.tinkerpop.gremlin.process.traverser.TraverserRequirement;
-
-import java.util.Set;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class DefaultTraverserGeneratorFactory implements TraverserGeneratorFactory {
-
- private static DefaultTraverserGeneratorFactory INSTANCE = new DefaultTraverserGeneratorFactory();
-
- public static DefaultTraverserGeneratorFactory instance() {
- return INSTANCE;
- }
-
- private DefaultTraverserGeneratorFactory() {
- }
-
- @Override
- public TraverserGenerator getTraverserGenerator(final Traversal.Admin<?,?> traversal) {
- final Set<TraverserRequirement> requirements = traversal.getTraverserRequirements();
-
- if (O_TraverserGenerator.instance().getProvidedRequirements().containsAll(requirements))
- return O_TraverserGenerator.instance();
-
- if (B_O_TraverserGenerator.instance().getProvidedRequirements().containsAll(requirements))
- return B_O_TraverserGenerator.instance();
-
- if (B_O_PA_S_SE_SL_TraverserGenerator.instance().getProvidedRequirements().containsAll(requirements))
- return B_O_PA_S_SE_SL_TraverserGenerator.instance();
-
- if (B_O_P_PA_S_SE_SL_TraverserGenerator.instance().getProvidedRequirements().containsAll(requirements))
- return B_O_P_PA_S_SE_SL_TraverserGenerator.instance();
-
- throw new IllegalStateException("The provided traverser generator factory does not support the requirements of the traversal: " + this.getClass().getCanonicalName() + requirements);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/EmptyTraverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/EmptyTraverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/EmptyTraverser.java
deleted file mode 100644
index 2d15ac4..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traverser/util/EmptyTraverser.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * 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.traverser.util;
-
-import org.apache.tinkerpop.gremlin.process.Path;
-import org.apache.tinkerpop.gremlin.process.Step;
-import org.apache.tinkerpop.gremlin.process.TraversalSideEffects;
-import org.apache.tinkerpop.gremlin.process.Traverser;
-import org.apache.tinkerpop.gremlin.process.util.path.EmptyPath;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class EmptyTraverser<T> implements Traverser<T>, Traverser.Admin<T> {
-
- private static final EmptyTraverser INSTANCE = new EmptyTraverser();
-
- public static <R> EmptyTraverser<R> instance() {
- return INSTANCE;
- }
-
- private EmptyTraverser() {
-
- }
-
- @Override
- public void set(final T t) {
-
- }
-
- @Override
- public void incrLoops(final String stepLabel) {
-
- }
-
- @Override
- public void resetLoops() {
-
- }
-
- @Override
- public String getStepId() {
- return HALT;
- }
-
- @Override
- public void setStepId(final String stepId) {
-
- }
-
- @Override
- public void setBulk(long count) {
-
- }
-
- @Override
- public <R> Admin<R> split(final R r, final Step<T, R> step) {
- return INSTANCE;
- }
-
- @Override
- public Admin<T> split() {
- return this;
- }
-
- @Override
- public Admin<T> detach() {
- return this;
- }
-
- @Override
- public Admin<T> attach(final Vertex hostVertex) {
- return this;
- }
-
- @Override
- public void setSideEffects(final TraversalSideEffects sideEffects) {
-
- }
-
- @Override
- public T get() {
- return null;
- }
-
- @Override
- public <S> S sack() {
- return null;
- }
-
- @Override
- public <S> void sack(final S object) {
-
- }
-
- @Override
- public void merge(final Traverser.Admin<?> other) {
-
- }
-
- @Override
- public Path path() {
- return EmptyPath.instance();
- }
-
- @Override
- public int loops() {
- return 0;
- }
-
- @Override
- public long bulk() {
- return 0l;
- }
-
- @Override
- public TraversalSideEffects getSideEffects() {
- return null;
- }
-
- @Override
- public int hashCode() {
- return 380473707;
- }
-
- @Override
- public boolean equals(final Object object) {
- return object instanceof EmptyTraverser;
- }
-
- @Override
- @SuppressWarnings("CloneDoesntCallSuperClone")
- public EmptyTraverser<T> clone() {
- return this;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/BulkSet.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/BulkSet.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/BulkSet.java
deleted file mode 100644
index 70be9cc..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/BulkSet.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * 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.util;
-
-import java.io.Serializable;
-import java.util.AbstractSet;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.Spliterator;
-import java.util.function.BiConsumer;
-import java.util.stream.Collectors;
-
-/**
- * BulkSet is a weighted set (i.e. a multi-set). Objects are added along with a bulk counter the denotes how many times the object was added to the set.
- * Given that count-based compression (vs. enumeration) can yield large sets, methods exist that are long-based (2^64).
- *
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class BulkSet<S> extends AbstractSet<S> implements Set<S>, Serializable {
- private final Map<S, Long> map = new LinkedHashMap<>();
-
- @Override
- public int size() {
- return (int) this.longSize();
- }
-
- public int uniqueSize() {
- return this.map.size();
- }
-
- public long longSize() {
- return this.map.values().stream().collect(Collectors.summingLong(Long::longValue));
- }
-
- @Override
- public boolean isEmpty() {
- return this.map.isEmpty();
- }
-
- @Override
- public boolean contains(final Object s) {
- return this.map.containsKey(s);
- }
-
- @Override
- public boolean add(final S s) {
- return this.add(s, 1l);
- }
-
- @Override
- public boolean addAll(final Collection<? extends S> collection) {
- if (collection instanceof BulkSet) {
- ((BulkSet<S>) collection).map.forEach(this::add);
- } else {
- collection.iterator().forEachRemaining(this::add);
- }
- return true;
- }
-
- public void forEach(final BiConsumer<S, Long> consumer) {
- this.map.forEach(consumer);
- }
-
- public boolean add(final S s, final long bulk) {
- final Long current = this.map.get(s);
- if (current != null) {
- this.map.put(s, current + bulk);
- return false;
- } else {
- this.map.put(s, bulk);
- return true;
- }
- }
-
- public long get(final S s) {
- final Long bulk = this.map.get(s);
- return null == bulk ? 0 : bulk;
- }
-
- /*public void set(final S s, final long bulk) {
- this.map.remove(s);
- this.map.put(s, bulk);
- }*/
-
- @Override
- public boolean remove(final Object s) {
- return this.map.remove(s) != null;
- }
-
- @Override
- public void clear() {
- this.map.clear();
- }
-
- @Override
- public Spliterator<S> spliterator() {
- return this.toList().spliterator();
- }
-
- @Override
- public boolean removeAll(final Collection<?> collection) {
- Objects.requireNonNull(collection);
- boolean modified = false;
- for (final Object object : collection) {
- if (null != this.map.remove(object))
- modified = true;
- }
- return modified;
- }
-
- @Override
- public int hashCode() {
- return this.map.hashCode();
- }
-
- @Override
- public boolean equals(final Object object) {
- return this.map.equals(object);
- }
-
- @Override
- public String toString() {
- return this.map.toString();
- }
-
- private List<S> toList() {
- final List<S> list = new ArrayList<>();
- this.map.forEach((k, v) -> {
- for (long i = 0; i < v; i++) {
- list.add(k);
- }
- });
- return list;
- }
-
- @Override
- public Iterator<S> iterator() {
- return new Iterator<S>() {
- final Iterator<Map.Entry<S, Long>> entryIterator = map.entrySet().iterator();
- S lastObject = null;
- long lastCount = 0l;
-
- public boolean hasNext() {
- return this.lastCount > 0l || this.entryIterator.hasNext();
- }
-
- @Override
- public S next() {
- if (this.lastCount > 0l) {
- this.lastCount--;
- return this.lastObject;
- }
- final Map.Entry<S, Long> entry = entryIterator.next();
- if (entry.getValue() == 1) {
- return entry.getKey();
- } else {
- this.lastObject = entry.getKey();
- this.lastCount = entry.getValue() - 1;
- return this.lastObject;
- }
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/MapHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/MapHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/MapHelper.java
deleted file mode 100644
index 98d3c53..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/MapHelper.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.util;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class MapHelper {
-
- private MapHelper() {
- }
-
- public static <T> void incr(final Map<T, Long> map, final T key, final Long value) {
- map.put(key, value + map.getOrDefault(key, 0l));
- }
-
- public static <T> void incr(final Map<T, Double> map, final T key, final Double value) {
- map.put(key, value + map.getOrDefault(key, 0.0d));
- }
-
- public static <T, U> void incr(final Map<T, List<U>> map, final T key, final U value) {
- map.compute(key, (k, v) -> {
- if (null == v) v = new ArrayList<>();
- v.add(value);
- return v;
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/TraverserSet.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/TraverserSet.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/TraverserSet.java
deleted file mode 100644
index 37fb957..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/TraverserSet.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * 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.util;
-
-import org.apache.tinkerpop.gremlin.process.Traverser;
-
-import java.io.Serializable;
-import java.util.AbstractSet;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
-import java.util.Set;
-import java.util.Spliterator;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class TraverserSet<S> extends AbstractSet<Traverser.Admin<S>> implements Set<Traverser.Admin<S>>, Queue<Traverser.Admin<S>>, Serializable {
-
- private final Map<Traverser.Admin<S>, Traverser.Admin<S>> map = new LinkedHashMap<>();
-
- public TraverserSet() {
-
- }
-
- public TraverserSet(final Traverser.Admin<S> traverser) {
- this.map.put(traverser, traverser);
- }
-
- @Override
- public Iterator<Traverser.Admin<S>> iterator() {
- return this.map.values().iterator();
- }
-
- public Traverser.Admin<S> get(final Traverser.Admin<S> traverser) {
- return this.map.get(traverser);
- }
-
- @Override
- public int size() {
- return this.map.size();
- }
-
- public long bulkSize() {
- return this.map.values().stream().map(Traverser::bulk).reduce(0l, (a, b) -> a + b);
- }
-
- @Override
- public boolean isEmpty() {
- return this.map.isEmpty();
- }
-
- @Override
- public boolean contains(final Object traverser) {
- return this.map.containsKey(traverser);
- }
-
- @Override
- public boolean add(final Traverser.Admin<S> traverser) {
- final Traverser.Admin<S> existing = this.map.get(traverser);
- if (null == existing) {
- this.map.put(traverser, traverser);
- return true;
- } else {
- existing.merge(traverser);
- return false;
- }
- }
-
- @Override
- public boolean offer(final Traverser.Admin<S> traverser) {
- return this.add(traverser);
- }
-
- @Override
- public Traverser.Admin<S> remove() { // pop, exception if empty
- return this.map.remove(this.map.values().iterator().next());
- }
-
- @Override
- public Traverser.Admin<S> poll() { // pop, null if empty
- return this.map.isEmpty() ? null : this.remove();
- }
-
- @Override
- public Traverser.Admin<S> element() { // peek, exception if empty
- return this.iterator().next();
- }
-
- @Override
- public Traverser.Admin<S> peek() { // peek, null if empty
- return this.map.isEmpty() ? null : this.iterator().next();
- }
-
- @Override
- public boolean remove(final Object traverser) {
- return this.map.remove(traverser) != null;
- }
-
- @Override
- public void clear() {
- this.map.clear();
- }
-
- @Override
- public Spliterator<Traverser.Admin<S>> spliterator() {
- return this.map.values().spliterator();
- }
-
- @Override
- public String toString() {
- return this.map.keySet().toString();
- }
-
- public void sort(final Comparator<Traverser<S>> comparator) {
- final List<Traverser.Admin<S>> list = new ArrayList<>(this.map.values());
- Collections.sort(list, comparator);
- this.map.clear();
- list.forEach(traverser -> this.map.put(traverser, traverser));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/DependantMutableMetrics.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/DependantMutableMetrics.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/DependantMutableMetrics.java
deleted file mode 100644
index 7bb5c4d..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/DependantMutableMetrics.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.util.metric;
-
-/**
- * This Metrics class handles a metrics chain in which durations are "double counted" by upstream metrics. Durations are
- * corrected on-the-fly by subtracting upstream durations on every call to stop().
- *
- * @author Bob Briody (http://bobbriody.com)
- */
-public class DependantMutableMetrics extends MutableMetrics {
- private long prevDur = 0L;
- private DependantMutableMetrics upStreamMetrics;
-
- private DependantMutableMetrics() {
- // necessary for gryo serialization
- super();
- }
-
- public DependantMutableMetrics(final String id, final String name, final DependantMutableMetrics upStreamMetrics) {
- super(id, name);
- this.upStreamMetrics = upStreamMetrics;
- }
-
- public void start() {
- super.start();
- }
-
- public void stop() {
- super.stop();
- // root step will not have an upstream metrics
- if (upStreamMetrics != null) {
- // subtract time that is "double counted" by upstream metrics
- super.durationNs -= upStreamMetrics.getAndResetIncrementalDur();
- }
- }
-
- public long getAndResetIncrementalDur() {
- long incrementalDur = super.durationNs - prevDur;
- prevDur = super.durationNs;
- return incrementalDur;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/ImmutableMetrics.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/ImmutableMetrics.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/ImmutableMetrics.java
deleted file mode 100644
index 0bd0c0a..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/ImmutableMetrics.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * 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.util.metric;
-
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * @author Bob Briody (http://bobbriody.com)
- */
-public class ImmutableMetrics implements Metrics, Serializable {
-
- static final TimeUnit SOURCE_UNIT = TimeUnit.NANOSECONDS;
-
- protected String id;
- protected String name;
- protected Map<String, AtomicLong> counts = new HashMap<>();
- protected long durationNs = 0l;
- protected final Map<String, Object> annotations = new HashMap<>();
- protected final Map<String, ImmutableMetrics> nested = new LinkedHashMap<>();
-
- protected ImmutableMetrics() {
- }
-
- @Override
- public long getDuration(TimeUnit unit) {
- return unit.convert(this.durationNs, SOURCE_UNIT);
- }
-
- @Override
- public long getCount(String key) {
- return counts.get(key).get();
- }
-
- @Override
- public Map<String, Long> getCounts() {
- Map<String, Long> ret = new HashMap<>();
- for (Map.Entry<String, AtomicLong> count : counts.entrySet()) {
- ret.put(count.getKey(), count.getValue().get());
- }
- return ret;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- public String getId() {
- return id;
- }
-
- @Override
- public Collection<ImmutableMetrics> getNested() {
- return nested.values();
- }
-
- @Override
- public ImmutableMetrics getNested(String metricsId) {
- return nested.get(metricsId);
- }
-
- @Override
- public Map<String, Object> getAnnotations() {
- return annotations;
- }
-
- @Override
- public Object getAnnotation(final String key) {
- return annotations.get(key);
- }
-
- @Override
- public String toString() {
- return "ImmutableMetrics{" +
- "id='" + id + '\'' +
- ", name='" + name + '\'' +
- ", counts=" + counts +
- ", durationNs=" + durationNs +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/Metrics.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/Metrics.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/Metrics.java
deleted file mode 100644
index f6b5002..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/Metrics.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.util.metric;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Holds metrics data; typically for .profile()-step analysis. Metrics may be nested. Nesting enables the ability to
- * capture explicit metrics for multiple distinct operations. Annotations are used to store miscellaneous notes that
- * might be useful to a developer when examining results, such as index coverage for Steps in a Traversal.
- *
- * @author Bob Briody (http://bobbriody.com)
- */
-public interface Metrics {
-
-
-
-
- /**
- * Get the duration of execution time taken.
- *
- * @param units
- * @return
- */
- public long getDuration(TimeUnit units);
-
- /**
- * Get the count for the corresponding countKey.
- *
- * @param countKey key for counter to get.
- * @return
- */
- public long getCount(String countKey);
-
- /**
- * Get the map of all counters. This method copies the internal map.
- *
- * @return a Map where the key is the counter ID and the value is the counter value.
- */
- public Map<String, Long> getCounts();
-
- /**
- * Name of this Metrics.
- *
- * @return name of this Metrics.
- */
- public String getName();
-
- /**
- * Id of this Metrics.
- *
- * @return id of this Metrics.
- */
- public String getId();
-
-
- /**
- * Get the nested Metrics objects. Metrics will be ordered in the order they were inserted.
- *
- * @return the nested Metrics objects.
- */
- public Collection<? extends Metrics> getNested();
-
- /**
- * Get a nested Metrics object by Id.
- *
- * @param metricsId
- * @return a nested Metrics object.
- */
- Metrics getNested(String metricsId);
-
- /**
- * Obtain the annotations for this Metrics. Values may be of type String or Number.
- *
- * @return the annotations for this Metrics. Modifications to the returned object are persisted in the original.
- */
- public Map<String, Object> getAnnotations();
-
- /**
- * Obtain the annotation with the specified key. Values may be of type String or Number.
- *
- * @param key key of the annotation to obtain.
- * @return
- */
- public Object getAnnotation(String key);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/MutableMetrics.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/MutableMetrics.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/MutableMetrics.java
deleted file mode 100644
index d84ed40..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/MutableMetrics.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * 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.util.metric;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * @author Bob Briody (http://bobbriody.com)
- */
-public class MutableMetrics extends ImmutableMetrics implements Cloneable {
-
- // Note: if you add new members then you probably need to add them to the copy constructor;
-
- private long tempTime = -1l;
-
- protected MutableMetrics() {
- // necessary for gryo serialization
- }
-
- public MutableMetrics(final String id, final String name) {
- this.id = id;
- this.name = name;
- }
-
-
- public void addNested(MutableMetrics metrics) {
- this.nested.put(metrics.getId(), metrics);
- }
-
- public void start() {
- if (-1 != this.tempTime) {
- throw new IllegalStateException("Internal Error: Concurrent Metrics start. Stop timer before starting timer.");
- }
- this.tempTime = System.nanoTime();
- }
-
- public void stop() {
- if (-1 == this.tempTime)
- throw new IllegalStateException("Internal Error: Metrics has not been started. Start timer before stopping timer");
- this.durationNs = this.durationNs + (System.nanoTime() - this.tempTime);
- this.tempTime = -1;
- }
-
- public void incrementCount(String key, final long incr) {
- AtomicLong count = this.counts.get(key);
- if (count == null) {
- count = new AtomicLong();
- this.counts.put(key, count);
- }
- count.addAndGet(incr);
- }
-
- public void aggregate(MutableMetrics other) {
- this.durationNs += other.durationNs;
- for (Map.Entry<String, AtomicLong> otherCount : other.counts.entrySet()) {
- AtomicLong thisCount = this.counts.get(otherCount.getKey());
- if (thisCount == null) {
- thisCount = new AtomicLong(otherCount.getValue().get());
- this.counts.put(otherCount.getKey(), thisCount);
- } else {
- thisCount.addAndGet(otherCount.getValue().get());
- }
- }
-
- // Merge annotations. If multiple values for a given key are found then append it to a comma-separated list.
- for (Map.Entry<String, Object> p : other.annotations.entrySet()) {
- if (this.annotations.containsKey(p.getKey())) {
- // Strings are concatenated
- Object existingVal = this.annotations.get(p.getKey());
- if (existingVal instanceof String) {
- final List<String> existingValues = Arrays.asList(existingVal.toString().split(","));
- if (!existingValues.contains(p.getValue())) {
- // New value. Append to comma-separated list.
- this.annotations.put(p.getKey(), existingVal.toString() + ',' + p.getValue());
- }
- } else {
- // Numbers are summed
- Number existingNum = (Number) existingVal;
- Number otherNum = (Number) p.getValue();
- Number newVal;
- if (existingNum instanceof Double || existingNum instanceof Float) {
- newVal =
- existingNum.doubleValue() + otherNum.doubleValue();
- } else {
- newVal = existingNum.longValue() + otherNum.longValue();
- }
- this.annotations.put(p.getKey(), newVal);
- }
- } else {
- this.annotations.put(p.getKey(), p.getValue());
- }
- }
- this.annotations.putAll(other.annotations);
-
- // Merge nested Metrics
- other.nested.values().forEach(nested -> {
- MutableMetrics thisNested = (MutableMetrics) this.nested.get(nested.getId());
- if (thisNested == null) {
- thisNested = new MutableMetrics(nested.getId(), nested.getName());
- this.nested.put(thisNested.getId(), thisNested);
- }
- thisNested.aggregate((MutableMetrics) nested);
- });
- }
-
- /**
- * Set an annotation value. Support exists for Strings and Numbers only. During a merge, Strings are concatenated
- * into a "," (comma) separated list of distinct values (duplicates are ignored), and Numbers are summed.
- *
- * @param key
- * @param value
- */
- public void setAnnotation(String key, Object value) {
- if (!(value instanceof String) && !(value instanceof Number)) {
- throw new IllegalArgumentException("Metrics annotations only support String and Number values.");
- }
- annotations.put(key, value);
- }
-
- @Override
- public MutableMetrics getNested(String metricsId) {
- return (MutableMetrics) nested.get(metricsId);
- }
-
- public ImmutableMetrics getImmutableClone() {
- final ImmutableMetrics clone = new ImmutableMetrics();
- copyMembers(clone);
- this.nested.values().forEach(nested -> clone.nested.put(nested.id, ((MutableMetrics) nested).getImmutableClone()));
- return clone;
- }
-
- private void copyMembers(final ImmutableMetrics clone) {
- clone.id = this.id;
- clone.name = this.name;
- clone.durationNs = this.durationNs;
- for (Map.Entry<String, AtomicLong> c : this.counts.entrySet()) {
- clone.counts.put(c.getKey(), new AtomicLong(c.getValue().get()));
- }
- for (Map.Entry<String, Object> a : this.annotations.entrySet()) {
- clone.annotations.put(a.getKey(), a.getValue());
- }
- }
-
- @Override
- public MutableMetrics clone() {
- final MutableMetrics clone = new MutableMetrics();
- copyMembers(clone);
- this.nested.values().forEach(nested -> clone.nested.put(nested.id, ((MutableMetrics) nested).clone()));
- return clone;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4c97e964/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/StandardTraversalMetrics.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/StandardTraversalMetrics.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/StandardTraversalMetrics.java
deleted file mode 100644
index 4431004..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/util/metric/StandardTraversalMetrics.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * 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.util.metric;
-
-import org.apache.commons.lang.StringUtils;
-
-import java.io.Serializable;
-import java.util.*;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author Bob Briody (http://bobbriody.com)
- */
-public final class StandardTraversalMetrics implements TraversalMetrics, Serializable {
- // toString() specific headers
- private static final String[] HEADERS = {"Step", "Count", "Traversers", "Time (ms)", "% Dur"};
-
- private boolean dirty = true;
- private final Map<String, MutableMetrics> metrics = new HashMap<>();
- private final Map<String, MutableMetrics> allMetrics = new HashMap<>();
- private final TreeMap<Integer, String> indexToLabelMap = new TreeMap<>();
-
- /*
- The following are computed values upon the completion of profiling in order to report the results back to the user
- */
- private long totalStepDuration;
- private Map<String, ImmutableMetrics> computedMetrics;
-
- public StandardTraversalMetrics() {
- }
-
- public void start(final String metricsId) {
- dirty = true;
- if (allMetrics.get(metricsId) == null) {
- System.out.println();
- }
- allMetrics.get(metricsId).start();
- }
-
- public void stop(final String metricsId) {
- dirty = true;
- allMetrics.get(metricsId).stop();
- }
-
- public void finish(final String metricsId, final long bulk) {
- dirty = true;
- final MutableMetrics metrics = allMetrics.get(metricsId);
- metrics.stop();
- metrics.incrementCount(TraversalMetrics.TRAVERSER_COUNT_ID, 1);
- metrics.incrementCount(TraversalMetrics.ELEMENT_COUNT_ID, bulk);
- }
-
- @Override
- public long getDuration(final TimeUnit unit) {
- computeTotals();
- return unit.convert(totalStepDuration, MutableMetrics.SOURCE_UNIT);
- }
-
- @Override
- public Metrics getMetrics(final int index) {
- computeTotals();
- // adjust index to account for the injected profile steps
- return (Metrics) computedMetrics.get(indexToLabelMap.get(index));
- }
-
- @Override
- public Metrics getMetrics(final String id) {
- computeTotals();
- return computedMetrics.get(id);
- }
-
- @Override
- public Collection<ImmutableMetrics> getMetrics() {
- computeTotals();
- return computedMetrics.values();
- }
-
- @Override
- public String toString() {
- computeTotals();
-
- // Build a pretty table of metrics data.
-
- // Append headers
- final StringBuilder sb = new StringBuilder("Traversal Metrics\n")
- .append(String.format("%-50s %21s %11s %15s %8s", HEADERS));
-
- sb.append("\n=============================================================================================================");
-
- appendMetrics(computedMetrics.values(), sb, 0);
-
- // Append total duration
- sb.append(String.format("%n%50s %21s %11s %15.3f %8s",
- ">TOTAL", "-", "-", getDuration(TimeUnit.MICROSECONDS) / 1000.0, "-"));
-
- return sb.toString();
- }
-
- private void appendMetrics(final Collection<? extends Metrics> metrics, final StringBuilder sb, final int indent) {
- // Append each StepMetric's row. indexToLabelMap values are ordered by index.
- for (Metrics m : metrics) {
- String rowName = m.getName();
- for (int ii = 0; ii < indent; ii++) {
- rowName = " " + rowName;
- }
- rowName = StringUtils.abbreviate(rowName, 50);
- final long itemCount = m.getCount(TraversalMetrics.ELEMENT_COUNT_ID);
- final long traverserCount = m.getCount(TraversalMetrics.TRAVERSER_COUNT_ID);
-
- Double percentDur = (Double) m.getAnnotation(TraversalMetrics.PERCENT_DURATION_KEY);
- if (percentDur != null) {
- sb.append(String.format("%n%-50s %21d %11d %15.3f %8.2f",
- rowName, itemCount, traverserCount, m.getDuration(TimeUnit.MICROSECONDS) / 1000.0, percentDur));
- } else {
- sb.append(String.format("%n%-50s %21d %11d %15.3f",
- rowName, itemCount, traverserCount, m.getDuration(TimeUnit.MICROSECONDS) / 1000.0));
- }
- appendMetrics(m.getNested(), sb, indent + 1);
- }
- }
-
- private void computeTotals() {
- if (!dirty) {
- // already good to go
- return;
- }
-
- // Create temp list of ordered metrics
- List<MutableMetrics> tempMetrics = new ArrayList<>(metrics.size());
- for (String label : indexToLabelMap.values()) {
- // The indexToLabelMap is sorted by index (key)
- tempMetrics.add(metrics.get(label).clone());
- }
-
- // Calculate total duration
- this.totalStepDuration = 0;
- tempMetrics.forEach(m -> this.totalStepDuration += m.getDuration(MutableMetrics.SOURCE_UNIT));
-
- // Assign %'s
- tempMetrics.forEach(m -> {
- double dur = m.getDuration(TimeUnit.NANOSECONDS) * 100.d / this.totalStepDuration;
- m.setAnnotation(TraversalMetrics.PERCENT_DURATION_KEY, dur);
- });
-
- // Store immutable instances of the calculated metrics
- computedMetrics = new LinkedHashMap<>(metrics.size());
- tempMetrics.forEach(it -> computedMetrics.put(it.getId(), it.getImmutableClone()));
-
- dirty = false;
- }
-
- public static StandardTraversalMetrics merge(final Iterator<StandardTraversalMetrics> toMerge) {
- final StandardTraversalMetrics newTraversalMetrics = new StandardTraversalMetrics();
-
- // iterate the incoming TraversalMetrics
- toMerge.forEachRemaining(inTraversalMetrics -> {
- // aggregate the internal Metrics
- inTraversalMetrics.metrics.forEach((metricsId, toAggregate) -> {
-
- MutableMetrics aggregateMetrics = newTraversalMetrics.metrics.get(metricsId);
- if (null == aggregateMetrics) {
- // need to create a Metrics to aggregate into
- aggregateMetrics = new MutableMetrics(toAggregate.getId(), toAggregate.getName());
-
- newTraversalMetrics.metrics.put(metricsId, aggregateMetrics);
- // Set the index of the Metrics
- for (Map.Entry<Integer, String> entry : inTraversalMetrics.indexToLabelMap.entrySet()) {
- if (metricsId.equals(entry.getValue())) {
- newTraversalMetrics.indexToLabelMap.put(entry.getKey(), metricsId);
- break;
- }
- }
- }
- aggregateMetrics.aggregate(toAggregate);
- });
- });
- return newTraversalMetrics;
- }
-
- public void addMetrics(final MutableMetrics newMetrics, final String id, final int index, final boolean isTopLevel, final String profileStepId) {
- if (isTopLevel) {
- // The index is necessary to ensure that step order is preserved after a merge.
- indexToLabelMap.put(index, id);
- metrics.put(id, newMetrics);
- }
- allMetrics.put(profileStepId, newMetrics);
- }
-}