Exemplo n.º 1
0
  public PatternMatch next() {
    if (match == null) {
      match = findNextMatch();
      optionalFinder = null;
    }

    PatternMatch matchToReturn = match;
    PatternMatch optionalMatchToReturn = null;
    if (match != null && optionalNodes != null) {
      if (optionalFinder == null) {
        optionalFinder = new OptionalPatternFinder(matcher, match, optionalNodes);
      }
      if (optionalMatch == null) {
        optionalMatch = optionalFinder.findNextOptionalPatterns();
      }
      optionalMatchToReturn = optionalMatch;
      optionalMatch = null;
      if (optionalMatchToReturn == null) {
        match = null;
        if (optionalFinder.anyMatchFound()) {
          return next();
        }
      }
    } else {
      match = null;
    }
    if (matchToReturn == null) {
      throw new NoSuchElementException();
    }
    return optionalMatchToReturn != null
        ? PatternMatch.merge(matchToReturn, optionalMatchToReturn)
        : matchToReturn;
  }
Exemplo n.º 2
0
 public boolean hasNext() {
   if (match == null) {
     match = findNextMatch();
     optionalFinder = null;
   } else if (optionalNodes != null) {
     if (optionalFinder == null) {
       optionalFinder = new OptionalPatternFinder(matcher, match, optionalNodes);
     }
     if (optionalMatch == null) {
       optionalMatch = optionalFinder.findNextOptionalPatterns();
     }
     if (optionalMatch == null && optionalFinder.anyMatchFound()) {
       match = null;
       return hasNext();
     }
   }
   return match != null;
 }