public static <NodeType extends ZyGraphNode<?>> void invertSelection(
      final AbstractZyGraph<NodeType, ?> graph) {
    final ArrayList<NodeType> toSelect = new ArrayList<NodeType>();
    final ArrayList<NodeType> toUnselect = new ArrayList<NodeType>();

    graph.iterate(
        new INodeCallback<NodeType>() {
          @Override
          public IterationMode next(final NodeType node) {
            if (node.isSelected()) {
              toUnselect.add(node);
            } else {
              toSelect.add(node);
            }

            return IterationMode.CONTINUE;
          }
        });

    graph.selectNodes(toSelect, toUnselect);
  }
Inverts the selected nodes of a graph.

@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/functions/SelectionFunctions.java