@Test public void testAddDependency() { Node n1 = graph.getOrCreateNodeByName("v1"); Node n2 = graph.getOrCreateNodeByName("v2"); assertNull(graph.getEdge(n1, n2)); assertThat(graph.getAllNodes(), hasSize(2)); assertThat(graph.getAllEdges(), hasSize(0)); graph.addDependency(n1, n2, DependencyType.READ_ONLY); assertThat(graph.getAllEdges(), hasSize(1)); assertNotNull(graph.getEdge(n1, n2)); assertNull(graph.getEdge(n2, n1)); Dependency dep = graph.getAllEdges().iterator().next(); assertEquals(dep.getSource(), n1); assertEquals(dep.getTarget(), n2); assertEquals(DependencyType.READ_ONLY, dep.getDependencyType()); graph.addDependency(n1, n2, DependencyType.CREATE); assertThat(graph.getAllEdges(), hasSize(1)); dep = graph.getAllEdges().iterator().next(); assertEquals(dep.getSource(), n1); assertEquals(dep.getTarget(), n2); assertEquals(DependencyType.CREATE, dep.getDependencyType()); graph.addDependency(n1, n2, DependencyType.READ_WRITE); assertThat(graph.getAllEdges(), hasSize(1)); dep = graph.getAllEdges().iterator().next(); assertEquals(dep.getSource(), n1); assertEquals(dep.getTarget(), n2); assertEquals(DependencyType.CREATE, dep.getDependencyType()); }
@Override public Dependency addDependency(Node from, Node to, DependencyType type) { Dependency result; Dependency edge = graph.getEdge(from, to); if (edge != null) { if (edge.getDependencyType().ordinal() < type.ordinal()) { LOGGER.debug("Upgrading dependency {} to [{}]", edge, type); edge.setDependencyType(type); } else { LOGGER.debug("Reusing dependency {}", edge); } result = edge; } else { result = new Dependency(from, to, type); graph.addEdge(from, to, result); } return result; }
DependencyGraphSimpleImpl implements DependencyGraph { @Override public Dependency addDependency(Node from, Node to, DependencyType type) { Dependency result; Dependency edge = graph.getEdge(from, to); if (edge != null) { if (edge.getDependencyType().ordinal() < type.ordinal()) { LOGGER.debug("Upgrading dependency {} to [{}]", edge, type); edge.setDependencyType(type); } else { LOGGER.debug("Reusing dependency {}", edge); } result = edge; } else { result = new Dependency(from, to, type); graph.addEdge(from, to, result); } return result; } }
DependencyGraphSimpleImpl implements DependencyGraph { @Override public Dependency addDependency(Node from, Node to, DependencyType type) { Dependency result; Dependency edge = graph.getEdge(from, to); if (edge != null) { if (edge.getDependencyType().ordinal() < type.ordinal()) { LOGGER.debug("Upgrading dependency {} to [{}]", edge, type); edge.setDependencyType(type); } else { LOGGER.debug("Reusing dependency {}", edge); } result = edge; } else { result = new Dependency(from, to, type); graph.addEdge(from, to, result); } return result; } @SuppressWarnings("squid:S3366") // Sonar warns that "this" may be used by another thread before the object is completely created. In this setting // here, there won't be a problem.  DependencyGraphSimpleImpl();  DependencyGraphSimpleImpl(DependencyGraph baseGraph); }
DependencyGraphSimpleImpl implements DependencyGraph { @Override public Dependency addDependency(Node from, Node to, DependencyType type) { Dependency result; Dependency edge = graph.getEdge(from, to); if (edge != null) { if (edge.getDependencyType().ordinal() < type.ordinal()) { LOGGER.debug("Upgrading dependency {} to [{}]", edge, type); edge.setDependencyType(type); } else { LOGGER.debug("Reusing dependency {}", edge); } result = edge; } else { result = new Dependency(from, to, type); graph.addEdge(from, to, result); } return result; } @SuppressWarnings("squid:S3366") // Sonar warns that "this" may be used by another thread before the object is completely created. In this setting // here, there won't be a problem.  DependencyGraphSimpleImpl();  DependencyGraphSimpleImpl(DependencyGraph baseGraph); @Override DependencyGraph getBaseGraph(); @Override Node getOrCreateNodeByName(String name); @Override Node getNode(String name); @Override boolean hasNode(String name); @Override Dependency addDependency(Node from, Node to, DependencyType type); @Override Dependency getEdge(Node from, Node to); @Override Set<Dependency> getOutgoingEdges(Node node); @Override Set<Dependency> getOutgoingEdges(Node node, DependencyType dependencyType); @Override Set<Dependency> getIncomingEdges(Node node); @Override Set<Dependency> getIncomingEdges(Node node, DependencyType dependencyType); @Override DependencyGraph filter(final NodeFilter filter); @Override DependencyGraph filter(final EdgeFilter filter); @Override Collection<Node> getAllNodes(); @Override Collection<Dependency> getAllEdges(); AbstractGraph<Node, Dependency> getGraph(); @Override String toString(); }
DependencyGraphSimpleImpl implements DependencyGraph { @Override public Dependency addDependency(Node from, Node to, DependencyType type) { Dependency result; Dependency edge = graph.getEdge(from, to); if (edge != null) { if (edge.getDependencyType().ordinal() < type.ordinal()) { LOGGER.debug("Upgrading dependency {} to [{}]", edge, type); edge.setDependencyType(type); } else { LOGGER.debug("Reusing dependency {}", edge); } result = edge; } else { result = new Dependency(from, to, type); graph.addEdge(from, to, result); } return result; } @SuppressWarnings("squid:S3366") // Sonar warns that "this" may be used by another thread before the object is completely created. In this setting // here, there won't be a problem.  DependencyGraphSimpleImpl();  DependencyGraphSimpleImpl(DependencyGraph baseGraph); @Override DependencyGraph getBaseGraph(); @Override Node getOrCreateNodeByName(String name); @Override Node getNode(String name); @Override boolean hasNode(String name); @Override Dependency addDependency(Node from, Node to, DependencyType type); @Override Dependency getEdge(Node from, Node to); @Override Set<Dependency> getOutgoingEdges(Node node); @Override Set<Dependency> getOutgoingEdges(Node node, DependencyType dependencyType); @Override Set<Dependency> getIncomingEdges(Node node); @Override Set<Dependency> getIncomingEdges(Node node, DependencyType dependencyType); @Override DependencyGraph filter(final NodeFilter filter); @Override DependencyGraph filter(final EdgeFilter filter); @Override Collection<Node> getAllNodes(); @Override Collection<Dependency> getAllEdges(); AbstractGraph<Node, Dependency> getGraph(); @Override String toString();  }