public Set<EntityDescriptor> resolveEntities(Collection<EntityDescriptor> unresolvedEntities) { final MutableGraph<EntityDescriptor> dependencyGraph = GraphBuilder.directed() .allowsSelfLoops(false) .nodeOrder(ElementOrder.insertion()) .build(); unresolvedEntities.forEach(dependencyGraph::addNode); final HashSet<EntityDescriptor> resolvedEntities = new HashSet<>(); final MutableGraph<EntityDescriptor> finalDependencyGraph = resolveDependencyGraph(dependencyGraph, resolvedEntities); LOG.debug("Final dependency graph: {}", finalDependencyGraph); return finalDependencyGraph.nodes(); }
/** * Returns a {@link GraphBuilder} initialized with all properties queryable from {@code graph}. * * <p>The "queryable" properties are those that are exposed through the {@link Graph} interface, * such as {@link Graph#isDirected()}. Other properties, such as {@link #expectedNodeCount(int)}, * are not set in the new builder. */ public static <N> GraphBuilder<N> from(Graph<N> graph) { return new GraphBuilder<N>(graph.isDirected()) .allowsSelfLoops(graph.allowsSelfLoops()) .nodeOrder(graph.nodeOrder()); }
/** * Returns a {@link GraphBuilder} initialized with all properties queryable from {@code graph}. * * <p>The "queryable" properties are those that are exposed through the {@link Graph} interface, * such as {@link Graph#isDirected()}. Other properties, such as {@link #expectedNodeCount(int)}, * are not set in the new builder. */ public static <N> GraphBuilder<N> from(Graph<N> graph) { return new GraphBuilder<N>(graph.isDirected()) .allowsSelfLoops(graph.allowsSelfLoops()) .nodeOrder(graph.nodeOrder()); }
/** * Returns a {@link GraphBuilder} initialized with all properties queryable from {@code graph}. * * <p>The "queryable" properties are those that are exposed through the {@link Graph} interface, * such as {@link Graph#isDirected()}. Other properties, such as {@link #expectedNodeCount(int)}, * are not set in the new builder. */ public static <N> GraphBuilder<N> from(Graph<N> graph) { return new GraphBuilder<N>(graph.isDirected()) .allowsSelfLoops(graph.allowsSelfLoops()) .nodeOrder(graph.nodeOrder()); }
@Test public void nodeOrder_none() { MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(unordered()).build(); assertThat(graph.nodeOrder()).isEqualTo(unordered()); }
@Test public void nodeOrder_natural() { MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(ElementOrder.<Integer>natural()).build(); addNodes(graph); assertThat(graph.nodeOrder()).isEqualTo(ElementOrder.sorted(Ordering.<Integer>natural())); assertThat(graph.nodes()).containsExactly(1, 3, 4).inOrder(); }
@Test public void nodeOrder_sorted() { MutableGraph<Integer> graph = GraphBuilder.directed() .nodeOrder(ElementOrder.sorted(Ordering.<Integer>natural().reverse())) .build(); addNodes(graph); assertThat(graph.nodeOrder()) .isEqualTo(ElementOrder.sorted(Ordering.<Integer>natural().reverse())); assertThat(graph.nodes()).containsExactly(4, 3, 1).inOrder(); }
@Test public void nodeOrder_insertion() { MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(insertion()).build(); addNodes(graph); assertThat(graph.nodeOrder()).isEqualTo(insertion()); assertThat(graph.nodes()).containsExactly(3, 1, 4).inOrder(); }
@Test public void customComparable() { MutableGraph<ComparableSubClass> graph = GraphBuilder.undirected().nodeOrder(ElementOrder.<ComparableSubClass>natural()).build(); ComparableSubClass node2 = new ComparableSubClass(2); ComparableSubClass node4 = new ComparableSubClass(4); ComparableSubClass node6 = new ComparableSubClass(6); ComparableSubClass node8 = new ComparableSubClass(8); graph.addNode(node4); graph.addNode(node2); graph.addNode(node6); graph.addNode(node8); assertThat(graph.nodeOrder().comparator()).isEqualTo(Ordering.natural()); assertThat(graph.nodes()).containsExactly(node2, node4, node6, node8).inOrder(); }
@Test public void customComparator() { Comparator<NonComparableSuperClass> comparator = new Comparator<NonComparableSuperClass>() { @Override public int compare(NonComparableSuperClass left, NonComparableSuperClass right) { return left.value.compareTo(right.value); } }; MutableGraph<NonComparableSuperClass> graph = GraphBuilder.undirected().nodeOrder(ElementOrder.sorted(comparator)).build(); NonComparableSuperClass node1 = new NonComparableSuperClass(1); NonComparableSuperClass node3 = new NonComparableSuperClass(3); NonComparableSuperClass node5 = new NonComparableSuperClass(5); NonComparableSuperClass node7 = new NonComparableSuperClass(7); graph.addNode(node1); graph.addNode(node7); graph.addNode(node5); graph.addNode(node3); assertThat(graph.nodeOrder().comparator()).isEqualTo(comparator); assertThat(graph.nodes()).containsExactly(node1, node3, node5, node7).inOrder(); }
private static void filterCylicDependencies(List<ProjectConfiguratorContribution> configurators) { Map<String, ProjectConfiguratorContribution> idToConfigurator = configurators.stream() .collect(Collectors.toMap(ProjectConfiguratorContribution::getId, Function.identity())); MutableGraph<ProjectConfiguratorContribution> dependencyGraph = GraphBuilder.directed().nodeOrder(ElementOrder.insertion()).build(); configurators.forEach(c -> dependencyGraph.addNode(c)); for (ProjectConfiguratorContribution configurator : configurators) { filterCylicDependencies(configurator, configurator.getRunsBefore(), idToConfigurator, dependencyGraph, false); filterCylicDependencies(configurator, configurator.getRunsAfter(), idToConfigurator, dependencyGraph, true); } }
/** Returns an empty {@link MutableCTree} with the properties of this {@link TreeBuilder}. */ // TODO(jrtom): decide how we're going to handle different implementations. // For the graph stuff, we don't really need different implementations, but // for trees, maybe we do; at least for binary trees vs. trees with no restrictions on outgoing edges... public <N1 extends N> MutableCTree<N1> build() { GraphBuilder<Object> graphBuilder = GraphBuilder.directed().allowsSelfLoops(false); if (expectedNodeCount.isPresent()) { graphBuilder = graphBuilder.expectedNodeCount(expectedNodeCount.get()); } MutableGraph<N1> delegate = graphBuilder.nodeOrder(nodeOrder).build(); @SuppressWarnings("unchecked") Optional<N1> rootCast = (Optional<N1>) root; return new DelegateCTree<N1>(delegate, rootCast); }
/** * Returns a {@link GraphBuilder} initialized with all properties queryable from {@code graph}. * * <p>The "queryable" properties are those that are exposed through the {@link Graph} interface, * such as {@link Graph#isDirected()}. Other properties, such as {@link #expectedNodeCount(int)}, * are not set in the new builder. */ public static <N> GraphBuilder<N> from(Graph<N> graph) { return new GraphBuilder<N>(graph.isDirected()) .allowsSelfLoops(graph.allowsSelfLoops()) .nodeOrder(graph.nodeOrder()); }
/** * Returns a {@link GraphBuilder} initialized with all properties queryable from {@code graph}. * * <p>The "queryable" properties are those that are exposed through the {@link Graph} interface, * such as {@link Graph#isDirected()}. Other properties, such as {@link #expectedNodeCount(int)}, * are not set in the new builder. */ public static <N> GraphBuilder<N> from(Graph<N> graph) { return new GraphBuilder<N>(graph.isDirected()) .allowsSelfLoops(graph.allowsSelfLoops()) .nodeOrder(graph.nodeOrder()); }
public SampleGraph(final Method m, final SampleNode node) { int nrNodes = node.getNrNodes(); vertexMap = MultimapBuilder.hashKeys(nrNodes).hashSetValues(1).build(); aggregates = new THashMap<>(nrNodes); sampleTree = GraphBuilder.directed() .nodeOrder(ElementOrder.unordered()) .allowsSelfLoops(false) .expectedNodeCount(nrNodes) .build(); aggGraph = GraphBuilder.directed() .nodeOrder(ElementOrder.unordered()) .allowsSelfLoops(false) .expectedNodeCount(nrNodes) .build(); rootVertex = tree2Graph(m, node); }
@Test public void nodeOrder_sorted() { MutableGraph<Integer> graph = GraphBuilder.directed() .nodeOrder(ElementOrder.sorted(Ordering.<Integer>natural().reverse())) .build(); addNodes(graph); assertThat(graph.nodeOrder()) .isEqualTo(ElementOrder.sorted(Ordering.<Integer>natural().reverse())); assertThat(graph.nodes()).containsExactly(4, 3, 1).inOrder(); }
@Test public void nodeOrder_none() { MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(unordered()).build(); assertThat(graph.nodeOrder()).isEqualTo(unordered()); }
@Test public void nodeOrder_natural() { MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(ElementOrder.<Integer>natural()).build(); addNodes(graph); assertThat(graph.nodeOrder()).isEqualTo(ElementOrder.sorted(Ordering.<Integer>natural())); assertThat(graph.nodes()).containsExactly(1, 3, 4).inOrder(); }
@Test public void nodeOrder_insertion() { MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(insertion()).build(); addNodes(graph); assertThat(graph.nodeOrder()).isEqualTo(insertion()); assertThat(graph.nodes()).containsExactly(3, 1, 4).inOrder(); }
@Test public void customComparable() { MutableGraph<ComparableSubClass> graph = GraphBuilder.undirected().nodeOrder(ElementOrder.<ComparableSubClass>natural()).build(); ComparableSubClass node2 = new ComparableSubClass(2); ComparableSubClass node4 = new ComparableSubClass(4); ComparableSubClass node6 = new ComparableSubClass(6); ComparableSubClass node8 = new ComparableSubClass(8); graph.addNode(node4); graph.addNode(node2); graph.addNode(node6); graph.addNode(node8); assertThat(graph.nodeOrder().comparator()).isEqualTo(Ordering.natural()); assertThat(graph.nodes()).containsExactly(node2, node4, node6, node8).inOrder(); }