private static <NodeType extends ZyGraphNode<?>> int internalFilterNodes(
      final Collection<NodeType> nodes,
      final Criterion filterBy,
      final Collection<NodeType> resultSet) {
    checkNotNull(filterBy);

    int count = 0;
    boolean addToResult;
    for (final NodeType node : nodes) {
      switch (filterBy) {
        case VISIBLE:
          addToResult = node.isVisible();
          break;
        case INVISIBLE:
          addToResult = !node.isVisible();
          break;
        case SELECTED:
          addToResult = node.isSelected();
          break;
        case SELECTED_VISIBLE:
          addToResult = node.isSelected() && node.isVisible();
          break;
        case UNSELECTED_VISIBLE:
          addToResult = !node.isSelected() && node.isVisible();
          break;
        default:
          // Should not happen
          throw new IllegalArgumentException("Invalid node filter criterion");
      }
      if (addToResult) {
        count++;
        if (resultSet != null) {
          resultSet.add(node);
        }
      }
    }
    return count;
  }
Filter the nodes from a list that match a given filter criterion.

@param nodes a {@code Collection} containing the nodes to be filtered
@param filterBy the criterion to filter by
@param resultSet a {@code Collection} of nodes that match the specified criterion. If {@code
    null}, this method only counts the matching nodes.
@return The number of nodes in the graph matching the filter criterion
java/ui/src/main/java/com/google/security/zynamics/bindiff/graph/filter/GraphNodeFilter.java