Skip to content

Commit

Permalink
Fix code smell: duplication
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas ADAM <tadam@silicom.fr>
  • Loading branch information
tadam50 committed Jul 25, 2023
1 parent eb6ec4c commit 9df67bc
Showing 1 changed file with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,8 @@ public Map<VoltageLevelRawBuilder, FeederNode> createLine(String id,
List<VoltageLevelRawBuilder> vls,
List<Integer> orders,
List<Direction> 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);
Expand Down Expand Up @@ -89,15 +82,8 @@ public Map<VoltageLevelRawBuilder, FeederNode> createFeeder2WT(String id,
List<VoltageLevelRawBuilder> vls,
List<Integer> orders,
List<Direction> 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);
Expand Down Expand Up @@ -129,15 +115,8 @@ public Map<VoltageLevelRawBuilder, FeederNode> createFeeder3WT(String id,
List<VoltageLevelRawBuilder> vls,
List<Integer> orders,
List<Direction> 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);
Expand Down Expand Up @@ -169,4 +148,19 @@ public Map<VoltageLevelRawBuilder, FeederNode> createFeeder3WT(String id,
public Map<VoltageLevelRawBuilder, FeederNode> 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<VoltageLevelRawBuilder> vls,
List<Integer> orders,
List<Direction> directions) {
if (vls.size() != expectedSize) {
throw new IllegalArgumentException(String.format(REQUIRED_N_VOLTAGELEVEL_RAW_BUILDER, Math.abs(3 - vls.size())));
}
if (orders.size() != expectedSize) {
throw new IllegalArgumentException(String.format(REQUIRED_N_ORDER, Math.abs(3 - orders.size())));
}
if (directions.size() != expectedSize) {
throw new IllegalArgumentException(String.format(REQUIRED_N_DIRECTION, Math.abs(3 - directions.size())));
}
}
}

0 comments on commit 9df67bc

Please sign in to comment.