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

Fix Java17 syntax detection with maven-checkstyle-plugin #2659

Merged
merged 4 commits into from
Aug 1, 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 @@ -68,7 +68,7 @@ public void ruleChecked(RunningContext runningContext, Rule rule, RuleEvaluation
if (verbose || status == RuleEvaluationStatus.TRUE) {
out.println(" Rule '" + rule.getId() + "' evaluated to " + status);
}
if (verbose && (variables.size() + actions.size() > 0)) {
if (verbose && variables.size() + actions.size() > 0) {
Writer writer = new OutputStreamWriter(out);
try (AbstractTableFormatter formatter = new AsciiTableFormatter(writer, null,
new Column("Variable"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,23 @@ private void applyTapChangersRegulatingControl(ThreeWindingsTransformer twt,

rtcRegulating1 = checkOnlyOneEnabled(twt.getId(), rtcRegulating1, regulatingSet, "ratioTapChanger at Leg1");
setRatioTapChangerControl(rtcRegulating1, rc.ratioTapChanger1, rtcControl1, twt.getLeg1().getRatioTapChanger());
regulatingSet = regulatingSet || (twt.getLeg1().hasRatioTapChanger() && twt.getLeg1().getRatioTapChanger().isRegulating());
regulatingSet = regulatingSet
|| twt.getLeg1().hasRatioTapChanger() && twt.getLeg1().getRatioTapChanger().isRegulating();

ptcRegulating2 = checkOnlyOneEnabled(twt.getId(), ptcRegulating2, regulatingSet, "phaseTapChanger at Leg2");
setPhaseTapChangerControl(ptcRegulating2, rc.phaseTapChanger2, ptcControl2, twt.getLeg2().getPhaseTapChanger());
regulatingSet = regulatingSet || (twt.getLeg2().hasPhaseTapChanger() && twt.getLeg2().getPhaseTapChanger().isRegulating());
regulatingSet = regulatingSet
|| twt.getLeg2().hasPhaseTapChanger() && twt.getLeg2().getPhaseTapChanger().isRegulating();

rtcRegulating2 = checkOnlyOneEnabled(twt.getId(), rtcRegulating2, regulatingSet, "ratioTapChanger at Leg2");
setRatioTapChangerControl(rtcRegulating2, rc.ratioTapChanger2, rtcControl2, twt.getLeg2().getRatioTapChanger());
regulatingSet = regulatingSet || (twt.getLeg2().hasRatioTapChanger() && twt.getLeg2().getRatioTapChanger().isRegulating());
regulatingSet = regulatingSet
|| twt.getLeg2().hasRatioTapChanger() && twt.getLeg2().getRatioTapChanger().isRegulating();

ptcRegulating3 = checkOnlyOneEnabled(twt.getId(), ptcRegulating3, regulatingSet, "phaseTapChanger at Leg3");
setPhaseTapChangerControl(ptcRegulating3, rc.phaseTapChanger3, ptcControl3, twt.getLeg3().getPhaseTapChanger());
regulatingSet = regulatingSet || (twt.getLeg3().hasPhaseTapChanger() && twt.getLeg3().getPhaseTapChanger().isRegulating());
regulatingSet = regulatingSet
|| twt.getLeg3().hasPhaseTapChanger() && twt.getLeg3().getPhaseTapChanger().isRegulating();

rtcRegulating3 = checkOnlyOneEnabled(twt.getId(), rtcRegulating3, regulatingSet, "ratioTapChanger at Leg3");
setRatioTapChangerControl(rtcRegulating3, rc.ratioTapChanger3, rtcControl3, twt.getLeg3().getRatioTapChanger());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public SvInjectionConversion(PropertyBag p, Context context) {
@Override
public boolean valid() {
return voltageLevel != null
&& ((context.nodeBreaker() && node != -1)
|| (!context.nodeBreaker() && voltageLevel.getBusBreakerView().getBus(busId) != null));
&& (context.nodeBreaker() && node != -1
|| !context.nodeBreaker() && voltageLevel.getBusBreakerView().getBus(busId) != null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ private static void writeGeneratingUnitsParticitationFactors(Network network, St
}

private static GeneratingUnit generatingUnitForGeneratorAndBatteries(Injection<?> i, CgmesExportContext context) {
if (i.hasProperty(GENERATING_UNIT_PROPERTY) && ((i.getExtension(ActivePowerControl.class) != null) || i.hasProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + "normalPF"))) {
if (i.hasProperty(GENERATING_UNIT_PROPERTY) && (i.getExtension(ActivePowerControl.class) != null || i.hasProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + "normalPF"))) {
GeneratingUnit gu = new GeneratingUnit();
gu.id = context.getNamingStrategy().getCgmesIdFromProperty(i, GENERATING_UNIT_PROPERTY);
if (i.getExtension(ActivePowerControl.class) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ static boolean isConsideredForNetwork(Attr attr) {
}
if (attr.getLocalName().equals("value")) {
Element e = attr.getOwnerElement();
return !e.getLocalName().equals("property") ||
(!"CGMES.TP_ID".equals(e.getAttribute("name")) && !"CGMES.SSH_ID".equals(e.getAttribute("name")));
return !e.getLocalName().equals("property")
|| !"CGMES.TP_ID".equals(e.getAttribute("name")) && !"CGMES.SSH_ID".equals(e.getAttribute("name"));
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ public boolean isValidName(String contextName) {
EQUIPMENT_BOUNDARY("EQ_BD") {
@Override
public boolean isValidName(String contextName) {
return super.isValidName(contextName) || (EQUIPMENT.isValidName(contextName) && isBoundary(contextName));
return super.isValidName(contextName)
|| EQUIPMENT.isValidName(contextName) && isBoundary(contextName);
}
},
TOPOLOGY_BOUNDARY("TP_BD") {
@Override
public boolean isValidName(String contextName) {
return super.isValidName(contextName) || (TOPOLOGY.isValidName(contextName) && isBoundary(contextName));
return super.isValidName(contextName)
|| TOPOLOGY.isValidName(contextName) && isBoundary(contextName);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public T getExtendable() {
}

public void setExtendable(T extendable) {
if ((extendable != null) && (this.extendable != null) && (this.extendable != extendable)) {
if (extendable != null && this.extendable != null && this.extendable != extendable) {
throw new PowsyblException("Extension is already associated to the extendable " + this.extendable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ void testUnauthorizedColspan() throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (Writer writer = new OutputStreamWriter(bos, StandardCharsets.UTF_8);
AsciiTableFormatter formatter = new AsciiTableFormatter(writer, null, config,
new Column("column1").setColspan(4).setHorizontalAlignment(HorizontalAlignment.CENTER),
new Column("column2").setColspan(2).setHorizontalAlignment(HorizontalAlignment.CENTER))) {
new Column("column1").setColspan(4).setHorizontalAlignment(HorizontalAlignment.CENTER),
new Column("column2").setColspan(2).setHorizontalAlignment(HorizontalAlignment.CENTER))) {
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> formatter.writeCell("Line:1 Cell:1", 1)
.writeCell("Line:1 Cell:2", 1)
.writeCell("Line:1 Cell:3", 1)
Expand All @@ -91,8 +91,8 @@ void testEmptyLines() throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (Writer writer = new OutputStreamWriter(bos, StandardCharsets.UTF_8);
AsciiTableFormatter formatter = new AsciiTableFormatter(writer, null, config,
new Column("column1").setColspan(4),
new Column("column2").setColspan(2))) {
new Column("column1").setColspan(4),
new Column("column2").setColspan(2))) {
formatter.writeCell("Line:1 Cell:1")
.writeCell("Line:1 Cell:2")
.writeCell("Line:1 Cell:3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ private static boolean checkShuntCompensatorContingency(Contingency contingency,

private static boolean checkBranchContingency(Contingency contingency, BranchContingency element, Network network) {
Branch branch = network.getBranch(element.getId());
if (branch == null || (element.getVoltageLevelId() != null &&
!(element.getVoltageLevelId().equals(branch.getTerminal1().getVoltageLevel().getId()) ||
element.getVoltageLevelId().equals(branch.getTerminal2().getVoltageLevel().getId())))) {
if (branch == null
|| element.getVoltageLevelId() != null
&& !(element.getVoltageLevelId().equals(branch.getTerminal1().getVoltageLevel().getId())
|| element.getVoltageLevelId().equals(branch.getTerminal2().getVoltageLevel().getId()))) {
LOGGER.warn("Branch '{}' of contingency '{}' not found", element.getId(), contingency.getId());
return false;
}
Expand All @@ -188,9 +189,10 @@ private static boolean checkBranchContingency(Contingency contingency, BranchCon

private static boolean checkLineContingency(Contingency contingency, LineContingency element, Network network) {
Line line = network.getLine(element.getId());
if (line == null || (element.getVoltageLevelId() != null &&
!(element.getVoltageLevelId().equals(line.getTerminal1().getVoltageLevel().getId()) ||
element.getVoltageLevelId().equals(line.getTerminal2().getVoltageLevel().getId())))) {
if (line == null
|| element.getVoltageLevelId() != null
&& !(element.getVoltageLevelId().equals(line.getTerminal1().getVoltageLevel().getId())
|| element.getVoltageLevelId().equals(line.getTerminal2().getVoltageLevel().getId()))) {
LOGGER.warn("Line '{}' of contingency '{}' not found", element.getId(), contingency.getId());
return false;
}
Expand All @@ -199,9 +201,10 @@ private static boolean checkLineContingency(Contingency contingency, LineConting

private static boolean checkTwoWindingsTransformerContingency(Contingency contingency, TwoWindingsTransformerContingency element, Network network) {
TwoWindingsTransformer twt = network.getTwoWindingsTransformer(element.getId());
if (twt == null || (element.getVoltageLevelId() != null &&
!(element.getVoltageLevelId().equals(twt.getTerminal1().getVoltageLevel().getId()) ||
element.getVoltageLevelId().equals(twt.getTerminal2().getVoltageLevel().getId())))) {
if (twt == null
|| element.getVoltageLevelId() != null
&& !(element.getVoltageLevelId().equals(twt.getTerminal1().getVoltageLevel().getId())
|| element.getVoltageLevelId().equals(twt.getTerminal2().getVoltageLevel().getId()))) {
LOGGER.warn("TwoWindingsTransformer '{}' of contingency '{}' not found", element.getId(), contingency.getId());
return false;
}
Expand All @@ -210,9 +213,10 @@ private static boolean checkTwoWindingsTransformerContingency(Contingency contin

private static boolean checkHvdcLineContingency(Contingency contingency, HvdcLineContingency element, Network network) {
HvdcLine hvdcLine = network.getHvdcLine(element.getId());
if (hvdcLine == null || (element.getVoltageLevelId() != null &&
!(element.getVoltageLevelId().equals(hvdcLine.getConverterStation1().getTerminal().getVoltageLevel().getId()) ||
element.getVoltageLevelId().equals(hvdcLine.getConverterStation2().getTerminal().getVoltageLevel().getId())))) {
if (hvdcLine == null
|| element.getVoltageLevelId() != null
&& !(element.getVoltageLevelId().equals(hvdcLine.getConverterStation1().getTerminal().getVoltageLevel().getId())
|| element.getVoltageLevelId().equals(hvdcLine.getConverterStation2().getTerminal().getVoltageLevel().getId()))) {
LOGGER.warn("HVDC line '{}' of contingency '{}' not found", element.getId(), contingency.getId());
return false;
}
Expand Down Expand Up @@ -261,9 +265,10 @@ private static boolean checkBusContingency(Contingency contingency, BusContingen

private static boolean checkTieLineContingency(Contingency contingency, TieLineContingency element, Network network) {
TieLine tieLine = network.getTieLine(element.getId());
if (tieLine == null || (element.getVoltageLevelId() != null &&
!(element.getVoltageLevelId().equals(tieLine.getDanglingLine1().getTerminal().getVoltageLevel().getId()) ||
element.getVoltageLevelId().equals(tieLine.getDanglingLine2().getTerminal().getVoltageLevel().getId())))) {
if (tieLine == null
|| element.getVoltageLevelId() != null
&& !(element.getVoltageLevelId().equals(tieLine.getDanglingLine1().getTerminal().getVoltageLevel().getId())
|| element.getVoltageLevelId().equals(tieLine.getDanglingLine2().getTerminal().getVoltageLevel().getId()))) {
LOGGER.warn("Tie line '{}' of contingency '{}' not found", element.getId(), contingency.getId());
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ private boolean filterThreeWindingsTransformer(ThreeWindingsTransformer threeWin
return filterSubstationOrVoltageLevel(voltageLevel1) || filterSubstationOrVoltageLevel(voltageLevel2) ||
filterSubstationOrVoltageLevel(voltageLevel3);
case BOTH:
return (filterSubstationOrVoltageLevel(voltageLevel1) && filterSubstationOrVoltageLevel(voltageLevel2)) ||
(filterSubstationOrVoltageLevel(voltageLevel1) && filterSubstationOrVoltageLevel(voltageLevel3)) ||
(filterSubstationOrVoltageLevel(voltageLevel2) && filterSubstationOrVoltageLevel(voltageLevel3));
return filterSubstationOrVoltageLevel(voltageLevel1) && filterSubstationOrVoltageLevel(voltageLevel2)
|| filterSubstationOrVoltageLevel(voltageLevel1) && filterSubstationOrVoltageLevel(voltageLevel3)
|| filterSubstationOrVoltageLevel(voltageLevel2) && filterSubstationOrVoltageLevel(voltageLevel3);
case ALL_THREE:
return filterSubstationOrVoltageLevel(voltageLevel1) && filterSubstationOrVoltageLevel(voltageLevel2) &&
filterSubstationOrVoltageLevel(voltageLevel3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ private boolean filterBranch(Terminal terminal1, Terminal terminal2) {
if (countrySide1 == null && !countries1.isEmpty() || countrySide2 == null && !countries2.isEmpty()) {
return false;
}
return (countries1.isEmpty() && countries2.isEmpty()) ||
(countries1.isEmpty() && (countries2.contains(countrySide2) || countries2.contains(countrySide1))) ||
(countries2.isEmpty() && (countries1.contains(countrySide2) || countries1.contains(countrySide1))) ||
(countries1.contains(countrySide1) && countries2.contains(countrySide2)) ||
(countries1.contains(countrySide2) && countries2.contains(countrySide1));
return countries1.isEmpty() && countries2.isEmpty()
|| countries1.isEmpty() && (countries2.contains(countrySide2) || countries2.contains(countrySide1))
|| countries2.isEmpty() && (countries1.contains(countrySide2) || countries1.contains(countrySide1))
|| countries1.contains(countrySide1) && countries2.contains(countrySide2)
|| countries1.contains(countrySide2) && countries2.contains(countrySide1);
}

public List<Country> getCountries1() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import java.util.Collections;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.*;

/**
* @author Etienne Lesot <etienne.lesot@rte-france.com>
Expand Down Expand Up @@ -273,6 +272,51 @@ void testProperty() {
contingencies = contingencyList.getContingencies(fourSubstationNetwork);
assertEquals(1, contingencies.size());
assertEquals(new Contingency("GTH1", new GeneratorContingency("GTH1")), contingencies.get(0));

// three-windings transformers
Network network = ThreeWindingsTransformerNetworkFactory.create();
network.getVoltageLevel("VL_132").setProperty("property", "value1");
network.getVoltageLevel("VL_33").setProperty("property", "value2");
network.getVoltageLevel("VL_11").setProperty("property", "value3");
values = List.of("value");
propertyCriterion = new PropertyCriterion("property", values,
PropertyCriterion.EquipmentToCheck.VOLTAGE_LEVEL);
contingencyList = new ThreeWindingsTransformerCriterionContingencyList("list1", null,
null, Collections.singletonList(propertyCriterion), null);
var cl = contingencyList;
Exception e = assertThrows(IllegalArgumentException.class, () -> cl.getContingencies(network));
assertTrue(e.getMessage().contains("enum to check side can not be null for threeWindingsTransformer to check their voltage level"));

assertThreeWindingsTransformerContingencies(false, network, "value0", PropertyCriterion.SideToCheck.ONE);
assertThreeWindingsTransformerContingencies(true, network, "value1", PropertyCriterion.SideToCheck.ONE);
assertThreeWindingsTransformerContingencies(true, network, "value2", PropertyCriterion.SideToCheck.ONE);
assertThreeWindingsTransformerContingencies(true, network, "value3", PropertyCriterion.SideToCheck.ONE);
assertThreeWindingsTransformerContingencies(false, network, "value1", PropertyCriterion.SideToCheck.BOTH);
assertThreeWindingsTransformerContingencies(false, network, "value1", PropertyCriterion.SideToCheck.ALL_THREE);

network.getVoltageLevel("VL_11").setProperty("property", "value2");
assertThreeWindingsTransformerContingencies(true, network, "value2", PropertyCriterion.SideToCheck.BOTH);
assertThreeWindingsTransformerContingencies(false, network, "value2", PropertyCriterion.SideToCheck.ALL_THREE);

network.getVoltageLevel("VL_132").setProperty("property", "value2");
assertThreeWindingsTransformerContingencies(true, network, "value2", PropertyCriterion.SideToCheck.BOTH);
assertThreeWindingsTransformerContingencies(true, network, "value2", PropertyCriterion.SideToCheck.ALL_THREE);

}

private void assertThreeWindingsTransformerContingencies(boolean successExpected, Network network, String value,
PropertyCriterion.SideToCheck sideToCheck) {
PropertyCriterion propertyCriterion = new PropertyCriterion("property", List.of(value),
PropertyCriterion.EquipmentToCheck.VOLTAGE_LEVEL, sideToCheck);
ContingencyList contingencyList = new ThreeWindingsTransformerCriterionContingencyList("list1", null,
null, Collections.singletonList(propertyCriterion), null);
List<Contingency> contingencies = contingencyList.getContingencies(network);
if (successExpected) {
assertEquals(1, contingencies.size());
assertEquals(new Contingency("3WT", new ThreeWindingsTransformerContingency("3WT")), contingencies.get(0));
} else {
assertEquals(0, contingencies.size());
}
}

@Test
Expand Down
Loading