Skip to content

Commit

Permalink
Implementation of Identifiable::getNetwork() (#947)
Browse files Browse the repository at this point in the history
* Implementation for Identifiable::getNetwork()

Signed-off-by: Thomas ADAM <tadam@silicom.fr>
  • Loading branch information
tadam50 authored and Mathieu BAGUE committed Sep 25, 2019
1 parent 4401a85 commit cf84bb3
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 6 deletions.
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();

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

0 comments on commit cf84bb3

Please sign in to comment.