class NodeBreakerTopology {

    public static void removeIsolatedSwitches(VoltageLevel.NodeBreakerView topo) {
        Objects.requireNonNull(topo, "Node breaker topology view is null.");

        int[] nodes = topo.getNodes();
        final TIntSet encountered = new TIntHashSet();
        final Set<Switch> encounteredSwitches = new HashSet<>();

        for (int n : nodes) {
            if (encountered.contains(n) || topo.getTerminal(n) == null) {
                continue;
            }
            encountered.add(n);
            topo.traverse(n, (n1, sw, n2) -> {
                encountered.add(n2);
                encounteredSwitches.add(sw);
                return topo.getTerminal(n2) == null;
            });
        }

        List<Switch> toRemove = topo.getSwitchStream().filter(sw -> !encounteredSwitches.contains(sw)).collect(Collectors.toList());
        for (Switch sw : toRemove) {
            topo.removeSwitch(sw.getId());
        }
    }

    private  NodeBreakerTopology();

}