package layout;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javafx.scene.Node;
import javafx.scene.layout.Pane;
import physics.Spring;
import util.UnorderedPair;

/**
 * A layout pane that positions elements according to elastic connections.
 * @author Christoph Burschka &lt;christoph@burschka.de&gt;
 */
public class PhysLayoutPane extends Pane {
    private Map<UnorderedPair<Node>, Spring> connections;
    private Map<Node, Map<Node,Spring>> connectionsTo;

    public Spring getConnection(Node a, Node b) {
        return connections.get(new UnorderedPair(a, b));
    }

    public void addConnection(Node a, Node b, Spring s) {
        this.connections.put(new UnorderedPair(a, b), s);
        Map<Node, Spring> m = this.connectionsTo.get(a);
        Map<Node, Spring> n = this.connectionsTo.get(b);
        if (m == null) {
            m = new HashMap<Node, Spring>();
            this.connectionsTo.put(a, m);
        }
        if (n == null) {
            n = new HashMap<Node, Spring>();
            this.connectionsTo.put(b, n);
        }
        this.connectionsTo.get(a).put(b, s);
        this.connectionsTo.get(b).put(a, s);
    }

    public void removeConnection(Node a, Node b) {
        this.connections.remove(new UnorderedPair(a, b));
        Map<Node, Spring> m = this.connectionsTo.get(a);
        Map<Node, Spring> n = this.connectionsTo.get(b);
        if (m != null) m.remove(b);
        if (n != null) n.remove(a);
    }

    public Set<Node> getNeighbors(Node a) {
        Map<Node, Spring> m = this.connectionsTo.get(a);
        if (m == null) return null;
        return m.keySet();
    }
}

@@ -490,16 +490,133 @@
 onsTo;%0A%0A
+    public PhysLayoutPane() %7B%0A        connections = new HashMap%3C%3E();%0A        connectionsTo = new HashMap%3C%3E();%0A    %7D%0A%0A
     publ
@@ -844,38 +844,24 @@
 %0A        Map
-%3CNode, Spring%3E
  m = this.co
@@ -887,38 +887,24 @@
 %0A        Map
-%3CNode, Spring%3E
  n = this.co
@@ -972,36 +972,24 @@
 new HashMap%3C
-Node, Spring
 %3E();%0A       
@@ -1086,28 +1086,16 @@
 HashMap%3C
-Node, Spring
 %3E();%0A   
@@ -1356,38 +1356,24 @@
 %0A        Map
-%3CNode, Spring%3E
  m = this.co
@@ -1403,30 +1403,16 @@
      Map
-%3CNode, Spring%3E
  n = thi

Remove some redundant generics.