From 376b37d4bf0273740ede1dcfcf0dbbbdcbc1af0d Mon Sep 17 00:00:00 2001 From: pahimar Date: Wed, 29 May 2013 15:03:49 -0400 Subject: [PATCH] Underped my generics --- .../ee3/emc/graph/WeightedDirectedGraph.java | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java b/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java index 784de1d5..b5401e96 100644 --- a/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java +++ b/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java @@ -10,9 +10,9 @@ import java.util.NoSuchElementException; import java.util.SortedSet; import java.util.TreeSet; -public class WeightedDirectedGraph> implements Iterable { +public class WeightedDirectedGraph implements Iterable { - private final Map> graph = new HashMap>(); + private final Map>> graph = new HashMap>>(); private List orderedNodes = new ArrayList(); public boolean addNode(T node) @@ -23,9 +23,9 @@ public class WeightedDirectedGraph> implements Iter } orderedNodes.add(node); - graph.put(node, new TreeSet(new Comparator() + graph.put(node, new TreeSet>(new Comparator>() { - public int compare(E o1, E o2) { + public int compare(WeightedEdge o1, WeightedEdge o2) { return orderedNodes.indexOf(o1)-orderedNodes.indexOf(o2); } })); @@ -35,15 +35,7 @@ public class WeightedDirectedGraph> implements Iter public void addEdge(T from, T to) { - if (!(graph.containsKey(from) && graph.containsKey(to))) - { - throw new NoSuchElementException("Missing nodes from graph"); - } - - @SuppressWarnings("unchecked") - E edge = (E) new WeightedEdge(1, to); - - graph.get(from).add(edge); + addEdge(from, to, 1); } public void addEdge(T from, T to, int weight) @@ -53,8 +45,7 @@ public class WeightedDirectedGraph> implements Iter throw new NoSuchElementException("Missing nodes from graph"); } - @SuppressWarnings("unchecked") - E edge = (E) new WeightedEdge(weight, to); + WeightedEdge edge = new WeightedEdge(weight, to); graph.get(from).add(edge); }