void () { Set<Pair<Node, Node>> edges = new HashSet<>(); for (Node node : myGraph.getNodes()) { Iterator<Node> inIt = myGraph.getIn(node); while (inIt.hasNext()) { Node inNode = inIt.next(); if (!edges.add(new Pair<>(inNode, node))) { // Duplicate edge continue; } myOuts.computeIfAbsent(inNode, __ -> new ArrayList<>()).add(node); } } }