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

Intern cell explicit positionning #292

Merged
merged 26 commits into from
Dec 16, 2021
Merged

Conversation

BenoitJeanson
Copy link
Contributor

@BenoitJeanson BenoitJeanson commented Oct 22, 2021

Please check if the PR fulfills these requirements (please use '[x]' to check the checkboxes, or submit the PR and then click the checkboxes)

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR already have an issue describing the problem ? If so, link to this issue using '#XXX' and skip the rest

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
feature

What is the current behavior? (You can also link to an open issue here)
Only ExternCells have an order.

What is the new behavior (if this is a feature change)?
Introduce ability to define an order, and explicit orientation to a vertical InternCell.
No Extension is available in iidm to support that. See TestInternCellExplicitPosition.java

Does this PR introduce a breaking change or deprecate an API? If yes, check the following:

  • The Breaking Change or Deprecated label has been added
  • The migration guide has been updated in the github wiki (What changes might users need to make in their application due to this PR?)

Other information:

(if any of the questions/checkboxes don't apply, please delete them entirely)

@BenoitJeanson BenoitJeanson force-pushed the internCellExplicitPositionning branch from 77aac53 to ffff4f1 Compare October 22, 2021 13:24
Signed-off-by: BenoitJeanson <benoit.jeanson@rte-france.com>
Signed-off-by: BenoitJeanson <benoit.jeanson@rte-france.com>
Signed-off-by: BenoitJeanson <benoit.jeanson@rte-france.com>
@flo-dup flo-dup force-pushed the internCellExplicitPositionning branch from 7b1dcbe to e3d9c38 Compare October 22, 2021 16:10
flo-dup and others added 2 commits November 8, 2021 12:43
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
@@ -58,6 +59,12 @@

private String label;

private Optional<Integer> order = Optional.empty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional should not be used as parameter of a class or a method, but rather only in return values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some more arguments, as I didn't manage to convince you; intellij linter makes it a warning which says

Optional was designed to provide a limited mechanism for library method return types in which a clear way to represent "no result" was needed. Using a field with the java.util.Optional type is also problematic if the class needs to be Serializable, as java.util.Optional is not serializable.

See also the POJOs paragraph in http://dolszewski.com/java/java-8-optional-use-cases/

@flo-dup flo-dup force-pushed the internCellExplicitPositionning branch from 0bf0b94 to e3d9c38 Compare November 10, 2021 09:27
Signed-off-by: BenoitJeanson <benoit.jeanson@rte-france.com>
Signed-off-by: BenoitJeanson <benoit.jeanson@rte-france.com>
Signed-off-by: BenoitJeanson <benoit.jeanson@rte-france.com>
Signed-off-by: BenoitJeanson <benoit.jeanson@rte-france.com>
Signed-off-by: BenoitJeanson <benoit.jeanson@rte-france.com>
Signed-off-by: BenoitJeanson <benoit.jeanson@rte-france.com>
@flo-dup flo-dup force-pushed the internCellExplicitPositionning branch 2 times, most recently from bcaccbe to 19c2a90 Compare November 18, 2021 13:47
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
@flo-dup flo-dup force-pushed the internCellExplicitPositionning branch from 19c2a90 to 494d229 Compare November 18, 2021 13:50
flo-dup and others added 8 commits November 18, 2021 14:50
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
graph.getNodes().stream().filter(node -> node.getDirection() != Direction.UNDEFINED).forEach(node -> {
BusCell cell = (BusCell) node.getCell();
cell.setDirection(node.getDirection());
cell.setOrder(node.getOrder().orElse(null));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we remove the order if node.getOrder().isEmpty(). I think that's dangerous, if one node of the cell has no order it might remove it. I'd rather write node.getOrder().ifPresent(cell::setOrder)

@Override
protected void writeJsonContent(JsonGenerator generator) throws IOException {
super.writeJsonContent(generator);
generator.writeStringField("feederType", feederType.name());
generator.writeNumberField("order", order);
generator.writeNumberField("order", getOrder().orElse(-1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid writing -1 as it's the same as no information. I'll replace this line with getOrder().ifPresent(order -> generator.writeNumberField("order", order))

@@ -58,6 +59,12 @@

private String label;

private Optional<Integer> order = Optional.empty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some more arguments, as I didn't manage to convince you; intellij linter makes it a warning which says

Optional was designed to provide a limited mechanism for library method return types in which a clear way to represent "no result" was needed. Using a field with the java.util.Optional type is also problematic if the class needs to be Serializable, as java.util.Optional is not serializable.

See also the POJOs paragraph in http://dolszewski.com/java/java-8-optional-use-cases/

}

@Override
public void setOrder(Integer order) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to use Integer instead of int, as we never remove the order. If so one day, it should be done more explicitly via a removeOrder. I'll add such a method just in case

@@ -40,6 +40,12 @@ public Orientation toOrientation() {

int newHPosition(int hPosition);

Optional<Integer> getOrder();

void setOrder(Integer order);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said above, I'll replace Integer with int

Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

86.6% 86.6% Coverage
0.0% 0.0% Duplication

@flo-dup flo-dup merged commit 0e9b37a into main Dec 16, 2021
@flo-dup flo-dup deleted the internCellExplicitPositionning branch December 16, 2021 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants