Ejemplo n.º 1
0
  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();
  }
Ejemplo n.º 2
0
  /**
   * This method is used when the TransposePathElement is used on the LFH as data.
   *
   * <p>Aka, normal "evaluate" returns either a Number or a String.
   *
   * @param walkedPath WalkedPath to evaluate against
   * @return The data specified by this TransposePathElement.
   */
  public Optional<Object> objectEvaluate(WalkedPath walkedPath) {
    // Grap the data we need from however far up the tree we are supposed to go
    PathStep pathStep = walkedPath.elementFromEnd(upLevel);

    if (pathStep == null) {
      return Optional.empty();
    }

    Object treeRef = pathStep.getTreeRef();

    // Now walk down from that level using the subPathReader
    if (subPathReader == null) {
      return Optional.of(treeRef);
    } else {
      return subPathReader.read(treeRef, walkedPath);
    }
  }