@Test public void system() { ComponentRelationships gambit = ComponentRelationships.builder() .component(Component.of("gambit", "superhero")) .addDependency(Dependency.on(Component.of("rogue", "superhero"))) .addConsumer(Consumer.by(Component.of("angel", "superhero"))) .build(); ComponentRelationships rogue = ComponentRelationships.builder() .component(Component.of("rogue", "superhero")) .addConsumer(Consumer.by(Component.of("gambit", "superhero"))) .build(); ComponentRelationships angel = ComponentRelationships.builder() .component(Component.of("angel", "superhero")) .addDependency(Dependency.on(Component.of("gambit", "superhero"))) .build(); System system = System.of("xmen", gambit, angel, rogue); Graph graph = Graph.of(system); Assert.assertEquals(3, graph.getNodes().size()); Edge gambitToRogue = Edge.create("superhero:gambit-to-superhero:rogue", "superhero:gambit", "superhero:rogue"); Edge angelToGambit = Edge.create("superhero:angel-to-superhero:gambit", "superhero:angel", "superhero:gambit"); Set<Edge> expectedEdges = new HashSet<>(Arrays.asList(gambitToRogue, angelToGambit)); Assert.assertEquals(expectedEdges, graph.getEdges()); }
public static Graph of(System system) { Set<Node> nodes = new HashSet<>(); Set<Edge> edges = new HashSet<>(); for (ComponentRelationships rel : system.getComponentRelationships()) { nodes.add(Node.of(rel)); Set<Edge> dependencies = rel.getDependencies().stream().map(d -> Edge.to(rel.getComponent(), d)) .collect(Collectors.toSet()); edges.addAll(dependencies); Set<Edge> consumers = rel.getConsumers().stream().map(c -> Edge.from(rel.getComponent(), c)) .collect(Collectors.toSet()); edges.addAll(consumers); } return Graph.create(nodes, edges); }
Graph { public static Graph of(System system) { Set<Node> nodes = new HashSet<>(); Set<Edge> edges = new HashSet<>(); for (ComponentRelationships rel : system.getComponentRelationships()) { nodes.add(Node.of(rel)); Set<Edge> dependencies = rel.getDependencies().stream().map(d -> Edge.to(rel.getComponent(), d)) .collect(Collectors.toSet()); edges.addAll(dependencies); Set<Edge> consumers = rel.getConsumers().stream().map(c -> Edge.from(rel.getComponent(), c)) .collect(Collectors.toSet()); edges.addAll(consumers); } return Graph.create(nodes, edges); } }
Graph { public static Graph of(System system) { Set<Node> nodes = new HashSet<>(); Set<Edge> edges = new HashSet<>(); for (ComponentRelationships rel : system.getComponentRelationships()) { nodes.add(Node.of(rel)); Set<Edge> dependencies = rel.getDependencies().stream().map(d -> Edge.to(rel.getComponent(), d)) .collect(Collectors.toSet()); edges.addAll(dependencies); Set<Edge> consumers = rel.getConsumers().stream().map(c -> Edge.from(rel.getComponent(), c)) .collect(Collectors.toSet()); edges.addAll(consumers); } return Graph.create(nodes, edges); }  }
Graph { public static Graph of(System system) { Set<Node> nodes = new HashSet<>(); Set<Edge> edges = new HashSet<>(); for (ComponentRelationships rel : system.getComponentRelationships()) { nodes.add(Node.of(rel)); Set<Edge> dependencies = rel.getDependencies().stream().map(d -> Edge.to(rel.getComponent(), d)) .collect(Collectors.toSet()); edges.addAll(dependencies); Set<Edge> consumers = rel.getConsumers().stream().map(c -> Edge.from(rel.getComponent(), c)) .collect(Collectors.toSet()); edges.addAll(consumers); } return Graph.create(nodes, edges); }  static Graph of(System system); }
Graph { public static Graph of(System system) { Set<Node> nodes = new HashSet<>(); Set<Edge> edges = new HashSet<>(); for (ComponentRelationships rel : system.getComponentRelationships()) { nodes.add(Node.of(rel)); Set<Edge> dependencies = rel.getDependencies().stream().map(d -> Edge.to(rel.getComponent(), d)) .collect(Collectors.toSet()); edges.addAll(dependencies); Set<Edge> consumers = rel.getConsumers().stream().map(c -> Edge.from(rel.getComponent(), c)) .collect(Collectors.toSet()); edges.addAll(consumers); } return Graph.create(nodes, edges); }  static Graph of(System system);  }