public MathStep(final Traversal.Admin traversal, final String equation) { super(traversal); this.equation = equation; this.expression = new TinkerExpression(equation, MathStep.getVariables(this.equation)); }
@Override public Set<TraverserRequirement> getRequirements() { return this.getSelfAndChildRequirements(TraverserRequirement.OBJECT, TraverserRequirement.SIDE_EFFECTS); }
@Override public void modulateBy(final Traversal.Admin<?, ?> selectTraversal) { this.traversalRing.addTraversal(this.integrateChild(selectTraversal)); }
/** * Map the {@link Traverser} to a {@link Double} according to the mathematical expression provided in the argument. * * @param expression the mathematical expression with variables refering to scope variables. * @return the traversal with the {@link MathStep} added. * @since 3.3.1 */ public default GraphTraversal<S, Double> math(final String expression) { this.asAdmin().getBytecode().addStep(Symbols.math, expression); return this.asAdmin().addStep(new MathStep<>(this.asAdmin(), expression)); }
@Override protected Double map(final Traverser.Admin<S> traverser) { final Expression localExpression = new Expression(this.expression.getExpression()); for (final String var : this.expression.getVariables()) { localExpression.setVariable(var, var.equals(CURRENT) ? TraversalUtil.applyNullable(traverser, this.traversalRing.next()).doubleValue() : TraversalUtil.applyNullable((S) this.getNullableScopeValue(Pop.last, var, traverser), this.traversalRing.next()).doubleValue()); } this.traversalRing.reset(); return localExpression.evaluate(); }
/** * Map the {@link Traverser} to a {@link Double} according to the mathematical expression provided in the argument. * * @param expression the mathematical expression with variables refering to scope variables. * @return the traversal with the {@link MathStep} added. * @since 3.3.1 */ public default GraphTraversal<S, Double> math(final String expression) { this.asAdmin().getBytecode().addStep(Symbols.math, expression); return this.asAdmin().addStep(new MathStep<>(this.asAdmin(), expression)); }
@Override protected Double map(final Traverser.Admin<S> traverser) { final Expression localExpression = new Expression(this.expression.getExpression()); for (final String var : this.expression.getVariables()) { localExpression.setVariable(var, var.equals(CURRENT) ? TraversalUtil.applyNullable(traverser, this.traversalRing.next()).doubleValue() : TraversalUtil.applyNullable((S) this.getNullableScopeValue(Pop.last, var, traverser), this.traversalRing.next()).doubleValue()); } this.traversalRing.reset(); return localExpression.evaluate(); }
public static Set<String> getVariables(String equation) { return MathStep.getVariables(equation); } }
@Override public void modulateBy(final Traversal.Admin<?, ?> selectTraversal) { this.traversalRing.addTraversal(this.integrateChild(selectTraversal)); }
@Override public Set<TraverserRequirement> getRequirements() { return this.getSelfAndChildRequirements(TraverserRequirement.OBJECT, TraverserRequirement.SIDE_EFFECTS); }
public MathStep(final Traversal.Admin traversal, final String equation) { super(traversal); this.equation = equation; this.expression = new TinkerExpression(equation, MathStep.getVariables(this.equation)); }