Example #1
0
  public Node DFS() {
    boolean found;
    Math math;
    int tmp;
    math = new Math();
    found = false;
    currVal = 0;
    while (!found) {
      System.out.println(currNode.getId());
      if (math.equal(currNode.getVal(), value)) {
        found = true;
      } else {
      }

      if (!found && math.equal(currVal, currNode.getNumChilds())) {
        if (stack.isEmpty()) {
          found = true;
        } else {
          currNode = currNode.getParent();
          currVal = stack.pop();
        }
      } else if (!found) {
        tmp = currNode.getNode(currVal).setParent(currNode);
        currNode = currNode.getNode(currVal);

        currVal = currVal + 1;
        tmp = stack.push(currVal);
        currVal = 0;
      } else {
      }
    }

    return currNode;
  }
Example #2
0
 private Node getVariableNode() {
   Node rootNode = getEnvelopeNode();
   if (rootNode == null) return null;
   if (rootNode.hasNodes() == false) return null;
   Node propNode = rootNode.getNode(0);
   if (propNode.hasNodes() == false) return null;
   return propNode.getNode(0);
 }
Example #3
0
 /** {@inheritDoc} */
 public Node getNode(int index) {
   if (index == 0) {
     return this;
   }
   int leftNodes = left.countNodes();
   if (index <= leftNodes) {
     return left.getNode(index - 1);
   } else {
     return right.getNode(index - leftNodes - 1);
   }
 }
Example #4
0
  @Override
  public double getDistance(Node from, Node to) {
    Point pFrom = (Point) from.getNode();
    Point pTo = (Point) to.getNode();

    if (pTo.x - pFrom.x == 0 && pTo.y - pFrom.y == 0) return 0;

    if (pTo.x - pFrom.x == 0 || pTo.y - pFrom.y == 0) return 10;

    return 15;
  }
Example #5
0
 // Thanks for Giordano Sassaroli <*****@*****.**> (09/08/03)
 public PropertyList getPropertyList() {
   PropertyList properties = new PropertyList();
   Node varSetNode = getEnvelopeNode();
   // I2P change: ParserException caught in getRootNode() causes
   // getEnvelopeNode() to return null
   if (varSetNode == null) return properties;
   for (int i = 0; i < varSetNode.getNNodes(); i++) {
     Node propNode = varSetNode.getNode(i);
     if (propNode == null) continue;
     Property prop = getProperty(propNode.getNode(0));
     properties.add(prop);
   }
   return properties;
 }
 private Move getNextMove() {
   if (moveNo == 0) {
     moveNo++;
     return actual.getMove();
   }
   Move move = null;
   if (null != actual.getNode(0)) {
     Node nextNode = actual.getNode(0);
     actual = nextNode;
     move = actual.getMove();
     moveNo++;
   }
   return move;
 }
  private void doInitialCheckin() throws RepositoryException {

    Node rootNode = session.getRootNode();

    Node frontPage = rootNode.getNode("wiki/frontPage");

    if (frontPage.isCheckedOut()) {
      frontPage.checkin();
    }
  }
Example #8
0
  /**
   * adjoin operation on trees
   *
   * @param adj the tree to adjoin in target tree
   * @return success as true, if adjoin was successfull
   */
  public boolean adjoin(Node adj) {

    boolean success = false;

    if (adj.parent == null) { // check that adj is the root node

      Node adjFoot = adj.getNode(adj.data, true); // find foot node of adjoining tree

      if (adjFoot.getData().equals(adj.getData())) { // check that adj is an possible adjoining tree

        Node partialTreeRoot =
            this.getNode(
                adj.getData(), false); // save partial tree which gets separated through adjoin

        if (partialTreeRoot.data.equals(
            adj.getData())) { // check that there is an appropriate node in tree

          Node mainTreeLeaf = partialTreeRoot.parent; // save leaf of main tree on which to adjoin

          adjFoot.leftChild =
              partialTreeRoot.leftChild; // parse partial tree to foot of adjoining tree
          adjFoot.rightChild = partialTreeRoot.rightChild;
          adjFoot.foot = false; // remove the foot tag

          if (mainTreeLeaf.leftChild.data.equals(
              adj.data)) { // find out if tree has to be adjoined on left child

            mainTreeLeaf.leftChild = adj;

          } else if (mainTreeLeaf.rightChild.data.equals(adj.data)) { // or right child

            mainTreeLeaf.rightChild = adj;
          }

          success = true;
        }
      }

    } else { // if it wasn't the root

      success = this.adjoin(adj.parent); // search for it recursively
    }

    return success;
  }
 private JCRNodeWrapper dereference(JCRNodeWrapper parent, String refPath)
     throws RepositoryException {
   JCRStoreProvider provider = parent.getProvider();
   JCRNodeWrapper wrapper;
   Node referencedNode = parent.getRealNode().getProperty("j:node").getNode();
   String fullPath = parent.getPath() + DEREF_SEPARATOR + refPath;
   if (parent.getPath().startsWith(referencedNode.getPath())) {
     throw new PathNotFoundException(fullPath);
   }
   String refRootName = StringUtils.substringBefore(refPath, "/");
   if (!referencedNode.getName().equals(refRootName)) {
     throw new PathNotFoundException(fullPath);
   }
   refPath = StringUtils.substringAfter(refPath, "/");
   if (refPath.equals("")) {
     wrapper = provider.getNodeWrapper(referencedNode, fullPath, parent, this);
   } else {
     Node node = referencedNode.getNode(refPath);
     wrapper = provider.getNodeWrapper(node, fullPath, null, this);
   }
   sessionCacheByPath.put(fullPath, wrapper);
   return wrapper;
 }