List of usage examples for java.util.concurrent CompletableFuture thenApply
public <U> CompletableFuture<U> thenApply(Function<? super T, ? extends U> fn)
From source file:ru.histone.v2.evaluator.Evaluator.java
private CompletableFuture<EvalNode> processBorNode(ExpAstNode node, Context context) { CompletableFuture<List<EvalNode>> leftRightDone = evalAllNodesOfCurrent(node, context); return leftRightDone.thenApply(f -> new BooleanEvalNode(nodeAsBoolean(f.get(0)) | nodeAsBoolean(f.get(1)))); }
From source file:ru.histone.v2.evaluator.Evaluator.java
private CompletableFuture<EvalNode> processBxorNode(ExpAstNode node, Context context) { CompletableFuture<List<EvalNode>> leftRightDone = evalAllNodesOfCurrent(node, context); return leftRightDone.thenApply(f -> new BooleanEvalNode(nodeAsBoolean(f.get(0)) ^ nodeAsBoolean(f.get(1)))); }
From source file:ru.histone.v2.evaluator.Evaluator.java
private CompletableFuture<EvalNode> processBandNode(ExpAstNode node, Context context) { CompletableFuture<List<EvalNode>> leftRightDone = evalAllNodesOfCurrent(node, context); return leftRightDone.thenApply(f -> new BooleanEvalNode(nodeAsBoolean(f.get(0)) & nodeAsBoolean(f.get(1)))); }
From source file:ru.histone.v2.evaluator.Evaluator.java
private CompletableFuture<EvalNode> processVarNode(ExpAstNode node, Context context) { CompletableFuture<EvalNode> valueNameFuture = evaluateNode(node.getNode(1), context); CompletableFuture<EvalNode> valueNodeFuture = evaluateNode(node.getNode(0), context); CompletableFuture<List<EvalNode>> leftRightDone = sequence(valueNameFuture); return leftRightDone.thenApply(f -> { context.put(f.get(0).getValue() + "", valueNodeFuture); return EmptyEvalNode.INSTANCE; });/*from w ww .ja va 2 s . c o m*/ }
From source file:ru.histone.v2.evaluator.Evaluator.java
private CompletableFuture<EvalNode> processArrayNode(ExpAstNode node, Context context) { if (CollectionUtils.isEmpty(node.getNodes())) { return CompletableFuture.completedFuture(new MapEvalNode(Collections.emptyMap())); }//from ww w . j ava 2 s.c o m if (node.getNode(0).getType() == AstType.AST_VAR) { return evalAllNodesOfCurrent(node, context).thenApply(evalNodes -> EmptyEvalNode.INSTANCE); } else { if (node.size() > 0) { CompletableFuture<List<EvalNode>> futures = evalAllNodesOfCurrent(node, context); return futures.thenApply(nodes -> { Map<String, Object> map = new LinkedHashMap<>(); for (int i = 0; i < nodes.size() / 2; i++) { EvalNode key = nodes.get(i * 2); EvalNode value = nodes.get(i * 2 + 1); map.put(key.getValue() + "", value.getValue()); } return new MapEvalNode(map); }); } else { return CompletableFuture.completedFuture(new MapEvalNode(new LinkedHashMap<>())); } } }
From source file:ru.histone.v2.evaluator.Evaluator.java
private CompletableFuture<EvalNode> processUnaryMinus(ExpAstNode node, Context context) { CompletableFuture<EvalNode> res = evaluateNode(node.getNode(0), context); return res.thenApply(n -> { if (n instanceof LongEvalNode) { Long value = ((LongEvalNode) n).getValue(); return new LongEvalNode(-value); } else if (n instanceof FloatEvalNode) { Float value = ((FloatEvalNode) n).getValue(); return new FloatEvalNode(-value); }/*w w w . ja va 2 s.c o m*/ throw new NotImplementedException(); }); }
From source file:ru.histone.v2.evaluator.Evaluator.java
private CompletableFuture<EvalNode> processOrNode(ExpAstNode node, Context context) { CompletableFuture<List<EvalNode>> leftRightDone = evalAllNodesOfCurrent(node, context); return leftRightDone .thenApply(f -> new BooleanEvalNode(nodeAsBoolean(f.get(0)) || nodeAsBoolean(f.get(1)))); }
From source file:ru.histone.v2.evaluator.Evaluator.java
private CompletableFuture<EvalNode> processAndNode(ExpAstNode node, Context context) { CompletableFuture<List<EvalNode>> leftRightDone = evalAllNodesOfCurrent(node, context); return leftRightDone .thenApply(f -> new BooleanEvalNode(nodeAsBoolean(f.get(0)) && nodeAsBoolean(f.get(1)))); }
From source file:ru.histone.v2.evaluator.Evaluator.java
private CompletableFuture<EvalNode> processEqNode(ExpAstNode node, Context context, boolean isEquals) { CompletableFuture<List<EvalNode>> leftRightDone = evalAllNodesOfCurrent(node, context); return leftRightDone.thenApply(f -> { EvalNode left = f.get(0);/*from ww w .j a v a 2s . c o m*/ EvalNode right = f.get(1); return new BooleanEvalNode(isEquals == equalityNode(left, right)); }); }