public static void addRequirements(final TraversalStrategies traversalStrategies, final TraverserRequirement... requirements) { RequirementsStrategy strategy = (RequirementsStrategy) traversalStrategies.toList().stream().filter(s -> s instanceof RequirementsStrategy).findAny().orElse(null); if (null == strategy) { strategy = new RequirementsStrategy(); traversalStrategies.addStrategies(strategy); } else { final RequirementsStrategy cloneStrategy = new RequirementsStrategy(); cloneStrategy.requirements.addAll(strategy.requirements); strategy = cloneStrategy; traversalStrategies.addStrategies(strategy); } Collections.addAll(strategy.requirements, requirements); }
public static <A> void addSideEffect(final TraversalStrategies traversalStrategies, final String key, final A value, final BinaryOperator<A> reducer) { SideEffectStrategy strategy = (SideEffectStrategy) traversalStrategies.toList().stream().filter(s -> s instanceof SideEffectStrategy).findAny().orElse(null); if (null == strategy) { strategy = new SideEffectStrategy(); traversalStrategies.addStrategies(strategy); } else { final SideEffectStrategy cloneStrategy = new SideEffectStrategy(); cloneStrategy.sideEffects.addAll(strategy.sideEffects); strategy = cloneStrategy; traversalStrategies.addStrategies(strategy); } strategy.sideEffects.add(new Triplet<>(key, null == value ? null : value instanceof Supplier ? (Supplier) value : new ConstantSupplier<>(value), reducer)); } }
/** * {@inheritDoc} * * @deprecated As of release 3.3.5, replaced by {@link AnonymousTraversalSource#withRemote(RemoteConnection)}. * @see <a href="https://issues.apache.org/jira/browse/TINKERPOP-2078">TINKERPOP-2078</a> */ @Override @Deprecated public GraphTraversalSource withRemote(final RemoteConnection connection) { // check if someone called withRemote() more than once, so just release resources on the initial // connection as you can't have more than one. maybe better to toss IllegalStateException?? if (this.connection != null) throw new IllegalStateException(String.format("TraversalSource already configured with a RemoteConnection [%s]", connection)); final GraphTraversalSource clone = this.clone(); clone.connection = connection; clone.getStrategies().addStrategies(new RemoteStrategy(connection)); return clone; }
public void addGraphComputerStrategies(final TraversalSource traversalSource) { Class<? extends GraphComputer> graphComputerClass; if (this.computer.getGraphComputerClass().equals(GraphComputer.class)) { try { graphComputerClass = this.computer.apply(traversalSource.getGraph()).getClass(); } catch (final Exception e) { graphComputerClass = GraphComputer.class; } } else graphComputerClass = this.computer.getGraphComputerClass(); final List<TraversalStrategy<?>> graphComputerStrategies = TraversalStrategies.GlobalCache.getStrategies(graphComputerClass).toList(); traversalSource.getStrategies().addStrategies(graphComputerStrategies.toArray(new TraversalStrategy[graphComputerStrategies.size()])); }
public GraphTraversalSource(final RemoteConnection connection) { this(EmptyGraph.instance(), TraversalStrategies.GlobalCache.getStrategies(EmptyGraph.class).clone()); this.connection = connection; this.strategies.addStrategies(new RemoteStrategy(connection)); }
public SparqlTraversalSource(final RemoteConnection connection) { this(EmptyGraph.instance(), TraversalStrategies.GlobalCache.getStrategies(EmptyGraph.class).clone()); this.connection = connection; this.strategies.addStrategies(new RemoteStrategy(connection)); }
@Override public SparqlTraversalSource withRemote(final RemoteConnection connection) { try { // check if someone called withRemote() more than once, so just release resources on the initial // connection as you can't have more than one. maybe better to toss IllegalStateException?? if (this.connection != null) this.connection.close(); } catch (Exception ignored) { // not sure there's anything to do here } this.connection = connection; final TraversalSource clone = this.clone(); clone.getStrategies().addStrategies(new RemoteStrategy(connection)); return (SparqlTraversalSource) clone; }
public TraversalExplanation(final Traversal.Admin<?, ?> traversal) { this.traversal = traversal.clone(); TraversalStrategies mutatingStrategies = new DefaultTraversalStrategies(); for (final TraversalStrategy strategy : this.traversal.getStrategies().toList()) { final Traversal.Admin<?, ?> mutatingTraversal = this.traversal.clone(); mutatingStrategies.addStrategies(strategy); mutatingTraversal.setStrategies(mutatingStrategies); mutatingTraversal.applyStrategies(); this.strategyTraversals.add(Pair.with(strategy, mutatingTraversal)); } }
/** * Add an arbitrary collection of {@link TraversalStrategy} instances to the traversal source. * * @param traversalStrategies a collection of traversal strategies to add * @return a new traversal source with updated strategies */ public default TraversalSource withStrategies(final TraversalStrategy... traversalStrategies) { final TraversalSource clone = this.clone(); clone.getStrategies().addStrategies(traversalStrategies); clone.getBytecode().addSource(TraversalSource.Symbols.withStrategies, traversalStrategies); for (final TraversalStrategy traversalStrategy : traversalStrategies) { if (traversalStrategy instanceof VertexProgramStrategy) { ((VertexProgramStrategy) traversalStrategy).addGraphComputerStrategies(clone); } } return clone; }
/** * Add a sack to be used throughout the life of a spawned {@link Traversal}. * This adds a {@link org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SackStrategy} to the strategies. * * @param initialValue a supplier that produces the initial value of the sideEffect * @return a new traversal source with updated strategies */ public default <A> TraversalSource withSack(final Supplier<A> initialValue) { final TraversalSource clone = this.clone(); clone.getStrategies().addStrategies(SackStrategy.<A>build().initialValue(initialValue).create()); clone.getBytecode().addSource(TraversalSource.Symbols.withSack, initialValue); return clone; }
/** * Add a sack to be used throughout the life of a spawned {@link Traversal}. * This adds a {@link org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SackStrategy} to the strategies. * * @param initialValue the initial value of the sideEffect * @return a new traversal source with updated strategies */ public default <A> TraversalSource withSack(final A initialValue) { final TraversalSource clone = this.clone(); clone.getStrategies().addStrategies(SackStrategy.<A>build().initialValue(new ConstantSupplier<>(initialValue)).create()); clone.getBytecode().addSource(TraversalSource.Symbols.withSack, initialValue); return clone; }
/** * Add a sack to be used throughout the life of a spawned {@link Traversal}. * This adds a {@link org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SackStrategy} to the strategies. * * @param initialValue a supplier that produces the initial value of the sideEffect * @param splitOperator the sack split operator * @return a new traversal source with updated strategies */ public default <A> TraversalSource withSack(final Supplier<A> initialValue, final UnaryOperator<A> splitOperator) { final TraversalSource clone = this.clone(); clone.getStrategies().addStrategies(SackStrategy.<A>build().initialValue(initialValue).splitOperator(splitOperator).create()); clone.getBytecode().addSource(TraversalSource.Symbols.withSack, initialValue, splitOperator); return clone; }
/** * Add a sack to be used throughout the life of a spawned {@link Traversal}. * This adds a {@link org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SackStrategy} to the strategies. * * @param initialValue a supplier that produces the initial value of the sideEffect * @param mergeOperator the sack merge operator * @return a new traversal source with updated strategies */ public default <A> TraversalSource withSack(final Supplier<A> initialValue, final BinaryOperator<A> mergeOperator) { final TraversalSource clone = this.clone(); clone.getStrategies().addStrategies(SackStrategy.<A>build().initialValue(initialValue).mergeOperator(mergeOperator).create()); clone.getBytecode().addSource(TraversalSource.Symbols.withSack, initialValue, mergeOperator); return clone; }
/** * Add a sack to be used throughout the life of a spawned {@link Traversal}. * This adds a {@link org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SackStrategy} to the strategies. * * @param initialValue the initial value of the sideEffect * @param mergeOperator the sack merge operator * @return a new traversal source with updated strategies */ public default <A> TraversalSource withSack(final A initialValue, final BinaryOperator<A> mergeOperator) { final TraversalSource clone = this.clone(); clone.getStrategies().addStrategies(SackStrategy.<A>build().initialValue(new ConstantSupplier<>(initialValue)).mergeOperator(mergeOperator).create()); clone.getBytecode().addSource(TraversalSource.Symbols.withSack, initialValue, mergeOperator); return clone; }
/** * Add a sack to be used throughout the life of a spawned {@link Traversal}. * This adds a {@link org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SackStrategy} to the strategies. * * @param initialValue the initial value of the sideEffect * @param splitOperator the sack split operator * @return a new traversal source with updated strategies */ public default <A> TraversalSource withSack(final A initialValue, final UnaryOperator<A> splitOperator) { final TraversalSource clone = this.clone(); clone.getStrategies().addStrategies(SackStrategy.<A>build().initialValue(new ConstantSupplier<>(initialValue)).splitOperator(splitOperator).create()); clone.getBytecode().addSource(TraversalSource.Symbols.withSack, initialValue, splitOperator); return clone; }
/** * Add a sack to be used throughout the life of a spawned {@link Traversal}. * This adds a {@link org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SackStrategy} to the strategies. * * @param initialValue a supplier that produces the initial value of the sideEffect * @param splitOperator the sack split operator * @param mergeOperator the sack merge operator * @return a new traversal source with updated strategies */ public default <A> TraversalSource withSack(final Supplier<A> initialValue, final UnaryOperator<A> splitOperator, final BinaryOperator<A> mergeOperator) { final TraversalSource clone = this.clone(); clone.getStrategies().addStrategies(SackStrategy.<A>build().initialValue(initialValue).splitOperator(splitOperator).mergeOperator(mergeOperator).create()); clone.getBytecode().addSource(TraversalSource.Symbols.withSack, initialValue, splitOperator, mergeOperator); return clone; }
/** * Add a sack to be used throughout the life of a spawned {@link Traversal}. * This adds a {@link org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SackStrategy} to the strategies. * * @param initialValue the initial value of the sideEffect * @param splitOperator the sack split operator * @param mergeOperator the sack merge operator * @return a new traversal source with updated strategies */ public default <A> TraversalSource withSack(final A initialValue, final UnaryOperator<A> splitOperator, final BinaryOperator<A> mergeOperator) { final TraversalSource clone = this.clone(); clone.getStrategies().addStrategies(SackStrategy.<A>build().initialValue(new ConstantSupplier<>(initialValue)).splitOperator(splitOperator).mergeOperator(mergeOperator).create()); clone.getBytecode().addSource(TraversalSource.Symbols.withSack, initialValue, splitOperator, mergeOperator); return clone; }
public Builder traversal(Traversal.Admin<?, ?> traversal) { // this is necessary if the job was submitted via TraversalVertexProgram.build() instead of TraversalVertexProgramStep. if (!(traversal.getParent() instanceof TraversalVertexProgramStep)) { final MemoryTraversalSideEffects memoryTraversalSideEffects = new MemoryTraversalSideEffects(traversal.getSideEffects()); final Traversal.Admin<?, ?> parentTraversal = new DefaultTraversal<>(); traversal.getGraph().ifPresent(parentTraversal::setGraph); final TraversalStrategies strategies = traversal.getStrategies().clone(); strategies.addStrategies(ComputerFinalizationStrategy.instance(), ComputerVerificationStrategy.instance(), new VertexProgramStrategy(Computer.compute())); parentTraversal.setStrategies(strategies); traversal.setStrategies(strategies); parentTraversal.setSideEffects(memoryTraversalSideEffects); parentTraversal.addStep(new TraversalVertexProgramStep(parentTraversal, traversal)); traversal = ((TraversalVertexProgramStep) parentTraversal.getStartStep()).getGlobalChildren().get(0); traversal.setSideEffects(memoryTraversalSideEffects); } PureTraversal.storeState(this.configuration, TRAVERSAL, traversal); return this; } }
public GraphTraversalSource(final RemoteConnection connection) { this(EmptyGraph.instance(), TraversalStrategies.GlobalCache.getStrategies(EmptyGraph.class).clone()); this.connection = connection; this.strategies.addStrategies(new RemoteStrategy(connection)); }
public TraversalExplanation(final Traversal.Admin<?, ?> traversal) { this.traversal = traversal.clone(); TraversalStrategies mutatingStrategies = new DefaultTraversalStrategies(); for (final TraversalStrategy strategy : this.traversal.getStrategies().toList()) { final Traversal.Admin<?, ?> mutatingTraversal = this.traversal.clone(); mutatingStrategies.addStrategies(strategy); mutatingTraversal.setStrategies(mutatingStrategies); mutatingTraversal.applyStrategies(); this.strategyTraversals.add(Pair.with(strategy, mutatingTraversal)); } }