Skip to content

Commit

Permalink
ThreeSides to integer conversion helper in enum (#2721)
Browse files Browse the repository at this point in the history
Signed-off-by: Bertrand Rix <bertrand.rix@artelys.com>
(cherry picked from commit 8b73f84)
  • Loading branch information
obrix authored and olperr1 committed Sep 28, 2023
1 parent 0839ea9 commit 68dcfb4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,32 @@
*/
package com.powsybl.iidm.network;

import com.powsybl.commons.PowsyblException;

/*
@author Bertrand Rix <bertrand.rix at artelys.com>
*/
public enum ThreeSides {
ONE,
TWO,
THREE
ONE(1),
TWO(2),
THREE(3);

private final int num;

ThreeSides(int num) {
this.num = num;
}

public int getNum() {
return num;
}

public static ThreeSides valueOf(int num) {
return switch (num) {
case 1 -> ONE;
case 2 -> TWO;
case 3 -> THREE;
default -> throw new PowsyblException("Cannot convert integer value " + num + " to ThreeSides.");
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.powsybl.iidm.network.tck;

import com.google.common.collect.Iterables;
import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.PhaseTapChanger.RegulationMode;
import com.powsybl.iidm.network.ThreeWindingsTransformer.Leg;
Expand Down Expand Up @@ -987,6 +988,19 @@ public void validLeg3Arguments() {
createThreeWindingsTransformerWithLeg3(1.3, 2.3, 3.3, 4.3, 5.3);
}

@Test
public void threeSidesTest() {
assertEquals(ThreeSides.ONE, ThreeSides.valueOf(1));
assertEquals(ThreeSides.TWO, ThreeSides.valueOf(2));
assertEquals(ThreeSides.THREE, ThreeSides.valueOf(3));

assertEquals(1, ThreeSides.ONE.getNum());
assertEquals(2, ThreeSides.TWO.getNum());
assertEquals(3, ThreeSides.THREE.getNum());

assertThrows(PowsyblException.class, () -> ThreeSides.valueOf(4));
}

private void createThreeWindingsTransformerWithLeg3(double r, double x, double g, double b, double ratedU) {
substation.newThreeWindingsTransformer()
.setId("twt")
Expand Down

0 comments on commit 68dcfb4

Please sign in to comment.