@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()); }
public void removeDependency(T from, T to) { lock.writeLock().lock(); 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.writeLock().unlock(); } }
DependencyGraph { public void removeDependency(T from, T to) { lock.writeLock().lock(); 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.writeLock().unlock(); } } }
DependencyGraph { public void removeDependency(T from, T to) { lock.writeLock().lock(); 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.writeLock().unlock(); } }  }
DependencyGraph { public void removeDependency(T from, T to) { lock.writeLock().lock(); 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.writeLock().unlock(); } }  List<T> topologicalSort(); void addDependency(T from, T to); void removeDependency(T from, T to); void clearAll(); boolean hasDependent(T element); Set<T> getDependents(T element); void remove(T element); }
DependencyGraph { public void removeDependency(T from, T to) { lock.writeLock().lock(); 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.writeLock().unlock(); } }  List<T> topologicalSort(); void addDependency(T from, T to); void removeDependency(T from, T to); void clearAll(); boolean hasDependent(T element); Set<T> getDependents(T element); void remove(T element);  }