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

Implementation of Identifiable::getNetwork() #947

Merged
merged 3 commits into from
Sep 25, 2019
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 @@ -20,6 +20,11 @@
*/
public interface Identifiable<I extends Identifiable<I>> extends Extendable<I> {

/**
* Get the network associated to the object.
*/
Network getNetwork();

/**
* Get the unique identifier of the object.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public boolean isInMainSynchronousComponent() {
return sc != null && sc.getNum() == ComponentConstants.MAIN_NUM;
}

@Override
public NetworkImpl getNetwork() {
return voltageLevel.getNetwork();
}

@Override
public VoltageLevel getVoltageLevel() {
return voltageLevel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public List<TerminalExt> getTerminals() {
return terminals;
}

protected NetworkImpl getNetwork() {
@Override
public NetworkImpl getNetwork() {
if (terminals.isEmpty()) {
throw new PowsyblException(id + " is not attached to a network");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public String getName() {
return name != null ? name : id;
}

@Override
public abstract NetworkImpl getNetwork();
mathbagu marked this conversation as resolved.
Show resolved Hide resolved

protected abstract String getTypeDescription();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public void invalidate() {
buses.clear();
}

@Override
public NetworkImpl getNetwork() {
return (NetworkImpl) getVoltageLevel().getNetwork();
}

@Override
public VoltageLevel getVoltageLevel() {
checkValidity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ public NetworkIndex getIndex() {
return index;
}

@Override
public NetworkImpl getNetwork() {
return this;
}

@Override
public VariantManagerImpl getVariantManager() {
return variantManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class SwitchImpl extends AbstractIdentifiable<Switch> implements Switch, MultiVa
}
}

@Override
public NetworkImpl getNetwork() {
return voltageLevel.getNetwork();
}

@Override
public VoltageLevelExt getVoltageLevel() {
return voltageLevel;
Expand All @@ -54,12 +59,12 @@ public SwitchKind getKind() {

@Override
public boolean isOpen() {
return open.get(voltageLevel.getNetwork().getVariantIndex());
return open.get(getNetwork().getVariantIndex());
}

@Override
public void setOpen(boolean open) {
NetworkImpl network = voltageLevel.getNetwork();
NetworkImpl network = getNetwork();
int index = network.getVariantIndex();
boolean oldValue = this.open.get(index);
if (oldValue != open) {
Expand All @@ -72,15 +77,15 @@ public void setOpen(boolean open) {

@Override
public boolean isRetained() {
return retained.get(voltageLevel.getNetwork().getVariantIndex());
return retained.get(getNetwork().getVariantIndex());
}

@Override
public void setRetained(boolean retained) {
if (voltageLevel.getTopologyKind() != TopologyKind.NODE_BREAKER) {
throw new ValidationException(this, "retain status is not modifiable in a non node/breaker voltage level");
}
NetworkImpl network = voltageLevel.getNetwork();
NetworkImpl network = getNetwork();
int index = network.getVariantIndex();
boolean oldValue = this.retained.get(index);
if (oldValue != retained) {
Expand All @@ -102,7 +107,7 @@ public void setFictitious(boolean fictitious) {
if (oldValue != fictitious) {
this.fictitious = fictitious;
voltageLevel.invalidateCache();
NetworkImpl network = voltageLevel.getNetwork();
NetworkImpl network = getNetwork();
network.getListeners().notifyUpdate(this, "fictitious", oldValue, fictitious);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void testSetterGetter() {
vscConverterStation.getTerminal().setQ(q2);

assertSame(voltageLevel, bus.getVoltageLevel());
assertSame(network, bus.getNetwork());
try {
bus.setV(-1.0);
fail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;

/**
* @author Luma Zamarreño <zamarrenolm at aia.es>
Expand All @@ -33,6 +34,7 @@ private void checkSameMergedBus(Network n, String ida, String idb) {
assertNotNull(ma);
assertNotNull(mb);
assertEquals(ma, mb);
assertSame(n, ma.getNetwork());
}

private Network createBusBreaker() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public NetworkTest() {
@Test
public void testNetwork1() {
Network network = NetworkTest1Factory.create();
assertSame(network, network.getNetwork());
assertEquals(1, Iterables.size(network.getCountries()));
assertEquals(1, network.getCountryCount());
Country country1 = network.getCountries().iterator().next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public String getName() {
return id;
}

@Override
public Network getNetwork() {
return null;
}

@Override
public boolean hasProperty() {
return false;
Expand Down