Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThreeSides to integer conversion helper in enum #2721

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading