Skip to content

Commit

Permalink
Rename ValueGraph to Graph.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=130546021
  • Loading branch information
Bezier89 authored and cpovirk committed Aug 17, 2016
1 parent c3f9fef commit 41becc6
Show file tree
Hide file tree
Showing 24 changed files with 145 additions and 147 deletions.
Expand Up @@ -122,7 +122,7 @@ public void validateGraphState() {
validateGraph(graph);
}

static <N> void validateGraph(ValueGraph<N, ?> graph) {
static <N> void validateGraph(Graph<N, ?> graph) {
if (graph instanceof BasicGraph) {
@SuppressWarnings("unchecked")
BasicGraph<N> basicGraph = (BasicGraph<N>) graph;
Expand Down
Expand Up @@ -157,7 +157,7 @@ public void validateNetworkState() {
String nodeString = networkString.substring(nodeStart, edgeStart);
String edgeString = networkString.substring(edgeStart);

ValueGraph<Integer, Set<String>> asGraph = network.asGraph();
Graph<Integer, Set<String>> asGraph = network.asGraph();
AbstractGraphTest.validateGraph(asGraph);
assertThat(network.nodes()).isEqualTo(asGraph.nodes());
assertThat(network.edges().size()).isAtLeast(asGraph.edges().size());
Expand Down
Expand Up @@ -26,7 +26,7 @@
import org.junit.runners.JUnit4;

/**
* Tests for {@link Graphs#hasCycle(ValueGraph)} and {@link Graphs#hasCycle(Network)}.
* Tests for {@link Graphs#hasCycle(Graph)} and {@link Graphs#hasCycle(Network)}.
*/
// TODO(user): Consider moving this to GraphsTest.
@RunWith(JUnit4.class)
Expand Down
Expand Up @@ -26,19 +26,19 @@
import org.junit.runners.JUnit4;

/**
* Tests for {@link ConfigurableMutableValueGraph} and related functionality.
* Tests for {@link ConfigurableMutableGraph} and related functionality.
*/
// TODO(user): Expand coverage and move to proper test suite.
@RunWith(JUnit4.class)
public final class ValueGraphTest {
MutableValueGraph<Integer, String> graph;
public final class GraphTest {
MutableGraph<Integer, String> graph;

@After
public void validateGraphState() {
new EqualsTester().addEqualityGroup(
graph,
Graphs.copyOf(graph),
ImmutableValueGraph.copyOf(graph)).testEquals();
ImmutableGraph.copyOf(graph)).testEquals();

for (Endpoints<Integer> edge : graph.edges()) {
assertThat(graph.edgeValue(edge.nodeA(), edge.nodeB())).isNotNull();
Expand All @@ -48,8 +48,8 @@ public void validateGraphState() {
}

@Test
public void directedValueGraph() {
graph = ValueGraphBuilder.directed().allowsSelfLoops(true).build();
public void directedGraph() {
graph = GraphBuilder.directed().allowsSelfLoops(true).build();
graph.putEdgeValue(1, 2, "valueA");
graph.putEdgeValue(2, 1, "valueB");
graph.putEdgeValue(2, 3, "valueC");
Expand All @@ -68,8 +68,8 @@ public void directedValueGraph() {
}

@Test
public void undirectedValueGraph() {
graph = ValueGraphBuilder.undirected().allowsSelfLoops(true).build();
public void undirectedGraph() {
graph = GraphBuilder.undirected().allowsSelfLoops(true).build();
graph.putEdgeValue(1, 2, "valueA");
graph.putEdgeValue(2, 1, "valueB"); // overwrites valueA in undirected case
graph.putEdgeValue(2, 3, "valueC");
Expand All @@ -89,7 +89,7 @@ public void undirectedValueGraph() {

@Test
public void putEdgeValue_directed() {
graph = ValueGraphBuilder.directed().build();
graph = GraphBuilder.directed().build();

assertThat(graph.putEdgeValue(1, 2, "valueA")).isNull();
assertThat(graph.putEdgeValue(2, 1, "valueB")).isNull();
Expand All @@ -99,7 +99,7 @@ public void putEdgeValue_directed() {

@Test
public void putEdgeValue_undirected() {
graph = ValueGraphBuilder.undirected().build();
graph = GraphBuilder.undirected().build();

assertThat(graph.putEdgeValue(1, 2, "valueA")).isNull();
assertThat(graph.putEdgeValue(2, 1, "valueB")).isEqualTo("valueA");
Expand All @@ -109,7 +109,7 @@ public void putEdgeValue_undirected() {

@Test
public void removeEdge_directed() {
graph = ValueGraphBuilder.directed().build();
graph = GraphBuilder.directed().build();
graph.putEdgeValue(1, 2, "valueA");
graph.putEdgeValue(2, 1, "valueB");
graph.putEdgeValue(2, 3, "valueC");
Expand All @@ -124,7 +124,7 @@ public void removeEdge_directed() {

@Test
public void removeEdge_undirected() {
graph = ValueGraphBuilder.undirected().build();
graph = GraphBuilder.undirected().build();
graph.putEdgeValue(1, 2, "valueA");
graph.putEdgeValue(2, 1, "valueB");
graph.putEdgeValue(2, 3, "valueC");
Expand All @@ -138,7 +138,7 @@ public void removeEdge_undirected() {

@Test
public void edgeValue_edgeNotPresent() {
graph = ValueGraphBuilder.directed().build();
graph = GraphBuilder.directed().build();
graph.addNode(1);
graph.addNode(2);

Expand All @@ -152,7 +152,7 @@ public void edgeValue_edgeNotPresent() {

@Test
public void edgeValue_nodeNotPresent() {
graph = ValueGraphBuilder.undirected().build();
graph = GraphBuilder.undirected().build();
graph.putEdgeValue(1, 2, "value");

try {
Expand All @@ -165,7 +165,7 @@ public void edgeValue_nodeNotPresent() {

@Test
public void edgeValueOrDefault() {
graph = ValueGraphBuilder.directed().build();
graph = GraphBuilder.directed().build();

graph.addNode(1);
graph.addNode(2);
Expand Down
52 changes: 26 additions & 26 deletions guava-tests/test/com/google/common/graph/GraphsTest.java
Expand Up @@ -336,7 +336,7 @@ public void adjacentEdges_unmodifiableView() {
}

@Test
public void inducedSubgraph_Graph() {
public void inducedSubgraph_BasicGraph() {
Set<Integer> nodeSubset = ImmutableSet.of(N1, N2, N4);

MutableBasicGraph<Integer> directedGraph = BasicGraphBuilder.directed().build();
Expand All @@ -355,17 +355,17 @@ public void inducedSubgraph_Graph() {
}

@Test
public void inducedSubgraph_ValueGraph() {
public void inducedSubgraph_Graph() {
Set<Integer> nodeSubset = ImmutableSet.of(N1, N2, N4);

MutableValueGraph<Integer, String> directedGraph = ValueGraphBuilder.directed().build();
MutableGraph<Integer, String> directedGraph = GraphBuilder.directed().build();
directedGraph.putEdgeValue(N1, N2, E12);
directedGraph.putEdgeValue(N2, N1, E21);
directedGraph.putEdgeValue(N1, N3, E13); // only incident to one node in nodeSubset
directedGraph.putEdgeValue(N4, N4, E44);
directedGraph.putEdgeValue(5, 6, "5-6"); // not incident to any node in nodeSubset

MutableValueGraph<Integer, String> expectedSubgraph = ValueGraphBuilder.directed().build();
MutableGraph<Integer, String> expectedSubgraph = GraphBuilder.directed().build();
expectedSubgraph.putEdgeValue(N1, N2, E12);
expectedSubgraph.putEdgeValue(N2, N1, E21);
expectedSubgraph.putEdgeValue(N4, N4, E44);
Expand Down Expand Up @@ -413,48 +413,48 @@ public void copyOf_nullArgument() {
}

@Test
public void copyOf_directedGraph() {
BasicGraph<Integer> directedGraph = buildDirectedTestGraph();
public void copyOf_directedBasicGraph() {
BasicGraph<Integer> directedGraph = buildDirectedBasicGraph();

BasicGraph<Integer> copy = copyOf(directedGraph);
assertThat(copy).isEqualTo(directedGraph);
}

@Test
public void copyOf_undirectedGraph() {
BasicGraph<Integer> undirectedGraph = buildUndirectedTestGraph();
public void copyOf_undirectedBasicGraph() {
BasicGraph<Integer> undirectedGraph = buildUndirectedBasicGraph();

BasicGraph<Integer> copy = copyOf(undirectedGraph);
assertThat(copy).isEqualTo(undirectedGraph);
}

@Test
public void copyOf_directedValueGraph() {
ValueGraph<Integer, String> directedGraph = buildDirectedTestValueGraph();
public void copyOf_directedGraph() {
Graph<Integer, String> directedGraph = buildDirectedGraph();

ValueGraph<Integer, String> copy = copyOf(directedGraph);
Graph<Integer, String> copy = copyOf(directedGraph);
assertThat(copy).isEqualTo(directedGraph);
}

@Test
public void copyOf_undirectedValueGraph() {
ValueGraph<Integer, String> undirectedGraph = buildUndirectedTestValueGraph();
public void copyOf_undirectedGraph() {
Graph<Integer, String> undirectedGraph = buildUndirectedGraph();

ValueGraph<Integer, String> copy = copyOf(undirectedGraph);
Graph<Integer, String> copy = copyOf(undirectedGraph);
assertThat(copy).isEqualTo(undirectedGraph);
}

@Test
public void copyOf_directedNetwork() {
Network<Integer, String> directedGraph = buildDirectedTestNetwork();
Network<Integer, String> directedGraph = buildDirectedNetwork();

Network<Integer, String> copy = copyOf(directedGraph);
assertThat(copy).isEqualTo(directedGraph);
}

@Test
public void copyOf_undirectedNetwork() {
Network<Integer, String> undirectedGraph = buildUndirectedTestNetwork();
Network<Integer, String> undirectedGraph = buildUndirectedNetwork();

Network<Integer, String> copy = copyOf(undirectedGraph);
assertThat(copy).isEqualTo(undirectedGraph);
Expand Down Expand Up @@ -619,7 +619,7 @@ private static <N> void checkTransitiveClosure(
assertThat(transitiveClosure(originalGraph)).isEqualTo(expectedClosure);
}

private static MutableBasicGraph<Integer> buildDirectedTestGraph() {
private static MutableBasicGraph<Integer> buildDirectedBasicGraph() {
MutableBasicGraph<Integer> directedGraph =
BasicGraphBuilder.directed().allowsSelfLoops(true).build();
directedGraph.putEdge(N1, N1);
Expand All @@ -629,7 +629,7 @@ private static MutableBasicGraph<Integer> buildDirectedTestGraph() {
return directedGraph;
}

private static MutableBasicGraph<Integer> buildUndirectedTestGraph() {
private static MutableBasicGraph<Integer> buildUndirectedBasicGraph() {
MutableBasicGraph<Integer> undirectedGraph =
BasicGraphBuilder.undirected().allowsSelfLoops(true).build();
undirectedGraph.putEdge(N1, N1);
Expand All @@ -639,27 +639,27 @@ private static MutableBasicGraph<Integer> buildUndirectedTestGraph() {
return undirectedGraph;
}

private static MutableValueGraph<Integer, String> buildDirectedTestValueGraph() {
MutableValueGraph<Integer, String> directedGraph =
ValueGraphBuilder.directed().allowsSelfLoops(true).build();
private static MutableGraph<Integer, String> buildDirectedGraph() {
MutableGraph<Integer, String> directedGraph =
GraphBuilder.directed().allowsSelfLoops(true).build();
directedGraph.putEdgeValue(N1, N1, E11);
directedGraph.putEdgeValue(N1, N2, E12);
directedGraph.putEdgeValue(N2, N1, E21);

return directedGraph;
}

private static MutableValueGraph<Integer, String> buildUndirectedTestValueGraph() {
MutableValueGraph<Integer, String> undirectedGraph =
ValueGraphBuilder.undirected().allowsSelfLoops(true).build();
private static MutableGraph<Integer, String> buildUndirectedGraph() {
MutableGraph<Integer, String> undirectedGraph =
GraphBuilder.undirected().allowsSelfLoops(true).build();
undirectedGraph.putEdgeValue(N1, N1, E11);
undirectedGraph.putEdgeValue(N1, N2, E12);
undirectedGraph.putEdgeValue(N2, N1, E21); // overwrites E12

return undirectedGraph;
}

private static MutableNetwork<Integer, String> buildDirectedTestNetwork() {
private static MutableNetwork<Integer, String> buildDirectedNetwork() {
MutableNetwork<Integer, String> directedGraph =
NetworkBuilder.directed().allowsSelfLoops(true).allowsParallelEdges(true).build();
directedGraph.addEdge(N1, N1, E11);
Expand All @@ -671,7 +671,7 @@ private static MutableNetwork<Integer, String> buildDirectedTestNetwork() {
return directedGraph;
}

private static MutableNetwork<Integer, String> buildUndirectedTestNetwork() {
private static MutableNetwork<Integer, String> buildUndirectedNetwork() {
MutableNetwork<Integer, String> undirectedGraph =
NetworkBuilder.undirected().allowsSelfLoops(true).allowsParallelEdges(true).build();
undirectedGraph.addEdge(N1, N1, E11);
Expand Down
Expand Up @@ -32,7 +32,7 @@ public class PackageSanityTests extends AbstractPackageSanityTests {
private static final AbstractGraphBuilder<?> GRAPH_BUILDER_A =
BasicGraphBuilder.directed().expectedNodeCount(10);
private static final AbstractGraphBuilder<?> GRAPH_BUILDER_B =
ValueGraphBuilder.directed().allowsSelfLoops(false).expectedNodeCount(16);
GraphBuilder.directed().allowsSelfLoops(false).expectedNodeCount(16);

private static final ImmutableBasicGraph<String> IMMUTABLE_GRAPH_A = graphWithNode("A");
private static final ImmutableBasicGraph<String> IMMUTABLE_GRAPH_B = graphWithNode("B");
Expand Down
2 changes: 1 addition & 1 deletion guava/src/com/google/common/graph/AbstractBasicGraph.java
Expand Up @@ -32,7 +32,7 @@
*/
@Beta
public abstract class AbstractBasicGraph<N>
extends AbstractValueGraph<N, Presence> implements BasicGraph<N> {
extends AbstractGraph<N, Presence> implements BasicGraph<N> {

/**
* Returns a string representation of this graph.
Expand Down
Expand Up @@ -31,8 +31,8 @@
import javax.annotation.Nullable;

/**
* This class provides a skeletal implementation of {@link ValueGraph}. It is recommended to extend
* this class rather than implement {@link ValueGraph} directly, to ensure consistent {@link
* This class provides a skeletal implementation of {@link Graph}. It is recommended to extend
* this class rather than implement {@link Graph} directly, to ensure consistent {@link
* #equals(Object)} and {@link #hashCode()} results across different graph implementations.
*
* @author James Sexton
Expand All @@ -41,7 +41,7 @@
* @since 20.0
*/
@Beta
public abstract class AbstractValueGraph<N, V> implements ValueGraph<N, V> {
public abstract class AbstractGraph<N, V> implements Graph<N, V> {

/**
* Returns the number of edges in this graph; used to calculate the size of {@link #edges()}.
Expand All @@ -59,15 +59,15 @@ protected long edgeCount() {
}

/**
* A reasonable default implementation of {@link ValueGraph#edges()} defined in terms of
* A reasonable default implementation of {@link Graph#edges()} defined in terms of
* {@link #nodes()} and {@link #successors(Object)}.
*/
@Override
public Set<Endpoints<N>> edges() {
return new AbstractSet<Endpoints<N>>() {
@Override
public Iterator<Endpoints<N>> iterator() {
return EndpointsIterator.of(AbstractValueGraph.this);
return EndpointsIterator.of(AbstractGraph.this);
}

@Override
Expand All @@ -94,10 +94,10 @@ public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof ValueGraph)) {
if (!(obj instanceof Graph)) {
return false;
}
ValueGraph<?, ?> other = (ValueGraph<?, ?>) obj;
Graph<?, ?> other = (Graph<?, ?>) obj;

if (isDirected() != other.isDirected()
|| !nodes().equals(other.nodes())
Expand Down Expand Up @@ -152,7 +152,7 @@ public V apply(Endpoints<N> edge) {
* @throws IllegalArgumentException if {@code node} is not an element of this graph
*/
// TODO(b/30649235): What to do with this? Move to Graphs or interfaces? Provide in/outDegree?
private static int degree(ValueGraph<?, ?> graph, Object node) {
private static int degree(Graph<?, ?> graph, Object node) {
if (graph.isDirected()) {
return IntMath.saturatedAdd(graph.predecessors(node).size(), graph.successors(node).size());
} else {
Expand Down
4 changes: 2 additions & 2 deletions guava/src/com/google/common/graph/AbstractNetwork.java
Expand Up @@ -42,8 +42,8 @@
public abstract class AbstractNetwork<N, E> implements Network<N, E> {

@Override
public ValueGraph<N, Set<E>> asGraph() {
return new AbstractValueGraph<N, Set<E>>() {
public Graph<N, Set<E>> asGraph() {
return new AbstractGraph<N, Set<E>>() {
@Override
public Set<N> nodes() {
return AbstractNetwork.this.nodes();
Expand Down
2 changes: 1 addition & 1 deletion guava/src/com/google/common/graph/BasicGraph.java
Expand Up @@ -168,7 +168,7 @@
* @since 20.0
*/
@Beta
public interface BasicGraph<N> extends ValueGraph<N, BasicGraph.Presence> {
public interface BasicGraph<N> extends Graph<N, BasicGraph.Presence> {

/**
* A placeholder for the (generally ignored) Value type of a {@link BasicGraph}. Users shouldn't
Expand Down

0 comments on commit 41becc6

Please sign in to comment.