@Override public String evaluate(WalkedPath walkedPath) { Optional dataFromTranspose = objectEvaluate(walkedPath); if (dataFromTranspose.isPresent()) { Object data = dataFromTranspose.get(); // Coerce a number into a String if (data instanceof Number) { // the idea here being we are looking for an array index value int val = ((Number) data).intValue(); return Integer.toString(val); } // Coerce a boolean into a String if (data instanceof Boolean) { return Boolean.toString((Boolean) data); } if (data == null || !(data instanceof String)) { // If this output path has a TransposePathElement, and when we evaluate it // it does not resolve to a String, then return null return null; } return (String) data; } else { return null; } }
public final Optional<DataType> traverse( StepType tree, Operation op, Iterator<String> keys, DataType data) { if (tree == null) { return Optional.empty(); } if (getStepType().isAssignableFrom(tree.getClass())) { String key = keys.next(); if (child == null) { // End of the Traversal so do the set or get switch (op) { case GET: return this.get(tree, key); case SET: return (Optional<DataType>) traversr.handleFinalSet(this, tree, key, data); case REMOVE: return this.remove(tree, key); default: throw new IllegalStateException("Invalid op:" + op.toString()); } } else { // We just an intermediate step, so traverse and then hand over control to our child Optional<Object> optSub = traversr.handleIntermediateGet(this, tree, key, op); if (optSub.isPresent()) { return child.traverse(optSub.get(), op, keys, data); } } } return Optional.empty(); }