com.google.common.graph.Graph.hasEdgeConnecting()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中com.google.common.graph.Graph.hasEdgeConnecting()方法的一些代码示例,展示了Graph.hasEdgeConnecting()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.hasEdgeConnecting()方法的具体详情如下:
包路径:com.google.common.graph.Graph
类名称:Graph
方法名:hasEdgeConnecting

Graph.hasEdgeConnecting介绍

[英]Returns true if there is an edge that directly connects endpoints (in the order, if any, specified by endpoints). This is equivalent to edges().contains(endpoints).

Unlike the other EndpointPair-accepting methods, this method does not throw if the endpoints are unordered and the graph is directed; it simply returns false. This is for consistency with the behavior of Collection#contains(Object) (which does not generally throw if the object cannot be present in the collection), and the desire to have this method's behavior be compatible with edges().contains(endpoints).
[中]如果存在直接连接端点的边(按端点指定的顺序,如果有),则返回true。这相当于边()。包含(端点)。
与其他端点对接受方法不同,如果端点无序且图形有方向,则此方法不会抛出;它只是返回false。这是为了与集合#contains(Object)的行为保持一致(如果对象不能出现在集合中,则通常不会抛出),并且希望此方法的行为与edges()兼容。包含(端点)。

代码示例

代码示例来源:origin: google/guava

@Override
public boolean hasEdgeConnecting(N nodeU, N nodeV) {
 return delegate().hasEdgeConnecting(nodeV, nodeU); // transpose
}

代码示例来源:origin: google/j2objc

@Override
 public boolean hasEdgeConnecting(N nodeU, N nodeV) {
  return delegate().hasEdgeConnecting(nodeV, nodeU); // transpose
 }
}

代码示例来源:origin: google/guava

@Override
 public boolean hasEdgeConnecting(EndpointPair<N> endpoints) {
  return delegate().hasEdgeConnecting(transpose(endpoints));
 }
}

代码示例来源:origin: wildfly/wildfly

@Override
 public boolean hasEdgeConnecting(N nodeU, N nodeV) {
  return delegate().hasEdgeConnecting(nodeV, nodeU); // transpose
 }
}

代码示例来源:origin: google/guava

assertThat(graph.hasEdgeConnecting(predecessor, node)).isTrue();
assertThat(graph.incidentEdges(node)).contains(EndpointPair.of(graph, predecessor, node));
allEndpointPairs.add(EndpointPair.of(graph, node, successor));
assertThat(graph.predecessors(successor)).contains(node);
assertThat(graph.hasEdgeConnecting(node, successor)).isTrue();
assertThat(graph.incidentEdges(node)).contains(EndpointPair.of(graph, node, successor));
 assertThat(graph.hasEdgeConnecting(endpoints.source(), endpoints.target())).isTrue();
} else {
 assertThat(graph.hasEdgeConnecting(endpoints.nodeU(), endpoints.nodeV())).isTrue();

代码示例来源: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: org.jboss.eap/wildfly-client-all

@Override
 public boolean hasEdgeConnecting(N nodeU, N nodeV) {
  return delegate().hasEdgeConnecting(nodeV, nodeU); // transpose
 }
}

代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger

@Override
 public boolean hasEdgeConnecting(N nodeU, N nodeV) {
  return delegate().hasEdgeConnecting(nodeV, nodeU); // transpose
 }
}

代码示例来源:origin: com.io7m.jgrapht/jgrapht-guava

@Override
public EndpointPair<V> getEdge(V sourceVertex, V targetVertex)
{
  if (sourceVertex == null || targetVertex == null) {
    return null;
  } else if (!graph.hasEdgeConnecting(sourceVertex, targetVertex)) {
    return null;
  } else {
    return createEdge(sourceVertex, targetVertex);
  }
}

代码示例来源:origin: com.io7m.jgrapht/jgrapht-guava

@Override
public double getEdgeWeight(EndpointPair<V> e)
{
  if (e == null) {
    throw new NullPointerException();
  } else if (!graph.hasEdgeConnecting(e.nodeU(), e.nodeV())) {
    throw new IllegalArgumentException("no such edge in graph: " + e.toString());
  } else {
    return Graph.DEFAULT_EDGE_WEIGHT;
  }
}

代码示例来源:origin: com.io7m.jgrapht/jgrapht-guava

@Override
public Set<EndpointPair<V>> getAllEdges(V sourceVertex, V targetVertex)
{
  if (sourceVertex == null || targetVertex == null || !graph.nodes().contains(sourceVertex)
    || !graph.nodes().contains(targetVertex))
  {
    return null;
  } else if (!graph.hasEdgeConnecting(sourceVertex, targetVertex)) {
    return Collections.emptySet();
  } else {
    return Collections.singleton(createEdge(sourceVertex, targetVertex));
  }
}

代码示例来源:origin: com.google.guava/guava-tests

assertThat(graph.hasEdgeConnecting(predecessor, node)).isTrue();
allEndpointPairs.add(EndpointPair.of(graph, node, successor));
assertThat(graph.predecessors(successor)).contains(node);
assertThat(graph.hasEdgeConnecting(node, successor)).isTrue();

代码示例来源: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);
  }
 }
}

相关文章