From 10e0418ef42c110fbce9fc20aaa9e0862a87ba4b Mon Sep 17 00:00:00 2001 From: James Ball Date: Tue, 11 Feb 2020 22:12:02 +0000 Subject: [PATCH] Removed graph package --- src/graphs/Graph.java | 34 --------------------------- src/graphs/Node.java | 53 ------------------------------------------- 2 files changed, 87 deletions(-) delete mode 100644 src/graphs/Graph.java delete mode 100644 src/graphs/Node.java diff --git a/src/graphs/Graph.java b/src/graphs/Graph.java deleted file mode 100644 index 7968313..0000000 --- a/src/graphs/Graph.java +++ /dev/null @@ -1,34 +0,0 @@ -package graphs; - -import shapes.Line; -import shapes.Vector2; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -// TODO: Implement Chinese postman solving. - -public class Graph { - private Map nodes; - - public Graph(List lines) { - this.nodes = new HashMap<>(); - - for (Line line : lines) { - if (!nodes.containsKey(line.getA())) { - nodes.put(line.getA(), new Node(line.getA())); - } - - if (!nodes.containsKey(line.getB())) { - nodes.put(line.getB(), new Node(line.getB())); - } - - Node nodeA = nodes.get(line.getA()); - Node nodeB = nodes.get(line.getB()); - - nodeA.addAdjacent(nodeB, line.getLength()); - nodeB.addAdjacent(nodeA, line.getLength()); - } - } -} diff --git a/src/graphs/Node.java b/src/graphs/Node.java deleted file mode 100644 index 7ac8d21..0000000 --- a/src/graphs/Node.java +++ /dev/null @@ -1,53 +0,0 @@ -package graphs; - -import shapes.Vector2; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -public class Node { - private Vector2 location; - private List adjacentNodes; - private List adjacentWeights; - - public Node(Vector2 location) { - this.location = location; - this.adjacentNodes = new ArrayList<>(); - this.adjacentWeights = new ArrayList<>(); - } - - public Vector2 getLocation() { - return location; - } - - public void addAdjacent(Node node, double weight) { - adjacentNodes.add(node); - adjacentWeights.add(weight); - } - - public Node getAdjacentNode(int index) { - return adjacentNodes.get(index); - } - - public double getAdjacentWeight(int index) { - return adjacentWeights.get(index); - } - - public int degree() { - return adjacentNodes.size(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Node node = (Node) o; - return location.equals(node.location); - } - - @Override - public int hashCode() { - return Objects.hash(location); - } -}