本文整理了Java中com.google.common.graph.Graph.predecessors()
方法的一些代码示例,展示了Graph.predecessors()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.predecessors()
方法的具体详情如下:
包路径:com.google.common.graph.Graph
类名称:Graph
方法名:predecessors
暂无
代码示例来源:origin: google/guava
@Override
public Set<N> successors(N node) {
return delegate().predecessors(node); // transpose
}
代码示例来源:origin: google/j2objc
@Override
public Set<N> successors(N node) {
return delegate().predecessors(node); // transpose
}
代码示例来源:origin: wildfly/wildfly
@Override
public Set<N> successors(N node) {
return delegate().predecessors(node); // transpose
}
代码示例来源:origin: google/guava
private static <N> GraphConnections<N, Presence> connectionsOf(Graph<N> graph, N node) {
Function<Object, Presence> edgeValueFn = Functions.constant(Presence.EDGE_EXISTS);
return graph.isDirected()
? DirectedGraphConnections.ofImmutable(
graph.predecessors(node), Maps.asMap(graph.successors(node), edgeValueFn))
: UndirectedGraphConnections.ofImmutable(
Maps.asMap(graph.adjacentNodes(node), edgeValueFn));
}
代码示例来源:origin: google/j2objc
private static <N> GraphConnections<N, Presence> connectionsOf(Graph<N> graph, N node) {
Function<Object, Presence> edgeValueFn = Functions.constant(Presence.EDGE_EXISTS);
return graph.isDirected()
? DirectedGraphConnections.ofImmutable(
graph.predecessors(node), Maps.asMap(graph.successors(node), edgeValueFn))
: UndirectedGraphConnections.ofImmutable(
Maps.asMap(graph.adjacentNodes(node), edgeValueFn));
}
代码示例来源:origin: wildfly/wildfly
private static <N> GraphConnections<N, Presence> connectionsOf(Graph<N> graph, N node) {
Function<Object, Presence> edgeValueFn = Functions.constant(Presence.EDGE_EXISTS);
return graph.isDirected()
? DirectedGraphConnections.ofImmutable(
graph.predecessors(node), Maps.asMap(graph.successors(node), edgeValueFn))
: UndirectedGraphConnections.ofImmutable(
Maps.asMap(graph.adjacentNodes(node), edgeValueFn));
}
代码示例来源:origin: google/guava
assertThat(graph.predecessors(node)).hasSize(graph.inDegree(node));
assertThat(graph.successors(node)).hasSize(graph.outDegree(node));
} else {
int selfLoopCount = graph.adjacentNodes(node).contains(node) ? 1 : 0;
assertThat(graph.degree(node)).isEqualTo(graph.adjacentNodes(node).size() + selfLoopCount);
assertThat(graph.predecessors(node)).isEqualTo(graph.adjacentNodes(node));
assertThat(graph.successors(node)).isEqualTo(graph.adjacentNodes(node));
assertThat(graph.inDegree(node)).isEqualTo(graph.degree(node));
graph.predecessors(node).contains(adjacentNode)
|| graph.successors(node).contains(adjacentNode))
.isTrue();
for (N predecessor : sanityCheckSet(graph.predecessors(node))) {
assertThat(graph.successors(predecessor)).contains(node);
assertThat(graph.hasEdgeConnecting(predecessor, node)).isTrue();
assertThat(graph.predecessors(successor)).contains(node);
assertThat(graph.hasEdgeConnecting(node, successor)).isTrue();
assertThat(graph.incidentEdges(node)).contains(EndpointPair.of(graph, node, successor));
代码示例来源:origin: google/guava
@After
public void validateGraphState() {
assertStronglyEquivalent(graph, Graphs.copyOf(graph));
assertStronglyEquivalent(graph, ImmutableValueGraph.copyOf(graph));
Graph<Integer> asGraph = graph.asGraph();
AbstractGraphTest.validateGraph(asGraph);
assertThat(graph.nodes()).isEqualTo(asGraph.nodes());
assertThat(graph.edges()).isEqualTo(asGraph.edges());
assertThat(graph.nodeOrder()).isEqualTo(asGraph.nodeOrder());
assertThat(graph.isDirected()).isEqualTo(asGraph.isDirected());
assertThat(graph.allowsSelfLoops()).isEqualTo(asGraph.allowsSelfLoops());
for (Integer node : graph.nodes()) {
assertThat(graph.adjacentNodes(node)).isEqualTo(asGraph.adjacentNodes(node));
assertThat(graph.predecessors(node)).isEqualTo(asGraph.predecessors(node));
assertThat(graph.successors(node)).isEqualTo(asGraph.successors(node));
assertThat(graph.degree(node)).isEqualTo(asGraph.degree(node));
assertThat(graph.inDegree(node)).isEqualTo(asGraph.inDegree(node));
assertThat(graph.outDegree(node)).isEqualTo(asGraph.outDegree(node));
for (Integer otherNode : graph.nodes()) {
boolean hasEdge = graph.hasEdgeConnecting(node, otherNode);
assertThat(hasEdge).isEqualTo(asGraph.hasEdgeConnecting(node, otherNode));
assertThat(graph.edgeValueOrDefault(node, otherNode, null) != null).isEqualTo(hasEdge);
assertThat(!graph.edgeValueOrDefault(node, otherNode, DEFAULT).equals(DEFAULT))
.isEqualTo(hasEdge);
}
}
}
代码示例来源:origin: google/guava
assertThat(network.predecessors(node)).isEqualTo(asGraph.predecessors(node));
assertThat(network.successors(node)).isEqualTo(asGraph.successors(node));
代码示例来源:origin: jrtom/jung
protected static <N, E> boolean link(Graph<N> g, N a, N b) {
return g.predecessors(b).contains(a);
}
代码示例来源:origin: com.io7m.jgrapht/jgrapht-guava
@Override
public Set<EndpointPair<V>> incomingEdgesOf(V vertex)
{
return graph.predecessors(vertex).stream().map(other -> createEdge(other, vertex)).collect(
collectingAndThen(toSet(), Collections::unmodifiableSet));
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
@Override
public Set<N> successors(N node) {
return delegate().predecessors(node); // transpose
}
代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger
@Override
public Set<N> successors(N node) {
return delegate().predecessors(node); // transpose
}
代码示例来源:origin: jrtom/jung
public static <N> ImmutableSet<N> roots(Graph<N> graph) {
checkNotNull(graph, "graph");
return graph
.nodes()
.stream()
.filter(node -> graph.predecessors(node).isEmpty())
.collect(toImmutableSet());
}
代码示例来源:origin: jrtom/jung
/**
* A graph is "forest-shaped" if it is directed, acyclic, and each node has at most one
* predecessor.
*/
public static <N> boolean isForestShaped(Graph<N> graph) {
checkNotNull(graph, "graph");
return graph.isDirected()
&& !Graphs.hasCycle(graph)
&& graph.nodes().stream().allMatch(node -> graph.predecessors(node).size() <= 1);
}
代码示例来源:origin: jrtom/jung
/**
* A recursive method for allocating the level for each node. Ensures that all predecessors of v
* have a level which is at least one greater than the level of v.
*
* @param node the node whose minimum level is to be calculated
*/
public void propagateMinimumLevel(N node) {
Graph<N> graph = layoutModel.getGraph();
int level = minLevels.get(node).intValue();
for (N child : graph.predecessors(node)) {
int oldLevel, newLevel;
Number o = minLevels.get(child);
if (o != null) {
oldLevel = o.intValue();
} else {
oldLevel = 0;
}
newLevel = Math.max(oldLevel, level + 1);
minLevels.put(child, new Integer(newLevel));
if (newLevel > graphHeight) {
graphHeight = newLevel;
}
propagateMinimumLevel(child);
}
}
代码示例来源:origin: jrtom/jung
/**
* @param node the node whose center is to be returned
* @return the coordinates of {@code node}'s parent, or the center of this layout's area if it's a
* root.
*/
public Point getCenter(LayoutModel<N> layoutModel, N node) {
Graph<N> graph = layoutModel.getGraph();
N parent = Iterables.getOnlyElement(graph.predecessors(node), null);
if (parent == null) {
return getCenter(layoutModel);
}
return layoutModel.get(parent);
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
private static <N> GraphConnections<N, Presence> connectionsOf(Graph<N> graph, N node) {
Function<Object, Presence> edgeValueFn = Functions.constant(Presence.EDGE_EXISTS);
return graph.isDirected()
? DirectedGraphConnections.ofImmutable(
graph.predecessors(node), Maps.asMap(graph.successors(node), edgeValueFn))
: UndirectedGraphConnections.ofImmutable(
Maps.asMap(graph.adjacentNodes(node), edgeValueFn));
}
代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger
private static <N> GraphConnections<N, Presence> connectionsOf(Graph<N> graph, N node) {
Function<Object, Presence> edgeValueFn = Functions.constant(Presence.EDGE_EXISTS);
return graph.isDirected()
? DirectedGraphConnections.ofImmutable(
graph.predecessors(node), Maps.asMap(graph.successors(node), edgeValueFn))
: UndirectedGraphConnections.ofImmutable(
Maps.asMap(graph.adjacentNodes(node), edgeValueFn));
}
代码示例来源:origin: com.google.guava/guava-tests
@After
public void validateGraphState() {
assertStronglyEquivalent(graph, Graphs.copyOf(graph));
assertStronglyEquivalent(graph, ImmutableValueGraph.copyOf(graph));
Graph<Integer> asGraph = graph.asGraph();
AbstractGraphTest.validateGraph(asGraph);
assertThat(graph.nodes()).isEqualTo(asGraph.nodes());
assertThat(graph.edges()).isEqualTo(asGraph.edges());
assertThat(graph.nodeOrder()).isEqualTo(asGraph.nodeOrder());
assertThat(graph.isDirected()).isEqualTo(asGraph.isDirected());
assertThat(graph.allowsSelfLoops()).isEqualTo(asGraph.allowsSelfLoops());
for (Integer node : graph.nodes()) {
assertThat(graph.adjacentNodes(node)).isEqualTo(asGraph.adjacentNodes(node));
assertThat(graph.predecessors(node)).isEqualTo(asGraph.predecessors(node));
assertThat(graph.successors(node)).isEqualTo(asGraph.successors(node));
assertThat(graph.degree(node)).isEqualTo(asGraph.degree(node));
assertThat(graph.inDegree(node)).isEqualTo(asGraph.inDegree(node));
assertThat(graph.outDegree(node)).isEqualTo(asGraph.outDegree(node));
for (Integer otherNode : graph.nodes()) {
boolean hasEdge = graph.hasEdgeConnecting(node, otherNode);
assertThat(hasEdge).isEqualTo(asGraph.hasEdgeConnecting(node, otherNode));
assertThat(graph.edgeValueOrDefault(node, otherNode, null) != null).isEqualTo(hasEdge);
assertThat(!graph.edgeValueOrDefault(node, otherNode, DEFAULT).equals(DEFAULT))
.isEqualTo(hasEdge);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!