Esempio n. 1
0
  public Object getValue() {
    if (ltree == null || rtree == null || value == null)
      throw new NotEnoughArgumentsException("TreeNode is missing arguments", this);

    Object leftVal = ltree.getValue();
    Object rightVal = rtree.getValue();

    if (leftVal instanceof StorageLeaf && rightVal instanceof StorageLeaf) {
      // make a shallow copy of the subtrees and return the newly constructed tree.
      Object valVal = value.getValue();
      StorageLeaf leftSN = (StorageLeaf) leftVal;
      StorageLeaf rightSN = (StorageLeaf) rightVal;
      return new StorageNode(leftSN.clone(), valVal, rightSN.clone());
    } else {
      throw new InvalidArgumentTypeException(
          "The left and right subtree values of a Node must be Nodes or Leafs!", this);
    }
  }
Esempio n. 2
0
 public StorageNode clone() {
   return new StorageNode(left.clone(), value, right.clone());
 }