diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/builders/AbstractRawBuilder.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/builders/AbstractRawBuilder.java index aab0e4557..6b57e2237 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/builders/AbstractRawBuilder.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/builders/AbstractRawBuilder.java @@ -27,11 +27,11 @@ public abstract class AbstractRawBuilder implements BaseRawBuilder { protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractRawBuilder.class); - private static final String REQUIRED_N_VOLTAGELEVEL_RAW_BUILDER = "Require 3 VoltageLevelRawBuilder (found %d)"; + private static final String REQUIRED_N_VOLTAGELEVEL_RAW_BUILDER = "Expected '%d' VoltageLevelRawBuilders but only '%d' found"; - private static final String REQUIRED_N_ORDER = "Require 3 node order (found %d)"; + private static final String REQUIRED_N_ORDER = "Expected '%d' node orders but only '%d' found"; - private static final String REQUIRED_N_DIRECTION = "Require 3 node direction (found %d)"; + private static final String REQUIRED_N_DIRECTION = "Expected '%d' node directions but only '%d' found"; protected abstract BaseGraph getGraph(); @@ -48,15 +48,8 @@ public Map createLine(String id, List vls, List orders, List directions) { - if (vls.size() != 2) { - throw new IllegalArgumentException(String.format(REQUIRED_N_VOLTAGELEVEL_RAW_BUILDER, Math.abs(3 - vls.size()))); - } - if (orders.size() != 2) { - throw new IllegalArgumentException(String.format(REQUIRED_N_ORDER, Math.abs(3 - orders.size()))); - } - if (directions.size() != 2) { - throw new IllegalArgumentException(String.format(REQUIRED_N_DIRECTION, Math.abs(3 - directions.size()))); - } + checkInputParameters(2, vls, orders, directions); + VoltageLevelRawBuilder vl1 = vls.get(0); VoltageLevelRawBuilder vl2 = vls.get(1); int order1 = orders.get(0); @@ -70,10 +63,10 @@ public Map createLine(String id, feederLineNodes.put(vl2, feederLineNode2); if (containsVoltageLevelRawBuilders(vl1, vl2)) { - // All VoltageLevel must be in the same Substation + // All VoltageLevel must be in the same Substation or the same Zone getGraph().addLineEdge(id, feederLineNode1, feederLineNode2); } else { - // At least one VoltageLevel is not in the same Substation (Zone graph case) + // Using SubstationRawBuilder in place of ZoneRawBuilder manageErrorCase(Stream.of(vl1, vl2)); } return feederLineNodes; @@ -89,15 +82,8 @@ public Map createFeeder2WT(String id, List vls, List orders, List directions) { - if (vls.size() != 2) { - throw new IllegalArgumentException(String.format(REQUIRED_N_VOLTAGELEVEL_RAW_BUILDER, Math.abs(3 - vls.size()))); - } - if (orders.size() != 2) { - throw new IllegalArgumentException(String.format(REQUIRED_N_ORDER, Math.abs(3 - orders.size()))); - } - if (directions.size() != 2) { - throw new IllegalArgumentException(String.format(REQUIRED_N_DIRECTION, Math.abs(3 - directions.size()))); - } + checkInputParameters(2, vls, orders, directions); + VoltageLevelRawBuilder vl1 = vls.get(0); VoltageLevelRawBuilder vl2 = vls.get(1); int order1 = orders.get(0); @@ -110,10 +96,10 @@ public Map createFeeder2WT(String id, f2WTNodes.put(vl1, feeder2WtNode1); f2WTNodes.put(vl2, feeder2WTNode2); if (containsVoltageLevelRawBuilders(vl1, vl2)) { - // All VoltageLevel must be in the same Substation + // All VoltageLevel must be in the same Substation or the same Zone NodeFactory.createMiddle2WTNode(getGraph(), id, id, feeder2WtNode1, feeder2WTNode2, vl1.getVoltageLevelInfos(), vl2.getVoltageLevelInfos(), false); } else { - // At least one VoltageLevel is not in the same Substation (Zone graph case) + // Using SubstationRawBuilder in place of ZoneRawBuilder manageErrorCase(Stream.of(vl1, vl2)); } return f2WTNodes; @@ -129,15 +115,8 @@ public Map createFeeder3WT(String id, List vls, List orders, List directions) { - if (vls.size() != 3) { - throw new IllegalArgumentException(String.format(REQUIRED_N_VOLTAGELEVEL_RAW_BUILDER, Math.abs(3 - vls.size()))); - } - if (orders.size() != 3) { - throw new IllegalArgumentException(String.format(REQUIRED_N_ORDER, Math.abs(3 - orders.size()))); - } - if (directions.size() != 3) { - throw new IllegalArgumentException(String.format(REQUIRED_N_DIRECTION, Math.abs(3 - directions.size()))); - } + checkInputParameters(3, vls, orders, directions); + VoltageLevelRawBuilder vl1 = vls.get(0); VoltageLevelRawBuilder vl2 = vls.get(1); VoltageLevelRawBuilder vl3 = vls.get(2); @@ -156,10 +135,11 @@ public Map createFeeder3WT(String id, f3WTNodes.put(vl3, feeder3WTNode3); if (containsVoltageLevelRawBuilders(vl1, vl2, vl3)) { - // All VoltageLevel must be in the same Substation + // All VoltageLevel must be in the same Substation or the same Zone // creation of the middle node and the edges linking the transformer leg nodes to this middle node NodeFactory.createMiddle3WTNode(getGraph(), id, id, feeder3WTNode1, feeder3WTNode2, feeder3WTNode3); } else { + // Using SubstationRawBuilder in place of ZoneRawBuilder manageErrorCase(Stream.of(vl1, vl2, vl3)); } return f3WTNodes; @@ -169,4 +149,19 @@ public Map createFeeder3WT(String id, public Map createFeeder3WT(String id, VoltageLevelRawBuilder vl1, VoltageLevelRawBuilder vl2, VoltageLevelRawBuilder vl3) { return createFeeder3WT(id, List.of(vl1, vl2, vl3), List.of(0, 0, 0), Stream.of((Direction) null, null, null).toList()); } + + private void checkInputParameters(int expectedSize, + List vls, + List orders, + List directions) { + if (vls.size() != expectedSize) { + throw new IllegalArgumentException(String.format(REQUIRED_N_VOLTAGELEVEL_RAW_BUILDER, expectedSize, Math.abs(expectedSize - vls.size()))); + } + if (orders.size() != expectedSize) { + throw new IllegalArgumentException(String.format(REQUIRED_N_ORDER, expectedSize, Math.abs(expectedSize - orders.size()))); + } + if (directions.size() != expectedSize) { + throw new IllegalArgumentException(String.format(REQUIRED_N_DIRECTION, expectedSize, Math.abs(expectedSize - directions.size()))); + } + } }