/** * Returns a view of {@code graph} with the direction (if any) of every edge reversed. All other * properties remain intact, and further updates to {@code graph} will be reflected in the view. */ public static <N, V> ValueGraph<N, V> transpose(ValueGraph<N, V> graph) { if (!graph.isDirected()) { return graph; // the transpose of an undirected graph is an identical graph } if (graph instanceof TransposedValueGraph) { return ((TransposedValueGraph<N, V>) graph).graph; } return new TransposedValueGraph<>(graph); }
@Override public boolean isDirected() { return delegate().isDirected(); }
/** * Returns a view of {@code graph} with the direction (if any) of every edge reversed. All other * properties remain intact, and further updates to {@code graph} will be reflected in the view. */ public static <N, V> ValueGraph<N, V> transpose(ValueGraph<N, V> graph) { if (!graph.isDirected()) { return graph; // the transpose of an undirected graph is an identical graph } if (graph instanceof TransposedValueGraph) { return ((TransposedValueGraph<N, V>) graph).graph; } return new TransposedValueGraph<>(graph); }
@Override public boolean isDirected() { return delegate().isDirected(); }
@Override public boolean isDirected() { return delegate().isDirected(); }
/** * Returns a view of {@code graph} with the direction (if any) of every edge reversed. All other * properties remain intact, and further updates to {@code graph} will be reflected in the view. */ public static <N, V> ValueGraph<N, V> transpose(ValueGraph<N, V> graph) { if (!graph.isDirected()) { return graph; // the transpose of an undirected graph is an identical graph } if (graph instanceof TransposedValueGraph) { return ((TransposedValueGraph<N, V>) graph).graph; } return new TransposedValueGraph<>(graph); }
@Override public final boolean equals(@Nullable Object obj) { if (obj == this) { return true; } if (!(obj instanceof ValueGraph)) { return false; } ValueGraph<?, ?> other = (ValueGraph<?, ?>) obj; return isDirected() == other.isDirected() && nodes().equals(other.nodes()) && edgeValueMap(this).equals(edgeValueMap(other)); }
/** * Returns a {@link ValueGraphBuilder} initialized with all properties queryable from {@code * graph}. * * <p>The "queryable" properties are those that are exposed through the {@link ValueGraph} * interface, such as {@link ValueGraph#isDirected()}. Other properties, such as {@link * #expectedNodeCount(int)}, are not set in the new builder. */ public static <N, V> ValueGraphBuilder<N, V> from(ValueGraph<N, V> graph) { return new ValueGraphBuilder<N, V>(graph.isDirected()) .allowsSelfLoops(graph.allowsSelfLoops()) .nodeOrder(graph.nodeOrder()); }
@Override public final boolean equals(@NullableDecl Object obj) { if (obj == this) { return true; } if (!(obj instanceof ValueGraph)) { return false; } ValueGraph<?, ?> other = (ValueGraph<?, ?>) obj; return isDirected() == other.isDirected() && nodes().equals(other.nodes()) && edgeValueMap(this).equals(edgeValueMap(other)); }
@Override public final boolean equals(@NullableDecl Object obj) { if (obj == this) { return true; } if (!(obj instanceof ValueGraph)) { return false; } ValueGraph<?, ?> other = (ValueGraph<?, ?>) obj; return isDirected() == other.isDirected() && nodes().equals(other.nodes()) && edgeValueMap(this).equals(edgeValueMap(other)); }
private static <N, V> GraphConnections<N, V> connectionsOf( final ValueGraph<N, V> graph, final N node) { Function<N, V> successorNodeToValueFn = new Function<N, V>() { @Override public V apply(N successorNode) { return graph.edgeValueOrDefault(node, successorNode, null); } }; return graph.isDirected() ? DirectedGraphConnections.ofImmutable( graph.predecessors(node), Maps.asMap(graph.successors(node), successorNodeToValueFn)) : UndirectedGraphConnections.ofImmutable( Maps.asMap(graph.adjacentNodes(node), successorNodeToValueFn)); } }
/** * Returns a {@link ValueGraphBuilder} initialized with all properties queryable from {@code * graph}. * * <p>The "queryable" properties are those that are exposed through the {@link ValueGraph} * interface, such as {@link ValueGraph#isDirected()}. Other properties, such as {@link * #expectedNodeCount(int)}, are not set in the new builder. */ public static <N, V> ValueGraphBuilder<N, V> from(ValueGraph<N, V> graph) { return new ValueGraphBuilder<N, V>(graph.isDirected()) .allowsSelfLoops(graph.allowsSelfLoops()) .nodeOrder(graph.nodeOrder()); }
/** * Returns a {@link ValueGraphBuilder} initialized with all properties queryable from {@code * graph}. * * <p>The "queryable" properties are those that are exposed through the {@link ValueGraph} * interface, such as {@link ValueGraph#isDirected()}. Other properties, such as {@link * #expectedNodeCount(int)}, are not set in the new builder. */ public static <N, V> ValueGraphBuilder<N, V> from(ValueGraph<N, V> graph) { return new ValueGraphBuilder<N, V>(graph.isDirected()) .allowsSelfLoops(graph.allowsSelfLoops()) .nodeOrder(graph.nodeOrder()); }
private static <N, V> GraphConnections<N, V> connectionsOf( final ValueGraph<N, V> graph, final N node) { Function<N, V> successorNodeToValueFn = new Function<N, V>() { @Override public V apply(N successorNode) { return graph.edgeValueOrDefault(node, successorNode, null); } }; return graph.isDirected() ? DirectedGraphConnections.ofImmutable( graph.predecessors(node), Maps.asMap(graph.successors(node), successorNodeToValueFn)) : UndirectedGraphConnections.ofImmutable( Maps.asMap(graph.adjacentNodes(node), successorNodeToValueFn)); } }
private static <N, V> GraphConnections<N, V> connectionsOf( final ValueGraph<N, V> graph, final N node) { Function<N, V> successorNodeToValueFn = new Function<N, V>() { @Override public V apply(N successorNode) { return graph.edgeValueOrDefault(node, successorNode, null); } }; return graph.isDirected() ? DirectedGraphConnections.ofImmutable( graph.predecessors(node), Maps.asMap(graph.successors(node), successorNodeToValueFn)) : UndirectedGraphConnections.ofImmutable( Maps.asMap(graph.adjacentNodes(node), successorNodeToValueFn)); } }
/** * Returns a view of {@code graph} with the direction (if any) of every edge reversed. All other * properties remain intact, and further updates to {@code graph} will be reflected in the view. */ public static <N, V> ValueGraph<N, V> transpose(ValueGraph<N, V> graph) { if (!graph.isDirected()) { return graph; // the transpose of an undirected graph is an identical graph } if (graph instanceof TransposedValueGraph) { return ((TransposedValueGraph<N, V>) graph).graph; } return new TransposedValueGraph<>(graph); }
/** * Create an edge * * @param s the source vertex * @param t the target vertex * @return the edge */ final EndpointPair<V> createEdge(V s, V t) { return valueGraph.isDirected() ? EndpointPair.ordered(s, t) : EndpointPair.unordered(s, t); }
@Override public final boolean equals(@NullableDecl Object obj) { if (obj == this) { return true; } if (!(obj instanceof ValueGraph)) { return false; } ValueGraph<?, ?> other = (ValueGraph<?, ?>) obj; return isDirected() == other.isDirected() && nodes().equals(other.nodes()) && edgeValueMap(this).equals(edgeValueMap(other)); }
@Override public final boolean equals(@Nullable Object obj) { if (obj == this) { return true; } if (!(obj instanceof ValueGraph)) { return false; } ValueGraph<?, ?> other = (ValueGraph<?, ?>) obj; return isDirected() == other.isDirected() && nodes().equals(other.nodes()) && edgeValueMap(this).equals(edgeValueMap(other)); }
@Override public GraphType getType() { return (valueGraph.isDirected() ? new DefaultGraphType.Builder().directed() : new DefaultGraphType.Builder().undirected()) .weighted(true).allowMultipleEdges(false) .allowSelfLoops(valueGraph.allowsSelfLoops()).build(); }