diff --git a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/intermediate/SelfLoopPlacer.java b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/intermediate/SelfLoopPlacer.java index 37aec4f83f..d0fa5a1fd9 100644 --- a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/intermediate/SelfLoopPlacer.java +++ b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/intermediate/SelfLoopPlacer.java @@ -119,10 +119,11 @@ private ISelfLoopPortPositioner getPositioner(final LNode node) { case FIXED_ORDER: case FIXED_POS: + case FIXED_RATIO: return new FixedOrderSelfLoopPortPositioner(); default: - return null; + throw new AssertionError("Unknown port constraint: " + constraint); } } diff --git a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/intermediate/SelfLoopPreProcessor.java b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/intermediate/SelfLoopPreProcessor.java index dbce16e767..477ee3a190 100644 --- a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/intermediate/SelfLoopPreProcessor.java +++ b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/intermediate/SelfLoopPreProcessor.java @@ -96,7 +96,7 @@ public void preprocessLabels(final SelfLoopNode slNode, final Direction layoutDi for (SelfLoopComponent component : slNode.getSelfLoopComponents()) { // Retrieve all labels attached to edges that belong to this component List labels = component.getConnectedEdges().stream() - .filter(edge -> edge.getEdge().getSource().getNode().equals(edge.getEdge().getTarget().getNode())) + .filter(edge -> edge.getEdge().isSelfLoop()) .flatMap(edge -> edge.getEdge().getLabels().stream()) .sorted(new Comparator() { @Override @@ -149,7 +149,7 @@ public int compare(final LLabel o1, final LLabel o2) { * Collect and remove ports that are only self-loop ports. */ private void hidePorts(final LNode node) { - List selfLoopPorts = new ArrayList(); + List selfLoopPorts = new ArrayList(node.getPorts().size()); // check each port if has to be hidden for (LPort port : node.getPorts()) { diff --git a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopComponent.java b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopComponent.java index 616937c52f..598bf917f8 100644 --- a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopComponent.java +++ b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopComponent.java @@ -30,13 +30,13 @@ public class SelfLoopComponent { /** The ports of the self loop component. They are all connected by at least one edge. */ - private List ports = new ArrayList<>(); + private final List ports; /** All center edge labels that occur at the component edges, if any. */ private SelfLoopLabel selfLoopLabel; /** The components that the self loop component depends on. */ - private Map> dependencyComponents = new HashMap<>(); + private final Map> dependencyComponents = new HashMap<>(); /** Any edges the component depends on. */ - private Map> edgeDependencies = new HashMap<>(); + private final Map> edgeDependencies = new HashMap<>(); /** @@ -46,6 +46,7 @@ public class SelfLoopComponent { * Ports of the connected self loop component. */ public SelfLoopComponent(final List ports) { + this.ports = new ArrayList<>(ports.size()); addAllPorts(ports); calculateConnectedEdges(); } @@ -113,7 +114,7 @@ private static void findAllConnectedPorts(final LNode node, final LPort lPort, /** * Adds a {@link SelfLoopPort} to the component that represents the given regular port. */ - public void addPort(final LPort port) { + private void addPort(final LPort port) { ports.add(new SelfLoopPort(port, this)); } @@ -224,9 +225,9 @@ private void calculateConnectedEdges() { for (SelfLoopPort port : ports) { for (LEdge edge : port.getLPort().getOutgoingEdges()) { SelfLoopPort targetPort = findPort(edge.getTarget()); - SelfLoopEdge selfLoopEdge = new SelfLoopEdge(this, port, targetPort, edge); - port.getConnectedEdges().add(selfLoopEdge); if (targetPort != null) { + SelfLoopEdge selfLoopEdge = new SelfLoopEdge(this, port, targetPort, edge); + port.getConnectedEdges().add(selfLoopEdge); targetPort.getConnectedEdges().add(selfLoopEdge); } } diff --git a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopEdge.java b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopEdge.java index 5a6b029844..7be0ed59b7 100644 --- a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopEdge.java +++ b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopEdge.java @@ -29,9 +29,9 @@ public class SelfLoopEdge { /** The component the self loop belongs to. */ private final SelfLoopComponent component; /** Other self loops this self loop depends on. */ - private Map> dependencyEdges = new HashMap<>(); + private final Map> dependencyEdges = new HashMap<>(); /** TODO Document. */ - private Map edgeOrders = new HashMap<>(); + private final Map edgeOrders = new HashMap<>(); /** * Create a new self loop. diff --git a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopLabel.java b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopLabel.java index 4b18305cc6..07807f9a8a 100644 --- a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopLabel.java +++ b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopLabel.java @@ -18,13 +18,13 @@ public class SelfLoopLabel { /** The list of labels this self loop label consists of. */ - private List labels = new ArrayList<>(); + private final List labels = new ArrayList<>(); /** The combined height of all labels. */ private double height; /** The maximum width over all labels. */ private double width; /** The candidate positions for this label. */ - private List candidatePositions = new ArrayList<>(); + private final List candidatePositions = new ArrayList<>(); /** The position chosen for this label. */ private SelfLoopLabelPosition labelPosition; diff --git a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopNode.java b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopNode.java index 401fbc6eba..e5ce3a9418 100644 --- a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopNode.java +++ b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopNode.java @@ -24,9 +24,9 @@ public class SelfLoopNode { /** The original node this class represents. */ private final LNode node; /** A map from all four port sides to their respective node side objects. */ - private EnumMap nodeSides = new EnumMap<>(PortSide.class); + private final EnumMap nodeSides = new EnumMap<>(PortSide.class); /** List of self loop components this node has. */ - private List selfLoopComponents = new ArrayList<>(); + private final List selfLoopComponents = new ArrayList<>(); /** diff --git a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopNodeSide.java b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopNodeSide.java index 4135b64c7e..538dfd8ec3 100644 --- a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopNodeSide.java +++ b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopNodeSide.java @@ -24,7 +24,7 @@ public class SelfLoopNodeSide { /** The actual side information. */ private final PortSide side; /** The ports which are placed on this node side. */ - private List ports = new ArrayList<>(); + private final List ports = new ArrayList<>(); /** The maximum level a port on this side has. */ private int maximumPortLevel; /** The maximum level a segment on this side has. */ @@ -32,9 +32,9 @@ public class SelfLoopNodeSide { /** The maximum offset which has to be considered when calculating the margin of the node. */ private double maximumLabelOffset; /** The segments which belong to an opposing self loop (space has to be reserved for them). */ - private Map opposingSegments = new HashMap<>(); + private final Map opposingSegments = new HashMap<>(); /** The roots of the component dependency graph. They hold the outermost components of the node side. */ - private Set componentDependencies = new HashSet<>(); + private final Set componentDependencies = new HashSet<>(); /** diff --git a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopPort.java b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopPort.java index 237bfa1e95..c8a4955db3 100644 --- a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopPort.java +++ b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/SelfLoopPort.java @@ -30,11 +30,11 @@ public class SelfLoopPort { /** The level of the edge segment. */ private int maximumLevel = 0; /** Map about the different level for the different edges connected to this port. */ - private Map edgeToLevelMap = new HashMap<>(); + private final Map edgeToLevelMap = new HashMap<>(); /** The SelfLoopComponent the port belongs to. */ private SelfLoopComponent component; /** Self loops connected to this port. */ - private List connectedEdges = new ArrayList<>(); + private final List connectedEdges = new ArrayList<>(); /** The port is connected to an edge connecting it to another node. */ private boolean isNonLoopPort = false; /** The original index of the port before using the linear node representation or altering the port order. */ diff --git a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/calculators/SelfLoopComponentDependencyGraphCalculator.java b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/calculators/SelfLoopComponentDependencyGraphCalculator.java index e25c96fb5c..ceb1505417 100644 --- a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/calculators/SelfLoopComponentDependencyGraphCalculator.java +++ b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/loops/calculators/SelfLoopComponentDependencyGraphCalculator.java @@ -196,7 +196,7 @@ public static void calculateEdgeDependecies(final List compon List sidePorts = component.getPortsOfSide(currentSide); // filter non-loop components - if (component.getPorts().size() > 1) { + if (ports.size() > 1) { List dependencies = calculateEdgeOrder( ports, sidePorts, new HashSet(), currentSide, false); component.getEdgeDependencies().put(currentSide, dependencies);