public static <NodeType extends IGraphNode<NodeType> & ISelectableNode> void shrinkSelectionDown(
      final ISelectableGraph<NodeType> graph) {
    final ArrayList<NodeType> deselect = new ArrayList<NodeType>();

    graph.iterateSelected(
        new INodeCallback<NodeType>() {
          @Override
          public IterationMode next(final NodeType node) {
            // Nodes without incoming edges into the subgraph formed by the selected nodes
            // are unselected. Those are just the nodes which have no selected parents.

            if (areAllParentsDeselected(node)) {
              if (!deselect.contains(node)) {
                deselect.add(node);
              }
            }

            return IterationMode.CONTINUE;
          }
        });

    graph.selectNodes(deselect, false);
  }
Shrinks the current selection down. This means that all selected nodes without incoming edges
are unselected.

@param <NodeType> The type of the nodes in the graph.
@param graph The graph in question.
java/zylib/src/main/java/com/google/security/zynamics/zylib/gui/zygraph/helpers/GraphHelpers.java