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

View refactoring #67

Merged
merged 2 commits into from
Mar 23, 2020
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 @@ -16,7 +16,6 @@

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
Expand All @@ -34,142 +33,8 @@ public abstract class AbstractBranchImpl<T extends Branch<T>, U extends BranchAt

protected AbstractBranchImpl(NetworkObjectIndex index, Resource<U> resource) {
super(index, resource);

terminal1 = TerminalImpl.create(index, resource, attributes -> new InjectionAttributes() {

@Override
public String getName() {
return attributes.getName();
}

@Override
public Map<String, String> getProperties() {
return attributes.getProperties();
}

@Override
public void setProperties(Map<String, String> properties) {
attributes.setProperties(properties);
}

@Override
public String getVoltageLevelId() {
return attributes.getVoltageLevelId1();
}

@Override
public Integer getNode() {
return attributes.getNode1();
}

@Override
public String getBus() {
return attributes.getBus1();
}

@Override
public String getConnectableBus() {
return attributes.getConnectableBus1();
}

@Override
public double getP() {
return attributes.getP1();
}

@Override
public void setP(double p) {
attributes.setP1(p);
}

@Override
public double getQ() {
return attributes.getQ1();
}

@Override
public void setQ(double q) {
attributes.setQ1(q);
}

@Override
public ConnectablePositionAttributes getPosition() {
return attributes.getPosition1();
}

@Override
public void setPosition(ConnectablePositionAttributes position) {
attributes.setPosition1(position);
}
}, getBranch());

terminal2 = TerminalImpl.create(index, resource, attributes -> new InjectionAttributes() {

@Override
public String getName() {
return attributes.getName();
}

@Override
public Map<String, String> getProperties() {
return attributes.getProperties();
}

@Override
public void setProperties(Map<String, String> properties) {
attributes.setProperties(properties);
}

@Override
public String getVoltageLevelId() {
return attributes.getVoltageLevelId2();
}

@Override
public Integer getNode() {
return attributes.getNode2();
}

@Override
public String getBus() {
return attributes.getBus2();
}

@Override
public String getConnectableBus() {
return attributes.getConnectableBus2();
}

@Override
public double getP() {
return attributes.getP2();
}

@Override
public void setP(double p) {
attributes.setP2(p);
}

@Override
public double getQ() {
return attributes.getQ2();
}

@Override
public void setQ(double q) {
attributes.setQ2(q);
}

@Override
public ConnectablePositionAttributes getPosition() {
return attributes.getPosition2();
}

@Override
public void setPosition(ConnectablePositionAttributes position) {
attributes.setPosition2(position);
}
}, getBranch());
terminal1 = TerminalImpl.create(index, new BranchToInjectionAttributesAdapter(resource.getAttributes(), true), getBranch());
terminal2 = TerminalImpl.create(index, new BranchToInjectionAttributesAdapter(resource.getAttributes(), false), getBranch());
}

protected abstract T getBranch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.util.Collections;
import java.util.List;
import java.util.function.Function;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
Expand All @@ -25,7 +24,7 @@ public abstract class AbstractInjectionImpl<I extends Injection<I>, D extends In

protected AbstractInjectionImpl(NetworkObjectIndex index, Resource<D> resource) {
super(index, resource);
terminal = TerminalImpl.create(index, resource, Function.identity(), getInjection());
terminal = TerminalImpl.create(index, resource.getAttributes(), getInjection());
}

protected abstract I getInjection();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* Copyright (c) 2020, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.network.store.client;

import com.powsybl.network.store.model.BranchAttributes;
import com.powsybl.network.store.model.ConnectablePositionAttributes;
import com.powsybl.network.store.model.InjectionAttributes;

import java.util.Map;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class BranchToInjectionAttributesAdapter implements InjectionAttributes {

private final BranchAttributes attributes;

private final boolean side1;

public BranchToInjectionAttributesAdapter(BranchAttributes attributes, boolean side1) {
this.attributes = attributes;
this.side1 = side1;
}

@Override
public String getName() {
return attributes.getName();
}

@Override
public Map<String, String> getProperties() {
return attributes.getProperties();
}

@Override
public void setProperties(Map<String, String> properties) {
attributes.setProperties(properties);
}

@Override
public String getVoltageLevelId() {
return side1 ? attributes.getVoltageLevelId1() : attributes.getVoltageLevelId2();
}

@Override
public Integer getNode() {
return side1 ? attributes.getNode1() : attributes.getNode2();
}

@Override
public String getBus() {
return side1 ? attributes.getBus1() : attributes.getBus2();
}

@Override
public String getConnectableBus() {
return side1 ? attributes.getConnectableBus1() : attributes.getConnectableBus2();
}

@Override
public double getP() {
return side1 ? attributes.getP1() : attributes.getP2();
}

@Override
public void setP(double p) {
if (side1) {
attributes.setP1(p);
} else {
attributes.setP2(p);
}
}

@Override
public double getQ() {
return side1 ? attributes.getQ1() : attributes.getQ2();
}

@Override
public void setQ(double q) {
if (side1) {
attributes.setQ1(q);
} else {
attributes.setQ2(q);
}
}

@Override
public ConnectablePositionAttributes getPosition() {
return side1 ? attributes.getPosition1() : attributes.getPosition2();
}

@Override
public void setPosition(ConnectablePositionAttributes position) {
if (side1) {
attributes.setPosition1(position);
} else {
attributes.setPosition2(position);
}
}
}
Loading