/** * Throw a {@link com.powsybl.commons.PowsyblException} if this substation contains at least one {@link Branch} or * one {@link ThreeWindingsTransformer} or one {@link HvdcConverterStation} linked to a voltage level outside this * substation. */ static void checkRemovability(Substation substation) { for (VoltageLevel vl : substation.getVoltageLevels()) { for (Connectable connectable : vl.getConnectables()) { if (connectable instanceof Branch) { checkRemovability(substation, (Branch) connectable); } else if (connectable instanceof ThreeWindingsTransformer) { checkRemovability(substation, (ThreeWindingsTransformer) connectable); } else if (connectable instanceof HvdcConverterStation) { checkRemovability(substation, (HvdcConverterStation) connectable); } } } }
@Override public void remove() { Substations.checkRemovability(this); Set<VoltageLevelExt> vls = new HashSet<>(voltageLevels); for (VoltageLevelExt vl : vls) { // Remove all branches, transformers and HVDC lines List<Connectable> connectables = Lists.newArrayList(vl.getConnectables()); for (Connectable connectable : connectables) { ConnectableType type = connectable.getType(); if (VoltageLevels.MULTIPLE_TERMINALS_CONNECTABLE_TYPES.contains(type)) { connectable.remove(); } else if (type == ConnectableType.HVDC_CONVERTER_STATION) { HvdcLine hvdcLine = getNetwork().getHvdcLine((HvdcConverterStation) connectable); if (hvdcLine != null) { hvdcLine.remove(); } } } // Then remove the voltage level (bus, switches and injections) from the network vl.remove(); } // Remove this substation from the network getNetwork().getObjectStore().remove(this); getNetwork().getListeners().notifyRemoval(this); }