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

Replace AssertionError by IllegalStateException. #2465

Merged
merged 15 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -73,7 +73,9 @@ protected AbstractConductingEquipmentConversion(
// It is assumed the property bags are already sorted
this.numTerminals = ps.size();
terminals = new TerminalData[] {null, null, null};
assert numTerminals <= 3;
if (numTerminals > 3) {
throw new IllegalStateException("numTerminals should be less or equal to 3 but is " + numTerminals);
}
for (int k = 1; k <= numTerminals; k++) {
int k0 = k - 1;
terminals[k0] = new TerminalData(CgmesNames.TERMINAL, ps.get(k0), context);
Expand Down Expand Up @@ -464,7 +466,9 @@ PowerFlow powerFlowSV(int n) {
// Terminals

protected void convertedTerminals(Terminal... ts) {
assert ts.length == numTerminals;
if (ts.length != numTerminals) {
throw new IllegalStateException();
}
for (int k = 0; k < ts.length; k++) {
int n = k + 1;
Terminal t = ts[k];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public void convert() {

String iidmSubstationId = context.substationIdMapping().substationIidm(id);
Substation substation = context.network().getSubstation(iidmSubstationId);
assert substation == null;
if (substation != null) {
throw new IllegalStateException("Substation should be null");
}
SubstationAdder adder = context.network().newSubstation()
.setId(iidmSubstationId)
.setName(iidmName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -902,36 +902,42 @@ public void detach(final TerminalExt terminal) {

@Override
public boolean connect(TerminalExt terminal) {
assert terminal instanceof BusTerminal;
if (terminal instanceof BusTerminal) {
flo-dup marked this conversation as resolved.
Show resolved Hide resolved

// already connected?
if (terminal.isConnected()) {
return false;
}
// already connected?
if (terminal.isConnected()) {
return false;
}

((BusTerminal) terminal).setConnected(true);
((BusTerminal) terminal).setConnected(true);

// invalidate connected components
invalidateCache();
// invalidate connected components
invalidateCache();

return true;
return true;
} else {
throw new IllegalStateException("Given TerminalExt not supported: " + terminal.getClass().getName());
}
}

@Override
public boolean disconnect(TerminalExt terminal) {
assert terminal instanceof BusTerminal;
if (terminal instanceof BusTerminal) {

// already disconnected?
if (!terminal.isConnected()) {
return false;
}
// already disconnected?
if (!terminal.isConnected()) {
return false;
}

((BusTerminal) terminal).setConnected(false);
((BusTerminal) terminal).setConnected(false);

// invalidate connected components
invalidateCache();
// invalidate connected components
invalidateCache();

return true;
return true;
} else {
throw new IllegalStateException("Given TerminalExt not suported: " + terminal.getClass().getName());
}
}

void traverse(BusTerminal terminal, Terminal.TopologyTraverser traverser) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1160,75 +1160,82 @@ private static boolean isOpenedDisconnector(Switch s) {

@Override
public boolean connect(TerminalExt terminal) {
assert terminal instanceof NodeTerminal;
if (terminal instanceof NodeTerminal) {

// already connected?
if (terminal.isConnected()) {
return false;
}
// already connected?
if (terminal.isConnected()) {
return false;
}

int node = ((NodeTerminal) terminal).getNode();
// find all paths starting from the current terminal to a busbar section that does not contain an open disconnector
// paths are already sorted
List<TIntArrayList> paths = graph.findAllPaths(node, NodeBreakerVoltageLevel::isBusbarSection, NodeBreakerVoltageLevel::isOpenedDisconnector);
boolean connected = false;
if (!paths.isEmpty()) {
// the shorted path is the best, close all opened breakers of the path
TIntArrayList shortestPath = paths.get(0);
for (int i = 0; i < shortestPath.size(); i++) {
int e = shortestPath.get(i);
SwitchImpl sw = graph.getEdgeObject(e);
if (sw != null && sw.getKind() == SwitchKind.BREAKER && sw.isOpen()) {
sw.setOpen(false);
connected = true;
int node = ((NodeTerminal) terminal).getNode();
// find all paths starting from the current terminal to a busbar section that does not contain an open disconnector
// paths are already sorted
List<TIntArrayList> paths = graph.findAllPaths(node, NodeBreakerVoltageLevel::isBusbarSection, NodeBreakerVoltageLevel::isOpenedDisconnector);
boolean connected = false;
if (!paths.isEmpty()) {
// the shorted path is the best, close all opened breakers of the path
TIntArrayList shortestPath = paths.get(0);
for (int i = 0; i < shortestPath.size(); i++) {
int e = shortestPath.get(i);
SwitchImpl sw = graph.getEdgeObject(e);
if (sw != null && sw.getKind() == SwitchKind.BREAKER && sw.isOpen()) {
sw.setOpen(false);
connected = true;
}
}
}
return connected;
} else {
throw new IllegalStateException("Given TerminalExt not supported: " + terminal.getClass().getName());
}
return connected;
}

@Override
public boolean disconnect(TerminalExt terminal) {
assert terminal instanceof NodeTerminal;

// already disconnected?
if (!terminal.isConnected()) {
return false;
}
if (terminal instanceof NodeTerminal) {
// already disconnected?
if (!terminal.isConnected()) {
return false;
}

int node = ((NodeTerminal) terminal).getNode();
// find all paths starting from the current terminal to a busbar section that does not contain an open disconnector
// (because otherwise there is nothing we can do to connected the terminal using only breakers)
List<TIntArrayList> paths = graph.findAllPaths(node, NodeBreakerVoltageLevel::isBusbarSection, NodeBreakerVoltageLevel::isOpenedDisconnector);
if (paths.isEmpty()) {
return false;
}
int node = ((NodeTerminal) terminal).getNode();
// find all paths starting from the current terminal to a busbar section that does not contain an open disconnector
// (because otherwise there is nothing we can do to connected the terminal using only breakers)
List<TIntArrayList> paths = graph.findAllPaths(node, NodeBreakerVoltageLevel::isBusbarSection, NodeBreakerVoltageLevel::isOpenedDisconnector);
if (paths.isEmpty()) {
return false;
}

for (TIntArrayList path : paths) {
boolean pathOpen = false;
for (int i = 0; i < path.size(); i++) {
int e = path.get(i);
SwitchImpl sw = graph.getEdgeObject(e);
if (sw != null && sw.getKind() == SwitchKind.BREAKER) {
if (!sw.isOpen()) {
sw.setOpen(true);
for (TIntArrayList path : paths) {
boolean pathOpen = false;
for (int i = 0; i < path.size(); i++) {
int e = path.get(i);
SwitchImpl sw = graph.getEdgeObject(e);
if (sw != null && sw.getKind() == SwitchKind.BREAKER) {
if (!sw.isOpen()) {
sw.setOpen(true);
}
// just one open breaker is enough to disconnect the terminal, so we can stop
pathOpen = true;
break;
}
// just one open breaker is enough to disconnect the terminal, so we can stop
pathOpen = true;
break;
}
if (!pathOpen) {
return false;
}
}
if (!pathOpen) {
return false;
}
return true;
} else {
throw new IllegalStateException("Given TerminalExt not supported: " + terminal.getClass().getName());
}
return true;
}

boolean isConnected(TerminalExt terminal) {
assert terminal instanceof NodeTerminal;

return terminal.getBusView().getBus() != null;
if (terminal instanceof NodeTerminal) {
return terminal.getBusView().getBus() != null;
} else {
throw new IllegalStateException("Given TerminalExt not supported: " + terminal.getClass().getName());
}
}

void traverse(NodeTerminal terminal, Terminal.TopologyTraverser traverser) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public double getMaxQ() {
private final TreeMap<Double, Point> points;

ReactiveCapabilityCurveImpl(TreeMap<Double, Point> points) {
assert points.size() >= 2;
if (points.size() < 2) {
throw new IllegalStateException("Points size must be >= 2");
}
this.points = points;
}

Expand Down Expand Up @@ -85,8 +87,9 @@ public ReactiveLimitsKind getKind() {

@Override
public double getMinQ(double p) {
assert points.size() >= 2;

if (points.size() < 2) {
throw new IllegalStateException("points size should be >= 2");
}
Point pt = points.get(p);
if (pt != null) {
return pt.getMinQ();
Expand All @@ -109,8 +112,9 @@ public double getMinQ(double p) {

@Override
public double getMaxQ(double p) {
assert points.size() >= 2;

if (points.size() < 2) {
throw new IllegalStateException("points size should be >= 2");
}
Point pt = points.get(p);
if (pt != null) {
return pt.getMaxQ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public static void write(Identifiable<?> identifiable, String rootElementName, N
}

public static void read(Identifiable<?> identifiable, NetworkXmlReaderContext context) throws XMLStreamException {
assert context.getReader().getLocalName().equals(ALIAS);
if (!context.getReader().getLocalName().equals(ALIAS)) {
throw new IllegalStateException();
}
String[] aliasType = new String[1];
IidmXmlUtil.runFromMinimumVersion(IidmXmlVersion.V_1_4, context, () -> aliasType[0] = context.getReader().getAttributeValue(null, "type"));
String alias = context.getAnonymizer().deanonymizeString(context.getReader().getElementText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public static void write(Identifiable<?> identifiable, NetworkXmlWriterContext c
}

public static void read(Identifiable identifiable, NetworkXmlReaderContext context) {
assert context.getReader().getLocalName().equals(PROPERTY);
if (!context.getReader().getLocalName().equals(PROPERTY)) {
throw new IllegalStateException();
}
String name = context.getReader().getAttributeValue(null, NAME);
String value = context.getReader().getAttributeValue(null, VALUE);
identifiable.setProperty(name, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ private static boolean include(String line) {

private static String includedResource(String line) {
int p = line.indexOf(INCLUDE);
assert p > 0;
if (p <= 0) {
throw new IllegalStateException("p should be > 0");
}
return line.substring(p + INCLUDE.length()).trim();
}

Expand All @@ -105,7 +107,9 @@ class ParsingContext {
void enterQuery(String line) {
leaveQuery();
int p = line.indexOf(QUERY_DEFINITION);
assert p > 0;
if (p <= 0) {
throw new IllegalStateException("p should be > 0");
}
queryName = line.substring(p + QUERY_DEFINITION.length()).trim();
}

Expand Down