class ParboiledAutoComplete {

  static Optional<PathElement> findFirstMatchingPathElement(
      PotentialMatch pm, int anchorIndex, Anchor.Type anchorType) {
    return IntStream.range(0, anchorIndex)
        .mapToObj(i -> pm.getPath().get(anchorIndex - i - 1))
        .filter(pe -> pe.getAnchorType() == anchorType)
        .findFirst();
  }

    ParboiledAutoComplete(
      CommonParser parser,
      Grammar grammar,
      Map<String, Anchor.Type> completionTypes,
      String network,
      String snapshot,
      String query,
      int maxSuggestions,
      CompletionMetadata completionMetadata,
      NodeRolesData nodeRolesData,
      ReferenceLibrary referenceLibrary);
    ParboiledAutoComplete(
      Grammar grammar,
      Rule inputRule,
      Map<String, Anchor.Type> completionTypes,
      String network,
      String snapshot,
      String query,
      int maxSuggestions,
      CompletionMetadata completionMetadata,
      NodeRolesData nodeRolesData,
      ReferenceLibrary referenceLibrary);

}