Skip to content

Commit

Permalink
Move Graphs.selfLoopPredicate() to GraphsTest.java
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=124271785
  • Loading branch information
kluever authored and cpovirk committed Jun 8, 2016
1 parent 477f645 commit 015fbbd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
18 changes: 17 additions & 1 deletion guava-tests/test/com/google/common/graph/GraphsTest.java
Expand Up @@ -16,12 +16,12 @@

package com.google.common.graph;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.graph.Graphs.addEdge;
import static com.google.common.graph.Graphs.copyOf;
import static com.google.common.graph.Graphs.mergeEdgesFrom;
import static com.google.common.graph.Graphs.mergeNodesFrom;
import static com.google.common.graph.Graphs.oppositeNode;
import static com.google.common.graph.Graphs.selfLoopPredicate;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;

Expand Down Expand Up @@ -71,6 +71,22 @@ public class GraphsTest {
"Should not be allowed to add a self-loop edge.";
static final String ERROR_SELF_LOOP = "self-loops are not allowed";

/**
* Returns a {@link Predicate} that returns {@code true} if the input edge is a self-loop in
* {@code graph}. A self-loop is defined as an edge whose set of incident nodes has exactly one
* element. The predicate's {@code apply} method will throw an {@link IllegalArgumentException} if
* {@code graph} does not contain {@code edge}.
*/
private static <E> Predicate<E> selfLoopPredicate(final Network<?, E> graph) {
checkNotNull(graph, "graph");
return new Predicate<E>() {
@Override
public boolean apply(E edge) {
return (graph.incidentNodes(edge).size() == 1);
}
};
}

@Test
public void oppositeNode_basic() {
List<MutableNetwork<Integer, String>> testNetworks = ImmutableList.of(
Expand Down
16 changes: 0 additions & 16 deletions guava/src/com/google/common/graph/Graphs.java
Expand Up @@ -375,22 +375,6 @@ public static String toString(Network<?, ?> graph) {
Maps.asMap(graph.edges(), edgeToIncidentNodesString(graph)));
}

/**
* Returns a {@link Predicate} that returns {@code true} if the input edge is a self-loop in
* {@code graph}. A self-loop is defined as an edge whose set of incident nodes has exactly one
* element. The predicate's {@code apply} method will throw an {@link IllegalArgumentException} if
* {@code graph} does not contain {@code edge}.
*/
public static <E> Predicate<E> selfLoopPredicate(final Network<?, E> graph) {
checkNotNull(graph, "graph");
return new Predicate<E>() {
@Override
public boolean apply(E edge) {
return (graph.incidentNodes(edge).size() == 1);
}
};
}

/**
* Returns a String of the adjacent node relationships for {@code graph}.
*/
Expand Down

0 comments on commit 015fbbd

Please sign in to comment.