Again, for more review
This commit is contained in:
parent
4bd9ae52f2
commit
12e80773ed
1 changed files with 18 additions and 2 deletions
|
@ -10,7 +10,7 @@ import java.util.NoSuchElementException;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
public class WeightedDirectedGraph<T, E> implements Iterable<T> {
|
public class WeightedDirectedGraph<T, E extends WeightedEdge<T>> implements Iterable<T> {
|
||||||
|
|
||||||
private final Map<T, SortedSet<E>> graph = new HashMap<T, SortedSet<E>>();
|
private final Map<T, SortedSet<E>> graph = new HashMap<T, SortedSet<E>>();
|
||||||
private List<T> orderedNodes = new ArrayList<T>();
|
private List<T> orderedNodes = new ArrayList<T>();
|
||||||
|
@ -40,7 +40,23 @@ public class WeightedDirectedGraph<T, E> implements Iterable<T> {
|
||||||
throw new NoSuchElementException("Missing nodes from graph");
|
throw new NoSuchElementException("Missing nodes from graph");
|
||||||
}
|
}
|
||||||
|
|
||||||
//graph.get(from).add((E) to);
|
@SuppressWarnings("unchecked")
|
||||||
|
E edge = (E) new WeightedEdge<T>(1, 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<T>(weight, to);
|
||||||
|
|
||||||
|
graph.get(from).add(edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue