public void removeDependency(T from, T to) {
      long stamp = lock.writeLock();
      try {
         Set<T> dependencies = outgoingEdges.get(from);
         if (dependencies == null || !dependencies.contains(to)) {
            throw new IllegalArgumentException("Inexistent dependency");
         }
         dependencies.remove(to);
         incomingEdges.get(to).remove(from);
      } finally {
         lock.unlockWrite(stamp);
      }
   }
@Test
   public void testRemoveDependency() throws CyclicDependencyException {
      DependencyGraph<String> g = new DependencyGraph<>();
      g.addDependency("E", "B");
      g.addDependency("E", "C");
      g.addDependency("E", "D");
      g.addDependency("B", "D");
      g.addDependency("B", "C");
      g.addDependency("C", "D");

      assertEquals(g.topologicalSort(), Arrays.asList("E", "B", "C", "D"));

      g.removeDependency("E", "B");
      g.addDependency("B", "E");

      assertEquals(g.topologicalSort(), Arrays.asList("B", "E", "C", "D"));

      g.clearAll();

      assertTrue(g.topologicalSort().isEmpty());
   }