You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/02/12 14:01:55 UTC
[29/77] [partial] incubator-tinkerpop git commit: moved com/tinkerpop
directories to org/apache/tinkerpop
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1545201f/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/GraphStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/GraphStrategy.java b/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/GraphStrategy.java
deleted file mode 100644
index ba9d22c..0000000
--- a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/GraphStrategy.java
+++ /dev/null
@@ -1,708 +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 com.tinkerpop.gremlin.structure.strategy;
-
-import com.tinkerpop.gremlin.process.graph.traversal.GraphTraversal;
-import com.tinkerpop.gremlin.structure.Direction;
-import com.tinkerpop.gremlin.structure.Edge;
-import com.tinkerpop.gremlin.structure.Graph;
-import com.tinkerpop.gremlin.structure.Property;
-import com.tinkerpop.gremlin.structure.Vertex;
-import com.tinkerpop.gremlin.structure.VertexProperty;
-import com.tinkerpop.gremlin.util.function.TriFunction;
-
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import java.util.function.UnaryOperator;
-
-/**
- * Defines a collection of functions that plug-in to Gremlin Structure API methods to enhance or alter the functionality of
- * the implementation. The methods defined in {@link GraphStrategy} follow a common pattern where each method
- * represents some injection point for new logic in the Gremlin Structure API. A method always accepts a
- * {@link StrategyContext} which contains the context of the call being made and will have
- * a different {@link StrategyContext#getCurrent()} object depending on that context (e.g the
- * {@link com.tinkerpop.gremlin.structure.Vertex#addEdge(String, com.tinkerpop.gremlin.structure.Vertex, Object...)} method will send the instance of
- * the {@link com.tinkerpop.gremlin.structure.Vertex} that was the object of that method call).
- * <p/>
- * A method will always return a {@link java.util.function.UnaryOperator} where the argument and return value to it is a function with
- * the same signature as the calling method where the strategy logic is being injected. The argument passed in to
- * this function will be a reference to the original calling function (from an implementation perspective, it might
- * be best to think of this "calling function" as the original Gremlin Structure API method that performs the ultimate
- * operation against the graph). In constructing the outgoing function to the {@link java.util.function.UnaryOperator}, it should
- * of course match the signature of the original calling function and depending on the functionality,
- * call the original function to trigger a call to the underlying implementation.
- * <p/>
- * The most simplistic implementation of a strategy method is to simply return a
- * {@link java.util.function.UnaryOperator#identity()} which happens to be the default implementation for all the
- * methods. By returning the {@code identity} function, the incoming original function is simply returned back
- * unchanged with no additional enhancements to the execution of it.
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public interface GraphStrategy {
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.Graph.Iterators#vertexIterator}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with
- * {@link com.tinkerpop.gremlin.structure.Graph.Iterators#vertexIterator} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Function<Object[], Iterator<Vertex>>> getGraphIteratorsVertexIteratorStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.Graph.Iterators#edgeIterator}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with
- * {@link com.tinkerpop.gremlin.structure.Graph.Iterators#edgeIterator} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Function<Object[], Iterator<Edge>>> getGraphIteratorsEdgeIteratorStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Graph.Variables#keys()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Graph.Variables#keys()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Supplier<Set<String>>> getVariableKeysStrategy(final StrategyContext<StrategyVariables> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Graph.Variables#asMap()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Graph.Variables#asMap()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Supplier<Map<String, Object>>> getVariableAsMapStrategy(final StrategyContext<StrategyVariables> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.Graph.Variables#get(String)}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with {@link com.tinkerpop.gremlin.structure.Graph.Variables#get(String)} signature
- * and returns an enhanced strategy {@link java.util.function.Function} with the same signature
- */
- public default <R> UnaryOperator<Function<String, Optional<R>>> getVariableGetStrategy(final StrategyContext<StrategyVariables> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.BiConsumer} that enhances the features of {@link com.tinkerpop.gremlin.structure.Graph.Variables#set(String, Object)}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.BiConsumer} with {@link com.tinkerpop.gremlin.structure.Graph.Variables#set(String, Object)} signature
- * and returns an enhanced strategy {@link java.util.function.BiConsumer} with the same signature
- */
- public default UnaryOperator<BiConsumer<String, Object>> getVariableSetStrategy(final StrategyContext<StrategyVariables> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Consumer} that enhances the features of {@link com.tinkerpop.gremlin.structure.Graph.Variables#remove(String)}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Consumer} with {@link com.tinkerpop.gremlin.structure.Graph.Variables#remove(String)} signature
- * and returns an enhanced strategy {@link java.util.function.BiConsumer} with the same signature
- */
- public default UnaryOperator<Consumer<String>> getVariableRemoveStrategy(final StrategyContext<StrategyVariables> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.Graph#addVertex(Object...)}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with {@link com.tinkerpop.gremlin.structure.Graph#addVertex(Object...)} signature
- * and returns an enhanced strategy {@link java.util.function.Function} with the same signature
- */
- public default UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link com.tinkerpop.gremlin.util.function.TriFunction} that enhances the features of
- * {@link com.tinkerpop.gremlin.structure.Vertex#addEdge(String, com.tinkerpop.gremlin.structure.Vertex, Object...)}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link com.tinkerpop.gremlin.util.function.TriFunction} with
- * {@link com.tinkerpop.gremlin.structure.Vertex#addEdge(String, com.tinkerpop.gremlin.structure.Vertex, Object...)} signature
- * and returns an enhanced strategy {@link java.util.function.Function} with the same signature
- */
- public default UnaryOperator<TriFunction<String, Vertex, Object[], Edge>> getAddEdgeStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Edge#remove()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Edge#remove()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Supplier<Void>> getRemoveEdgeStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Vertex#remove()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Vertex#remove()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Supplier<Void>> getRemoveVertexStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Property#remove()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Property#remove()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V> UnaryOperator<Supplier<Void>> getRemovePropertyStrategy(final StrategyContext<StrategyProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.VertexProperty#remove()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.VertexProperty#remove()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V> UnaryOperator<Supplier<Void>> getRemoveVertexPropertyStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.Vertex#property(String)}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with
- * {@link com.tinkerpop.gremlin.structure.Vertex#property(String)} signature
- * and returns an enhanced strategy {@link java.util.function.Function} with the same signature
- */
- public default <V> UnaryOperator<Function<String, VertexProperty<V>>> getVertexGetPropertyStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Vertex#keys()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Vertex#keys()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Supplier<Set<String>>> getVertexKeysStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Vertex#label()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Vertex#label()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Supplier<String>> getVertexLabelStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.BiFunction} that enhances the features of {@link com.tinkerpop.gremlin.structure.Vertex#property(String, Object)}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.BiFunction} with
- * {@link com.tinkerpop.gremlin.structure.Vertex#property(String, Object)} signature
- * and returns an enhanced strategy {@link java.util.function.BiFunction} with the same signature
- */
- public default <V> UnaryOperator<BiFunction<String, V, VertexProperty<V>>> getVertexPropertyStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.Element.Iterators#propertyIterator}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with
- * {@link com.tinkerpop.gremlin.structure.Element.Iterators#propertyIterator} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V> UnaryOperator<Function<String[], Iterator<VertexProperty<V>>>> getVertexIteratorsPropertyIteratorStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link TriFunction} that enhances the features of {@link com.tinkerpop.gremlin.structure.Vertex.Iterators#vertexIterator}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link BiFunction} with
- * {@link com.tinkerpop.gremlin.structure.Vertex.Iterators#vertexIterator} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<BiFunction<Direction, String[], Iterator<Vertex>>> getVertexIteratorsVertexIteratorStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link TriFunction} that enhances the features of {@link com.tinkerpop.gremlin.structure.Vertex.Iterators#edgeIterator}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link BiFunction} with
- * {@link com.tinkerpop.gremlin.structure.Vertex.Iterators#edgeIterator} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<BiFunction<Direction, String[], Iterator<Edge>>> getVertexIteratorsEdgeIteratorStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.Vertex.Iterators#valueIterator}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with
- * {@link com.tinkerpop.gremlin.structure.Vertex.Iterators#valueIterator} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V> UnaryOperator<Function<String[], Iterator<V>>> getVertexIteratorsValueIteratorStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Vertex#id()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Vertex#id()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Supplier<Object>> getVertexIdStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Vertex#graph()}.
- * Note that in this case, the {@link Graph} is {@link StrategyGraph} and this would be the expected
- * type to pass back out.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Vertex#graph()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Supplier<Graph>> getVertexGraphStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.Element#value(String)}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with
- * {@link com.tinkerpop.gremlin.structure.Element#value(String)} signature
- * and returns an enhanced strategy {@link java.util.function.Function} with the same signature
- */
- public default <V> UnaryOperator<Function<String, V>> getVertexValueStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.Edge#property(String)}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with
- * {@link com.tinkerpop.gremlin.structure.Edge#property(String)} signature
- * and returns an enhanced strategy {@link java.util.function.Function} with the same signature
- */
- public default <V> UnaryOperator<Function<String, Property<V>>> getEdgeGetPropertyStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.Edge.Iterators#vertexIterator}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with
- * {@link com.tinkerpop.gremlin.structure.Edge.Iterators#vertexIterator} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Function<Direction, Iterator<Vertex>>> getEdgeIteratorsVertexIteratorStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.Edge.Iterators#valueIterator}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with
- * {@link com.tinkerpop.gremlin.structure.Edge.Iterators#valueIterator} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V> UnaryOperator<Function<String[], Iterator<V>>> getEdgeIteratorsValueIteratorStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.Edge.Iterators#propertyIterator}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with
- * {@link com.tinkerpop.gremlin.structure.Edge.Iterators#propertyIterator} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V> UnaryOperator<Function<String[], Iterator<Property<V>>>> getEdgeIteratorsPropertyIteratorStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Edge#keys()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Edge#keys()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Supplier<Set<String>>> getEdgeKeysStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.BiFunction} that enhances the features of {@link com.tinkerpop.gremlin.structure.Edge#property(String, Object)}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.BiFunction} with
- * {@link com.tinkerpop.gremlin.structure.Edge#property(String, Object)} signature
- * and returns an enhanced strategy {@link java.util.function.BiFunction} with the same signature
- */
- public default <V> UnaryOperator<BiFunction<String, V, Property<V>>> getEdgePropertyStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.Edge#value(String)}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with
- * {@link com.tinkerpop.gremlin.structure.Element#value(String)} signature
- * and returns an enhanced strategy {@link java.util.function.Function} with the same signature
- */
- public default <V> UnaryOperator<Function<String, V>> getEdgeValueStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Edge#id()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Edge#id()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Supplier<Object>> getEdgeIdStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Edge#graph()}.
- * Note that in this case, the {@link Graph} is {@link StrategyGraph} and this would be the expected
- * type to pass back out.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Edge#graph()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Supplier<Graph>> getEdgeGraphStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Edge#label()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Edge#label()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Supplier<String>> getEdgeLabelStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.VertexProperty#id()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.VertexProperty#id()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V> UnaryOperator<Supplier<Object>> getVertexPropertyIdStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.VertexProperty#value()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Supplier} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.VertexProperty#value()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V> UnaryOperator<Supplier<V>> getVertexPropertyValueStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Property#key()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Supplier} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Property#key()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V> UnaryOperator<Supplier<String>> getVertexPropertyKeyStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.VertexProperty.Iterators#propertyIterator}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with
- * {@link com.tinkerpop.gremlin.structure.VertexProperty.Iterators#propertyIterator} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V, U> UnaryOperator<Function<String[], Iterator<Property<V>>>> getVertexPropertyIteratorsPropertyIteratorStrategy(final StrategyContext<StrategyVertexProperty<U>> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.VertexProperty.Iterators#valueIterator}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with
- * {@link com.tinkerpop.gremlin.structure.VertexProperty.Iterators#valueIterator} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V, U> UnaryOperator<Function<String[], Iterator<V>>> getVertexPropertyIteratorsValueIteratorStrategy(final StrategyContext<StrategyVertexProperty<U>> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.BiFunction} that enhances the features of {@link com.tinkerpop.gremlin.structure.VertexProperty#property(String, Object)}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.BiFunction} with
- * {@link com.tinkerpop.gremlin.structure.VertexProperty#property(String, Object)} signature
- * and returns an enhanced strategy {@link java.util.function.BiFunction} with the same signature
- */
- public default <V, U> UnaryOperator<BiFunction<String, V, Property<V>>> getVertexPropertyPropertyStrategy(final StrategyContext<StrategyVertexProperty<U>> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.VertexProperty#graph()}.
- * Note that in this case, the {@link Graph} is {@link StrategyGraph} and this would be the expected
- * type to pass back out.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.VertexProperty#graph()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V> UnaryOperator<Supplier<Graph>> getVertexPropertyGraphStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.VertexProperty#label()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.VertexProperty#label()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V> UnaryOperator<Supplier<String>> getVertexPropertyLabelStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.VertexProperty#keys()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.VertexProperty#keys()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V> UnaryOperator<Supplier<Set<String>>> getVertexPropertyKeysStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.VertexProperty#element}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.VertexProperty#element} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V> UnaryOperator<Supplier<Vertex>> getVertexPropertyGetElementStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Graph#close()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Supplier} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Graph#close()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default UnaryOperator<Supplier<Void>> getGraphCloseStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.Graph#V}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with
- * {@link com.tinkerpop.gremlin.structure.Graph#V} signature
- * and returns an enhanced strategy {@link java.util.function.Function} with the same signature
- */
- public default UnaryOperator<Function<Object[], GraphTraversal<Vertex, Vertex>>> getGraphVStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Function} that enhances the features of {@link com.tinkerpop.gremlin.structure.Graph#E}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Function} that accepts a {@link java.util.function.Function} with
- * {@link com.tinkerpop.gremlin.structure.Graph#E} signature
- * and returns an enhanced strategy {@link java.util.function.Function} with the same signature
- */
- public default UnaryOperator<Function<Object[], GraphTraversal<Edge, Edge>>> getGraphEStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Property#value()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Supplier} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Property#value()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V> UnaryOperator<Supplier<V>> getPropertyValueStrategy(final StrategyContext<StrategyProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
- /**
- * Construct a {@link java.util.function.Supplier} that enhances the features of {@link com.tinkerpop.gremlin.structure.Property#key()}.
- *
- * @param ctx the context within which this strategy function is called
- * @param composingStrategy the strategy that composed this strategy function
- * @return a {@link java.util.function.Supplier} that accepts a {@link java.util.function.Supplier} with
- * {@link com.tinkerpop.gremlin.structure.Property#key()} signature
- * and returns an enhanced strategy {@link java.util.function.Supplier} with the same signature
- */
- public default <V> UnaryOperator<Supplier<String>> getPropertyKeyStrategy(final StrategyContext<StrategyProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1545201f/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/IdStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/IdStrategy.java b/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/IdStrategy.java
deleted file mode 100644
index d47b086..0000000
--- a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/IdStrategy.java
+++ /dev/null
@@ -1,275 +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 com.tinkerpop.gremlin.structure.strategy;
-
-import com.tinkerpop.gremlin.process.T;
-import com.tinkerpop.gremlin.process.graph.traversal.GraphTraversal;
-import com.tinkerpop.gremlin.structure.Contains;
-import com.tinkerpop.gremlin.structure.Edge;
-import com.tinkerpop.gremlin.structure.Element;
-import com.tinkerpop.gremlin.structure.Property;
-import com.tinkerpop.gremlin.structure.Vertex;
-import com.tinkerpop.gremlin.structure.VertexProperty;
-import com.tinkerpop.gremlin.structure.util.ElementHelper;
-import com.tinkerpop.gremlin.structure.util.StringFactory;
-import com.tinkerpop.gremlin.util.function.TriFunction;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.UUID;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import java.util.function.UnaryOperator;
-
-/**
- * A {@link GraphStrategy} implementation which enables mapper element IDs even for those graphs which don't
- * otherwise support them.
- * <p/>
- * For those graphs which support vertex indices but not edge indices (or vice versa), the strategy can be configured
- * to use mapper IDs only for vertices or only for edges. ID generation is also configurable via ID {@link Supplier}
- * functions.
- * <p/>
- * If the {@link IdStrategy} is used in combination with a sequence of other strategies and when ID assignment
- * is enabled for an element, calls to strategies following this one are not made. It is important to consider that
- * aspect of its operation when doing strategy composition. Typically, the {@link IdStrategy} should be
- * executed last in a sequence.
- *
- * @author Joshua Shinavier (http://fortytwo.net)
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public final class IdStrategy implements GraphStrategy {
-
- private final String idKey;
-
- private final Supplier<?> edgeIdSupplier;
- private final Supplier<?> vertexIdSupplier;
-
- private final boolean supportsVertexId;
- private final boolean supportsEdgeId;
-
- /**
- * Creates a new instance. Public instantiation should be handled through the {@link Builder}.
- */
- private IdStrategy(final String idKey, final Supplier<?> vertexIdSupplier,
- final Supplier<?> edgeIdSupplier, final boolean supportsVertexId,
- final boolean supportsEdgeId) {
- this.idKey = idKey;
- this.edgeIdSupplier = edgeIdSupplier;
- this.vertexIdSupplier = vertexIdSupplier;
- this.supportsEdgeId = supportsEdgeId;
- this.supportsVertexId = supportsVertexId;
- }
-
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (keyValues) -> {
- throwIfIdKeyIsSet(Vertex.class, ElementHelper.getKeys(keyValues));
- return f.apply(this.injectId(supportsVertexId, keyValues, vertexIdSupplier).toArray());
- };
- }
-
- @Override
- public UnaryOperator<TriFunction<String, Vertex, Object[], Edge>> getAddEdgeStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (label, v, keyValues) -> {
- throwIfIdKeyIsSet(Edge.class, ElementHelper.getKeys(keyValues));
- return f.apply(label, v, this.injectId(supportsEdgeId, keyValues, edgeIdSupplier).toArray());
- };
- }
-
- @Override
- public UnaryOperator<Function<Object[], Iterator<Edge>>> getGraphIteratorsEdgeIteratorStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return supportsVertexId ? (f) -> (ids) -> ctx.getStrategyGraph().getBaseGraph().E().has(idKey, Contains.within, Arrays.asList(ids)) : UnaryOperator.identity();
- }
-
- @Override
- public UnaryOperator<Function<Object[], Iterator<Vertex>>> getGraphIteratorsVertexIteratorStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return supportsVertexId ? (f) -> (ids) -> ctx.getStrategyGraph().getBaseGraph().V().has(idKey, Contains.within, Arrays.asList(ids)) : UnaryOperator.identity();
- }
-
- @Override
- public UnaryOperator<Function<Object[], GraphTraversal<Edge, Edge>>> getGraphEStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return supportsEdgeId ? (f) -> (ids) -> ctx.getStrategyGraph().getBaseGraph().E().has(idKey, Contains.within, Arrays.asList(ids)) : UnaryOperator.identity();
- }
-
- @Override
- public UnaryOperator<Function<Object[], GraphTraversal<Vertex, Vertex>>> getGraphVStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return supportsVertexId ? (f) -> (ids) -> ctx.getStrategyGraph().getBaseGraph().V().has(idKey, Contains.within, Arrays.asList(ids)) : UnaryOperator.identity();
- }
-
- @Override
- public UnaryOperator<Supplier<Object>> getVertexIdStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return supportsVertexId ? (f) -> () -> ctx.getCurrent().getBaseVertex().value(idKey) : UnaryOperator.identity();
- }
-
- @Override
- public UnaryOperator<Supplier<Object>> getEdgeIdStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return supportsEdgeId ? (f) -> () -> ctx.getCurrent().getBaseEdge().value(idKey) : UnaryOperator.identity();
- }
-
- @Override
- public <V> UnaryOperator<BiFunction<String, V, VertexProperty<V>>> getVertexPropertyStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (k, v) -> {
- throwIfIdKeyIsSet(ctx.getCurrent().getClass(), k);
- return f.apply(k, v);
- };
- }
-
- @Override
- public <V> UnaryOperator<BiFunction<String, V, Property<V>>> getEdgePropertyStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (k, v) -> {
- throwIfIdKeyIsSet(ctx.getCurrent().getClass(), k);
- return f.apply(k, v);
- };
- }
-
- @Override
- public String toString() {
- return StringFactory.graphStrategyString(this);
- }
-
- private void throwIfIdKeyIsSet(final Class<? extends Element> element, final String k) {
- if (supportsAnId(element) && this.idKey.equals(k))
- throw new IllegalArgumentException(String.format("The key [%s] is protected by %s and cannot be set", idKey, IdStrategy.class.getSimpleName()));
- }
-
- private void throwIfIdKeyIsSet(final Class<? extends Element> element, final Set<String> keys) {
- if (supportsAnId(element) && keys.contains(this.idKey))
- throw new IllegalArgumentException(String.format("The key [%s] is protected by %s and cannot be set", idKey, IdStrategy.class.getSimpleName()));
- }
-
- private boolean supportsAnId(final Class<? extends Element> element) {
- return ((Vertex.class.isAssignableFrom(element) && supportsVertexId) || (Edge.class.isAssignableFrom(element) && supportsEdgeId));
- }
-
- /**
- * Gets the property name of the key used to lookup graph elements. Use this value to create an index in the underlying graph instance.
- */
- public String getIdKey() {
- return this.idKey;
- }
-
- public boolean isSupportsVertexId() {
- return supportsVertexId;
- }
-
- public boolean isSupportsEdgeId() {
- return supportsEdgeId;
- }
-
- private List<Object> injectId(final boolean supports, final Object[] keyValues, final Supplier<?> idMaker) {
- final List<Object> o = new ArrayList<>(Arrays.asList(keyValues));
- if (supports) {
- final Object val = ElementHelper.getIdValue(keyValues).orElse(idMaker.get());
- final int pos = o.indexOf(T.id);
- if (pos > -1) {
- o.remove(pos);
- o.remove(pos);
- }
-
- o.addAll(Arrays.asList(this.idKey, val));
- }
-
- return o;
- }
-
- /**
- * Create the {@link Builder} to create a {@link IdStrategy}.
- *
- * @param idKey The key to use for the index to lookup graph elements.
- */
- public static Builder build(final String idKey) {
- return new Builder(idKey);
- }
-
- public static final class Builder {
- private final String idKey;
- private Supplier<?> vertexIdSupplier;
- private Supplier<?> edgeIdSupplier;
- private boolean supportsVertexId;
- private boolean supportsEdgeId;
-
-
- private Builder(final String idKey) {
- this.idKey = idKey;
- this.edgeIdSupplier = Builder::supplyStringId;
- this.vertexIdSupplier = Builder::supplyStringId;
- this.supportsEdgeId = true;
- this.supportsVertexId = true;
-
- }
-
- public IdStrategy create() {
- if (!this.supportsEdgeId && !this.supportsVertexId)
- throw new IllegalStateException("Since supportsEdgeId and supportsVertexId are false, there is no need to use IdGraphStrategy");
-
- return new IdStrategy(this.idKey, this.vertexIdSupplier, this.edgeIdSupplier,
- this.supportsVertexId, this.supportsEdgeId);
- }
-
- /**
- * Provide a function that will provide ids when none are provided explicitly when creating vertices. By default
- * a UUID string will be used if this value is not set.
- */
- public Builder vertexIdMaker(final Supplier<?> vertexIdSupplier) {
- if (null == vertexIdSupplier)
- throw new IllegalArgumentException("vertexIdSupplier");
-
- this.vertexIdSupplier = vertexIdSupplier;
- return this;
- }
-
- /**
- * Provide a function that will provide ids when none are provided explicitly when creating edges. By default
- * a UUID string will be used if this value is not set.
- */
- public Builder edgeIdMaker(final Supplier<?> edgeIdSupplier) {
- if (null == edgeIdSupplier)
- throw new IllegalArgumentException("edgeIdSupplier");
-
- this.edgeIdSupplier = edgeIdSupplier;
- return this;
- }
-
- /**
- * Turn off support for this strategy for edges. Note that this value cannot be false if
- * {@link #supportsVertexId(boolean)} is also false.
- */
- public Builder supportsEdgeId(final boolean supports) {
- this.supportsEdgeId = supports;
- return this;
- }
-
- /**
- * Turn off support for this strategy for edges. Note that this value cannot be false if
- * {@link #supportsEdgeId(boolean)} is also false.
- */
- public Builder supportsVertexId(final boolean supports) {
- this.supportsVertexId = supports;
- return this;
- }
-
- private static String supplyStringId() {
- return UUID.randomUUID().toString();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1545201f/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/IdentityStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/IdentityStrategy.java b/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/IdentityStrategy.java
deleted file mode 100644
index f1a0f5a..0000000
--- a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/IdentityStrategy.java
+++ /dev/null
@@ -1,43 +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 com.tinkerpop.gremlin.structure.strategy;
-
-import com.tinkerpop.gremlin.structure.util.StringFactory;
-
-/**
- * A pass through implementation of {@link GraphStrategy} where all strategy functions are simply executed as
- * they were originally implemented.
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public final class IdentityStrategy implements GraphStrategy {
- private static final IdentityStrategy instance = new IdentityStrategy();
-
- private IdentityStrategy() {
- }
-
- @Override
- public String toString() {
- return StringFactory.graphStrategyString(this);
- }
-
- public static final IdentityStrategy instance() {
- return instance;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1545201f/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/PartitionStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/PartitionStrategy.java b/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/PartitionStrategy.java
deleted file mode 100644
index 7538c84..0000000
--- a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/PartitionStrategy.java
+++ /dev/null
@@ -1,322 +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 com.tinkerpop.gremlin.structure.strategy;
-
-import com.tinkerpop.gremlin.process.Step;
-import com.tinkerpop.gremlin.process.Traverser;
-import com.tinkerpop.gremlin.process.graph.traversal.GraphTraversal;
-import com.tinkerpop.gremlin.process.graph.traversal.step.filter.HasStep;
-import com.tinkerpop.gremlin.process.graph.traversal.DefaultGraphTraversal;
-import com.tinkerpop.gremlin.process.graph.util.HasContainer;
-import com.tinkerpop.gremlin.process.traverser.util.DefaultTraverserGeneratorFactory;
-import com.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
-import com.tinkerpop.gremlin.structure.Contains;
-import com.tinkerpop.gremlin.structure.Direction;
-import com.tinkerpop.gremlin.structure.Edge;
-import com.tinkerpop.gremlin.structure.Element;
-import com.tinkerpop.gremlin.structure.Property;
-import com.tinkerpop.gremlin.structure.Vertex;
-import com.tinkerpop.gremlin.structure.VertexProperty;
-import com.tinkerpop.gremlin.structure.util.ElementHelper;
-import com.tinkerpop.gremlin.structure.util.StringFactory;
-import com.tinkerpop.gremlin.util.StreamFactory;
-import com.tinkerpop.gremlin.util.function.TriFunction;
-import com.tinkerpop.gremlin.util.iterator.IteratorUtils;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.function.BiFunction;
-import java.util.function.BiPredicate;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import java.util.function.UnaryOperator;
-
-/**
- * A {@link GraphStrategy} which enables support for logical graph partitioning where the Graph can be blinded to
- * different parts of the total {@link com.tinkerpop.gremlin.structure.Graph}. Note that the {@code partitionKey}
- * is hidden by this strategy. Use the base {@link com.tinkerpop.gremlin.structure.Graph} to access that.
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
- * @author Joshua Shinavier (http://fortytwo.net)
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class PartitionStrategy implements GraphStrategy {
-
- private String writePartition;
- private final String partitionKey;
- private final Set<String> readPartitions = new HashSet<>();
-
- private PartitionStrategy(final String partitionKey, final String partition) {
- this.writePartition = partition;
- this.addReadPartition(partition);
- this.partitionKey = partitionKey;
- }
-
- public String getWritePartition() {
- return this.writePartition;
- }
-
- public void setWritePartition(final String writePartition) {
- this.writePartition = writePartition;
- }
-
- public String getPartitionKey() {
- return this.partitionKey;
- }
-
- public Set<String> getReadPartitions() {
- return Collections.unmodifiableSet(this.readPartitions);
- }
-
- public void removeReadPartition(final String readPartition) {
- this.readPartitions.remove(readPartition);
- }
-
- public void addReadPartition(final String readPartition) {
- this.readPartitions.add(readPartition);
- }
-
- public void clearReadPartitions() {
- this.readPartitions.clear();
- }
-
- ///////////// old subgraph strategy methods
- @Override
- public UnaryOperator<BiFunction<Direction, String[], Iterator<Vertex>>> getVertexIteratorsVertexIteratorStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (direction, labels) -> StreamFactory
- .stream(ctx.getCurrent().getBaseVertex().iterators().edgeIterator(direction, labels))
- .filter(this::testEdge)
- .map(edge -> otherVertex(direction, ctx.getCurrent(), edge)).iterator();
- // TODO: Note that we are not doing f.apply() like the other methods. Is this bad?
- // by not calling f.apply() to get the iterator, we're possibly bypassing strategy methods that
- // could have been sequenced
- }
-
- @Override
- public UnaryOperator<BiFunction<Direction, String[], Iterator<Edge>>> getVertexIteratorsEdgeIteratorStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (direction, labels) -> IteratorUtils.filter(f.apply(direction, labels), this::testEdge);
- }
-
- @Override
- public UnaryOperator<Function<Direction, Iterator<Vertex>>> getEdgeIteratorsVertexIteratorStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return (f) -> direction -> IteratorUtils.filter(f.apply(direction), this::testVertex);
- }
-
- @Override
- public UnaryOperator<Function<Object[], GraphTraversal<Vertex, Vertex>>> getGraphVStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return (f) -> ids -> {
- final GraphTraversal<Vertex, Vertex> traversal = this.generateTraversal(ctx.getStrategyGraph().getBaseGraph().getClass());
- traversal.asAdmin().getStrategies().setTraverserGeneratorFactory(DefaultTraverserGeneratorFactory.instance());
- TraversalHelper.insertTraversal(0, f.apply(ids).has(this.partitionKey, Contains.within, getReadPartitions()).asAdmin(), traversal.asAdmin());
- return traversal.filter(vertex -> testVertex(vertex.get()));
- };
- }
-
- @Override
- public UnaryOperator<Function<Object[], GraphTraversal<Edge, Edge>>> getGraphEStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return (f) -> ids -> {
- final GraphTraversal<Edge, Edge> traversal = this.generateTraversal(ctx.getStrategyGraph().getBaseGraph().getClass());
- traversal.asAdmin().getStrategies().setTraverserGeneratorFactory(DefaultTraverserGeneratorFactory.instance());
- TraversalHelper.insertTraversal(0, f.apply(ids).has(this.partitionKey, Contains.within, getReadPartitions()).asAdmin(), traversal.asAdmin());
- return traversal.filter(edge -> testEdge(edge.get()));
- };
- }
-
- private boolean testElement(final Element element) {
- final Property<String> property = element instanceof StrategyElement ?
- ((StrategyElement) element).getBaseElement().property(this.partitionKey) :
- element.property(this.partitionKey);
- return property.isPresent() && this.readPartitions.contains(property.value());
- }
-
- private boolean testVertex(final Vertex vertex) {
- return testElement(vertex);
- }
-
- private boolean testEdge(final Edge edge) {
- // the edge must pass the edge predicate, and both of its incident vertices must also pass the vertex predicate
- // inV() and/or outV() will be empty if they do not. it is sometimes the case that an edge is unwrapped
- // in which case it may not be filtered. in such cases, the vertices on such edges should be tested.
- return testElement(edge)
- && (edge instanceof StrategyWrapped ? edge.iterators().vertexIterator(Direction.IN).hasNext() && edge.iterators().vertexIterator(Direction.OUT).hasNext()
- : testVertex(edge.iterators().vertexIterator(Direction.IN).next()) && testVertex(edge.iterators().vertexIterator(Direction.OUT).next()));
- }
-
- private static final Vertex otherVertex(final Direction direction, final Vertex start, final Edge edge) {
- if (direction.equals(Direction.BOTH)) {
- final Vertex inVertex = edge.iterators().vertexIterator(Direction.IN).next();
- return ElementHelper.areEqual(start, inVertex) ?
- edge.iterators().vertexIterator(Direction.OUT).next() :
- inVertex;
- } else {
- return edge.iterators().vertexIterator(direction.opposite()).next();
- }
- }
-
- private final <S, E> GraphTraversal<S, E> generateTraversal(final Class emanatingClass) {
- return new DefaultGraphTraversal<S, E>(emanatingClass) {
- @Override
- public GraphTraversal<S, Vertex> to(final Direction direction, final String... edgeLabels) {
- return direction.equals(Direction.BOTH) ?
- this.toE(direction, edgeLabels).otherV() :
- this.toE(direction, edgeLabels).toV(direction.opposite());
- }
-
- @Override
- public GraphTraversal<S, Edge> toE(final Direction direction, final String... edgeLabels) {
- return super.toE(direction, edgeLabels).has(getPartitionKey(), Contains.within, getReadPartitions()).filter(edge -> testEdge(edge.get()));
- }
-
- @Override
- public GraphTraversal<S, Vertex> toV(final Direction direction) {
- return super.toV(direction).has(getPartitionKey(), Contains.within, getReadPartitions());
- }
-
- @Override
- public GraphTraversal<S, Vertex> otherV() {
- return super.otherV().has(getPartitionKey(), Contains.within, getReadPartitions());
- }
-
- @Override
- public GraphTraversal<S, E> has(final String key, final BiPredicate predicate, final Object value) {
- final HasContainer hasContainer = new HasContainer(key, predicate, value);
- final HasStep<Element> hasStep = new HasStep(this, hasContainer) {
- @Override
- protected boolean filter(final Traverser.Admin traverser) {
- return hasContainer.test(((StrategyElement) traverser.get()).getBaseElement());
- }
- };
- return this.asAdmin().addStep((Step) hasStep);
- }
- };
- }
-
- ///////////////////////////
-
- @Override
- public <V> UnaryOperator<Function<String[], Iterator<VertexProperty<V>>>> getVertexIteratorsPropertyIteratorStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (keys) -> IteratorUtils.filter(f.apply(keys), property -> {
- return !this.partitionKey.equals(property.key());
- });
- }
-
- @Override
- public <V> UnaryOperator<Function<String[], Iterator<V>>> getVertexIteratorsValueIteratorStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (keys) -> IteratorUtils.map(ctx.getCurrent().iterators().<V>propertyIterator(keys), vertexProperty -> vertexProperty.value());
- }
-
- @Override
- public UnaryOperator<Supplier<Set<String>>> getVertexKeysStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return (f) -> () -> IteratorUtils.fill(IteratorUtils.filter(f.get().iterator(), key -> {
- return !this.partitionKey.equals(key);
- }), new HashSet<>());
- }
-
- @Override
- public <V> UnaryOperator<Function<String, VertexProperty<V>>> getVertexGetPropertyStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return (f) -> k -> {
- return k.equals(this.partitionKey) ? VertexProperty.<V>empty() : f.apply(k);
- };
- }
-
- @Override
- public <V> UnaryOperator<Function<String, Property<V>>> getEdgeGetPropertyStrategy(StrategyContext<StrategyEdge> ctx, GraphStrategy composingStrategy) {
- return (f) -> k -> {
- return k.equals(this.partitionKey) ? Property.<V>empty() : f.apply(k);
- };
- }
-
- @Override
- public <V> UnaryOperator<Function<String[], Iterator<Property<V>>>> getEdgeIteratorsPropertyIteratorStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (keys) -> IteratorUtils.filter(f.apply(keys), property -> {
- return !this.partitionKey.equals(property.key());
- });
- }
-
- @Override
- public <V> UnaryOperator<Function<String[], Iterator<V>>> getEdgeIteratorsValueIteratorStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (keys) -> IteratorUtils.map(ctx.getCurrent().iterators().<V>propertyIterator(keys), property -> property.value());
- }
-
- @Override
- public UnaryOperator<Supplier<Set<String>>> getEdgeKeysStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return (f) -> () -> IteratorUtils.fill(IteratorUtils.filter(f.get().iterator(), key -> {
- return !this.partitionKey.equals(key);
- }), new HashSet<>());
- }
-
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (keyValues) -> f.apply(this.addKeyValues(keyValues));
- }
-
- @Override
- public UnaryOperator<TriFunction<String, Vertex, Object[], Edge>> getAddEdgeStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (label, v, keyValues) -> f.apply(label, v, this.addKeyValues(keyValues));
- }
-
- private final Object[] addKeyValues(final Object[] keyValues) {
- final Object[] keyValuesExtended = Arrays.copyOf(keyValues, keyValues.length + 2);
- keyValuesExtended[keyValues.length] = this.partitionKey;
- keyValuesExtended[keyValues.length + 1] = this.writePartition;
- return keyValuesExtended;
- }
-
- @Override
- public String toString() {
- return StringFactory.graphStrategyString(this);
- }
-
- public static Builder build() {
- return new Builder();
- }
-
- public static class Builder {
- private String startPartition = "default";
- private String partitionKey = "_partition";
-
- private Builder() {
- }
-
- /**
- * The initial partition to filter by. If this value is not set, it will be defaulted to "default".
- */
- public Builder startPartition(final String startPartition) {
- if (null == startPartition) throw new IllegalArgumentException("The startPartition cannot be null");
- this.startPartition = startPartition;
- return this;
- }
-
- /**
- * The name of the partition key. If this is not set, then the value is defaulted to "_partition".
- */
- public Builder partitionKey(final String partitionKey) {
- if (null == partitionKey) throw new IllegalArgumentException("The partitionKey cannot be null");
- this.partitionKey = partitionKey;
- return this;
- }
-
- public PartitionStrategy create() {
- return new PartitionStrategy(partitionKey, startPartition);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1545201f/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/ReadOnlyStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/ReadOnlyStrategy.java b/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/ReadOnlyStrategy.java
deleted file mode 100644
index d76085d..0000000
--- a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/strategy/ReadOnlyStrategy.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 com.tinkerpop.gremlin.structure.strategy;
-
-import com.tinkerpop.gremlin.structure.Edge;
-import com.tinkerpop.gremlin.structure.Property;
-import com.tinkerpop.gremlin.structure.Vertex;
-import com.tinkerpop.gremlin.structure.VertexProperty;
-import com.tinkerpop.gremlin.structure.util.StringFactory;
-import com.tinkerpop.gremlin.util.function.TriFunction;
-
-import java.util.Collections;
-import java.util.Map;
-import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import java.util.function.UnaryOperator;
-
-/**
- * This {@link GraphStrategy} prevents the graph from being modified and will throw a
- * {@link UnsupportedOperationException} if an attempt is made to do so.
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public final class ReadOnlyStrategy implements GraphStrategy {
- private static final ReadOnlyStrategy instance = new ReadOnlyStrategy();
-
- private ReadOnlyStrategy() {
- }
-
- public static final ReadOnlyStrategy instance() {
- return instance;
- }
-
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return readOnlyFunction();
- }
-
- @Override
- public UnaryOperator<TriFunction<String, Vertex, Object[], Edge>> getAddEdgeStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return readOnlyTriFunction();
- }
-
- @Override
- public <V> UnaryOperator<BiFunction<String, V, Property<V>>> getEdgePropertyStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (t, u) -> {
- throw Exceptions.graphUsesReadOnlyStrategy();
- };
- }
-
- @Override
- public <V> UnaryOperator<BiFunction<String, V, VertexProperty<V>>> getVertexPropertyStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (t, u) -> {
- throw Exceptions.graphUsesReadOnlyStrategy();
- };
- }
-
- @Override
- public <V, U> UnaryOperator<BiFunction<String, V, Property<V>>> getVertexPropertyPropertyStrategy(final StrategyContext<StrategyVertexProperty<U>> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (t, u) -> {
- throw Exceptions.graphUsesReadOnlyStrategy();
- };
- }
-
- @Override
- public UnaryOperator<Supplier<Void>> getRemoveEdgeStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return readOnlySupplier();
- }
-
- @Override
- public UnaryOperator<Supplier<Void>> getRemoveVertexStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return readOnlySupplier();
- }
-
- @Override
- public <V> UnaryOperator<Supplier<Void>> getRemovePropertyStrategy(final StrategyContext<StrategyProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return readOnlySupplier();
- }
-
- @Override
- public UnaryOperator<BiConsumer<String, Object>> getVariableSetStrategy(final StrategyContext<StrategyVariables> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (k, v) -> {
- throw Exceptions.graphUsesReadOnlyStrategy();
- };
- }
-
- @Override
- public UnaryOperator<Supplier<Map<String, Object>>> getVariableAsMapStrategy(final StrategyContext<StrategyVariables> ctx, final GraphStrategy composingStrategy) {
- return (f) -> () -> Collections.unmodifiableMap(f.get());
- }
-
- @Override
- public <V> UnaryOperator<Supplier<Void>> getRemoveVertexPropertyStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return readOnlySupplier();
- }
-
- @Override
- public String toString() {
- return StringFactory.graphStrategyString(this);
- }
-
- public static <T> UnaryOperator<Supplier<T>> readOnlySupplier() {
- return (f) -> () -> {
- throw Exceptions.graphUsesReadOnlyStrategy();
- };
- }
-
- public static <T, U> UnaryOperator<Function<T, U>> readOnlyFunction() {
- return (f) -> (t) -> {
- throw Exceptions.graphUsesReadOnlyStrategy();
- };
- }
-
- public static <T, U, V, W> UnaryOperator<TriFunction<T, U, V, W>> readOnlyTriFunction() {
- return (f) -> (t, u, v) -> {
- throw Exceptions.graphUsesReadOnlyStrategy();
- };
- }
-
- public static class Exceptions {
- public static UnsupportedOperationException graphUsesReadOnlyStrategy() {
- return new UnsupportedOperationException(String.format("Graph uses %s and is therefore unmodifiable", ReadOnlyStrategy.class));
- }
- }
-}