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

x33g5p2x  于2022-01-25 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(158)

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

Network.edges介绍

[英]Returns all edges in this network, in the order specified by #edgeOrder().
[中]按#edgeOrder()指定的顺序返回此网络中的所有边。

代码示例

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

private static <N, E> Map<E, EndpointPair<N>> edgeIncidentNodesMap(final Network<N, E> network) {
  Function<E, EndpointPair<N>> edgeToIncidentNodesFn =
    new Function<E, EndpointPair<N>>() {
     @Override
     public EndpointPair<N> apply(E edge) {
      return network.incidentNodes(edge);
     }
    };
  return Maps.asMap(network.edges(), edgeToIncidentNodesFn);
 }
}

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

AbstractGraphTest.validateGraph(asGraph);
assertThat(network.nodes()).isEqualTo(asGraph.nodes());
assertThat(network.edges().size()).isAtLeast(asGraph.edges().size());
assertThat(network.nodeOrder()).isEqualTo(asGraph.nodeOrder());
assertThat(network.isDirected()).isEqualTo(asGraph.isDirected());
assertThat(network.allowsSelfLoops()).isEqualTo(asGraph.allowsSelfLoops());
for (E edge : sanityCheckSet(network.edges())) {
    network.inEdges(node).contains(incidentEdge)
      || network.outEdges(node).contains(incidentEdge));
  assertThat(network.edges()).contains(incidentEdge);
  assertThat(network.incidentNodes(incidentEdge)).contains(node);

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

@Override
public Set<E> edges() {
 return network.edges();
}

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

@Override
public Set<E> edges() {
 return delegate().edges();
}

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

private static <N, E> Map<E, N> getEdgeToReferenceNode(Network<N, E> network) {
 // ImmutableMap.Builder maintains the order of the elements as inserted, so the map will have
 // whatever ordering the network's edges do, so ImmutableSortedMap is unnecessary even if the
 // input edges are sorted.
 ImmutableMap.Builder<E, N> edgeToReferenceNode = ImmutableMap.builder();
 for (E edge : network.edges()) {
  edgeToReferenceNode.put(edge, network.incidentNodes(edge).nodeU());
 }
 return edgeToReferenceNode.build();
}

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

private static <N, E> Map<E, EndpointPair<N>> edgeIncidentNodesMap(final Network<N, E> network) {
  Function<E, EndpointPair<N>> edgeToIncidentNodesFn =
    new Function<E, EndpointPair<N>>() {
     @Override
     public EndpointPair<N> apply(E edge) {
      return network.incidentNodes(edge);
     }
    };
  return Maps.asMap(network.edges(), edgeToIncidentNodesFn);
 }
}

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

@Override
public Set<E> edges() {
 return delegate().edges();
}

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

private static <N, E> Map<E, EndpointPair<N>> edgeIncidentNodesMap(final Network<N, E> network) {
  Function<E, EndpointPair<N>> edgeToIncidentNodesFn =
    new Function<E, EndpointPair<N>>() {
     @Override
     public EndpointPair<N> apply(E edge) {
      return network.incidentNodes(edge);
     }
    };
  return Maps.asMap(network.edges(), edgeToIncidentNodesFn);
 }
}

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

@Override
public Set<E> edges() {
 return delegate().edges();
}

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

private static <N, E> Map<E, N> getEdgeToReferenceNode(Network<N, E> network) {
 // ImmutableMap.Builder maintains the order of the elements as inserted, so the map will have
 // whatever ordering the network's edges do, so ImmutableSortedMap is unnecessary even if the
 // input edges are sorted.
 ImmutableMap.Builder<E, N> edgeToReferenceNode = ImmutableMap.builder();
 for (E edge : network.edges()) {
  edgeToReferenceNode.put(edge, network.incidentNodes(edge).nodeU());
 }
 return edgeToReferenceNode.build();
}

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

private static <N, E> Map<E, N> getEdgeToReferenceNode(Network<N, E> network) {
 // ImmutableMap.Builder maintains the order of the elements as inserted, so the map will have
 // whatever ordering the network's edges do, so ImmutableSortedMap is unnecessary even if the
 // input edges are sorted.
 ImmutableMap.Builder<E, N> edgeToReferenceNode = ImmutableMap.builder();
 for (E edge : network.edges()) {
  edgeToReferenceNode.put(edge, network.incidentNodes(edge).nodeU());
 }
 return edgeToReferenceNode.build();
}

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

/**
 * Returns true if {@code network} has at least one cycle. A cycle is defined as a non-empty
 * subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges)
 * starting and ending with the same node.
 *
 * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1).
 */
public static boolean hasCycle(Network<?, ?> network) {
 // In a directed graph, parallel edges cannot introduce a cycle in an acyclic graph.
 // However, in an undirected graph, any parallel edge induces a cycle in the graph.
 if (!network.isDirected()
   && network.allowsParallelEdges()
   && network.edges().size() > network.asGraph().edges().size()) {
  return true;
 }
 return hasCycle(network.asGraph());
}

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

/** Creates a mutable copy of {@code network} with the same nodes and edges. */
public static <N, E> MutableNetwork<N, E> copyOf(Network<N, E> network) {
 MutableNetwork<N, E> copy =
   NetworkBuilder.from(network)
     .expectedNodeCount(network.nodes().size())
     .expectedEdgeCount(network.edges().size())
     .build();
 for (N node : network.nodes()) {
  copy.addNode(node);
 }
 for (E edge : network.edges()) {
  EndpointPair<N> endpointPair = network.incidentNodes(edge);
  copy.addEdge(endpointPair.nodeU(), endpointPair.nodeV(), edge);
 }
 return copy;
}

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

/**
 * Returns true if {@code network} has at least one cycle. A cycle is defined as a non-empty
 * subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges)
 * starting and ending with the same node.
 *
 * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1).
 */
public static boolean hasCycle(Network<?, ?> network) {
 // In a directed graph, parallel edges cannot introduce a cycle in an acyclic graph.
 // However, in an undirected graph, any parallel edge induces a cycle in the graph.
 if (!network.isDirected()
   && network.allowsParallelEdges()
   && network.edges().size() > network.asGraph().edges().size()) {
  return true;
 }
 return hasCycle(network.asGraph());
}

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

/**
 * Returns true if {@code network} has at least one cycle. A cycle is defined as a non-empty
 * subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges)
 * starting and ending with the same node.
 *
 * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1).
 */
public static boolean hasCycle(Network<?, ?> network) {
 // In a directed graph, parallel edges cannot introduce a cycle in an acyclic graph.
 // However, in an undirected graph, any parallel edge induces a cycle in the graph.
 if (!network.isDirected()
   && network.allowsParallelEdges()
   && network.edges().size() > network.asGraph().edges().size()) {
  return true;
 }
 return hasCycle(network.asGraph());
}

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

/** Creates a mutable copy of {@code network} with the same nodes and edges. */
public static <N, E> MutableNetwork<N, E> copyOf(Network<N, E> network) {
 MutableNetwork<N, E> copy =
   NetworkBuilder.from(network)
     .expectedNodeCount(network.nodes().size())
     .expectedEdgeCount(network.edges().size())
     .build();
 for (N node : network.nodes()) {
  copy.addNode(node);
 }
 for (E edge : network.edges()) {
  EndpointPair<N> endpointPair = network.incidentNodes(edge);
  copy.addEdge(endpointPair.nodeU(), endpointPair.nodeV(), edge);
 }
 return copy;
}

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

/** Creates a mutable copy of {@code network} with the same nodes and edges. */
public static <N, E> MutableNetwork<N, E> copyOf(Network<N, E> network) {
 MutableNetwork<N, E> copy =
   NetworkBuilder.from(network)
     .expectedNodeCount(network.nodes().size())
     .expectedEdgeCount(network.edges().size())
     .build();
 for (N node : network.nodes()) {
  copy.addNode(node);
 }
 for (E edge : network.edges()) {
  EndpointPair<N> endpointPair = network.incidentNodes(edge);
  copy.addEdge(endpointPair.nodeU(), endpointPair.nodeV(), edge);
 }
 return copy;
}

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

private static SortedSet<IsisEdge> getIsisEdges(
  Map<String, Configuration> configs, Topology topology) {
 Network<IsisNode, IsisEdge> isisTopology = IsisTopology.initIsisTopology(configs, topology);
 return isisTopology.edges().stream()
   .filter(Objects::nonNull)
   .collect(ImmutableSortedSet.toImmutableSortedSet(Comparator.naturalOrder()));
}

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

private static <N, E> Map<E, N> getEdgeToReferenceNode(Network<N, E> network) {
 // ImmutableMap.Builder maintains the order of the elements as inserted, so the map will have
 // whatever ordering the network's edges do, so ImmutableSortedMap is unnecessary even if the
 // input edges are sorted.
 ImmutableMap.Builder<E, N> edgeToReferenceNode = ImmutableMap.builder();
 for (E edge : network.edges()) {
  edgeToReferenceNode.put(edge, network.incidentNodes(edge).nodeU());
 }
 return edgeToReferenceNode.build();
}

代码示例来源:origin: jrtom/jung

public void setNetwork(Network<N, E> network, boolean forceUpdate) {
 log.trace("setNetwork to n:{} e:{}", network.nodes(), network.edges());
 this.network = network;
 this.layoutModel.setGraph(network.asGraph());
 if (forceUpdate && this.layoutAlgorithm != null) {
  log.trace("will accept {}", layoutAlgorithm);
  layoutModel.accept(this.layoutAlgorithm);
  log.trace("will fire stateChanged");
  changeSupport.fireStateChanged();
  log.trace("fired stateChanged");
 }
}

相关文章