diff --git a/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java b/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java index ef3cf50a..784de1d5 100644 --- a/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java +++ b/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java @@ -10,7 +10,7 @@ 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 List orderedNodes = new ArrayList(); @@ -39,8 +39,24 @@ public class WeightedDirectedGraph implements Iterable { { throw new NoSuchElementException("Missing nodes from graph"); } + + @SuppressWarnings("unchecked") + E edge = (E) new WeightedEdge(1, to); - //graph.get(from).add((E) to); + graph.get(from).add(edge); + } + + public void addEdge(T from, T to, int weight) + { + if (!(graph.containsKey(from) && graph.containsKey(to))) + { + throw new NoSuchElementException("Missing nodes from graph"); + } + + @SuppressWarnings("unchecked") + E edge = (E) new WeightedEdge(weight, to); + + graph.get(from).add(edge); } @Override