Skip to content

Commit

Permalink
Implementation for Identifiable::getNetwork()
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas ADAM <tadam@silicom.fr>
  • Loading branch information
tadam50 committed Sep 18, 2019
1 parent 600b1a9 commit fbdf231
Show file tree
Hide file tree
Showing 8 changed files with 40 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().getSubstation().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 @@ -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 fbdf231

Please sign in to comment.