Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. @Override
  2.     public void addEdge(E e, V v1, V v2) {
  3.         if (!vertexToNeighbours.containsKey(v1)) {
  4.             throw new IllegalArgumentException("Graph doesn't contain vertex " + v1);
  5.         }
  6.         if (!vertexToNeighbours.containsKey(v2)) {
  7.             throw new IllegalArgumentException("Graph doesn't contain vertex " + v2);
  8.         }
  9.         UnorderedPair<V> endpoints = new UnorderedPair<>(v1, v2);
  10.         if (edgeToEndpoints.containsValue(endpoints)) {
  11.             throw new IllegalArgumentException("Graph already contains directed"
  12.                     + " edge from vertex " + v1 + " to vertex " + v2 + ".");
  13.         } else if (edgeToEndpoints.containsKey(e)) {
  14.             throw new IllegalArgumentException("Graph already containts edge "
  15.                     + e + "connecting these guys: " + edgeToEndpoints.get(e));
  16.         } else {
  17.             edgeToEndpoints.put(e, endpoints);
  18.             vertexToNeighbours.get(v1).addNeighbour(v2);
  19.             vertexToNeighbours.get(v2).addNeighbour(v1);
  20.         }
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement