private void filterCandidates(List<Candidate> candidates, Path path) {
    List<Candidate> newCandidates = new ArrayList<Candidate>(candidates.size());
    for (Candidate candidate : candidates) {
      if (candidate == null || !path.contains(candidate.node)) {
        newCandidates.add(candidate);
      }
    }
    candidates.clear();
    candidates.addAll(newCandidates);
  }