class ContingencyTopologyTraverser {

    static void traverse(Terminal terminal, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect) {
        Objects.requireNonNull(terminal);
        Objects.requireNonNull(switchesToOpen);
        Objects.requireNonNull(terminalsToDisconnect);

        terminal.traverse(new VoltageLevel.TopologyTraverser() {
            @Override
            public boolean traverse(Terminal terminal, boolean connected) {
                if (terminal.getVoltageLevel().getTopologyKind() == TopologyKind.BUS_BREAKER) {
                    // we have no idea what kind of switch it was in the initial node/breaker topology
                    // so to keep things simple we do not propagate the fault
                    if (connected) {
                        terminalsToDisconnect.add(terminal);
                    }
                    return false;
                }
                // in node/breaker topology propagation is decided only based on switch position
                return true;
            }

            @Override
            public boolean traverse(Switch aSwitch) {
                boolean traverse = false;

                if (isOpenable(aSwitch)) {
                    switchesToOpen.add(aSwitch);
                } else if (!aSwitch.isOpen()) {
                    traverse = true;
                }

                return traverse;
            }
        });
    }

    private  ContingencyTopologyTraverser();

}