Ejemplo n.º 1
0
 private boolean traverse(CallPosition callPos) {
   // make everything like it was before we returned previous match
   PatternPosition currentPos = callPos.getPatternPosition();
   PatternRelationship pRel = callPos.getPatternRelationship();
   pRel.mark();
   visitedRels.remove(callPos.getLastVisitedRelationship());
   Node currentNode = currentPos.getCurrentNode();
   Iterator<Relationship> relItr = callPos.getRelationshipIterator();
   while (relItr.hasNext()) {
     Relationship rel = relItr.next();
     if (visitedRels.contains(rel)) {
       continue;
     }
     if (!checkProperties(pRel, rel)) {
       continue;
     }
     Node otherNode = rel.getOtherNode(currentNode);
     PatternNode otherPosition = pRel.getOtherNode(currentPos.getPatternNode());
     pRel.mark();
     visitedRels.add(rel);
     if (traverse(new PatternPosition(otherNode, otherPosition, pRel, rel, optional), true)) {
       callPos.setLastVisitedRelationship(rel);
       return true;
     }
     visitedRels.remove(rel);
     pRel.unMark();
   }
   pRel.unMark();
   if (callPos.shouldPopUncompleted()) {
     uncompletedPositions.pop();
   }
   callStack.pop();
   foundElements.pop();
   return false;
 }
Ejemplo n.º 2
0
  private boolean traverse(PatternPosition currentPos, boolean pushElement) {
    PatternNode pNode = currentPos.getPatternNode();
    Node currentNode = currentPos.getCurrentNode();

    if (!checkProperties(pNode, currentNode)) {
      return false;
    }

    if (pushElement) {
      foundElements.push(
          new PatternElement(
              pNode, currentPos.fromPatternRel(),
              currentNode, currentPos.fromRelationship()));
    }
    if (currentPos.hasNext()) {
      boolean popUncompleted = false;
      PatternRelationship pRel = currentPos.next();
      if (currentPos.hasNext()) {
        uncompletedPositions.push(currentPos);
        popUncompleted = true;
      }
      assert !pRel.isMarked();
      Iterator<Relationship> relItr =
          getRelationshipIterator(currentPos.getPatternNode(), currentNode, pRel);
      pRel.mark();
      while (relItr.hasNext()) {
        Relationship rel = relItr.next();
        if (visitedRels.contains(rel)) {
          continue;
        }
        if (!checkProperties(pRel, rel)) {
          continue;
        }
        Node otherNode = rel.getOtherNode(currentNode);
        PatternNode otherPosition = pRel.getOtherNode(currentPos.getPatternNode());
        visitedRels.add(rel);

        CallPosition callPos = new CallPosition(currentPos, rel, relItr, pRel, popUncompleted);
        callStack.push(callPos);
        if (traverse(new PatternPosition(otherNode, otherPosition, pRel, rel, optional), true)) {
          return true;
        }
        callStack.pop();
        visitedRels.remove(rel);
      }
      pRel.unMark();
      if (popUncompleted) {
        uncompletedPositions.pop();
      }
      foundElements.pop();
      return false;
    }
    boolean matchFound = true;
    if (!uncompletedPositions.isEmpty()) {
      PatternPosition digPos = uncompletedPositions.pop();
      digPos.reset();
      matchFound = traverse(digPos, false);
      uncompletedPositions.push(digPos);
      return matchFound;
    }
    return true;
  }