本文整理汇总了Java中com.google.common.graph.MutableGraph.putEdge方法的典型用法代码示例。如果您正苦于以下问题:Java MutableGraph.putEdge方法的具体用法?Java MutableGraph.putEdge怎么用?Java MutableGraph.putEdge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.graph.MutableGraph
的用法示例。
在下文中一共展示了MutableGraph.putEdge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: trimClassGraph
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/** Removes all outgoing edges from classes that are not white listed. */
private static ImmutableGraph<String> trimClassGraph(
ImmutableGraph<String> classGraph, Pattern whiteList, Pattern blackList) {
MutableGraph<String> graph = GraphBuilder.directed().allowsSelfLoops(false).build();
for (String src : classGraph.nodes()) {
if (!whiteList.matcher(src).find() || blackList.matcher(src).find()) {
continue;
}
graph.addNode(src);
for (String dst : classGraph.successors(src)) {
if (blackList.matcher(dst).find()) {
continue;
}
graph.putEdge(src, dst);
}
}
return ImmutableGraph.copyOf(graph);
}
示例2: collapseInnerClasses
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/** Collapses inner classes into their top level parent class */
private static ImmutableGraph<String> collapseInnerClasses(ImmutableGraph<String> classGraph) {
MutableGraph<String> graph = GraphBuilder.directed().allowsSelfLoops(false).build();
for (String src : classGraph.nodes()) {
String outerSrc = getOuterClassName(src);
graph.addNode(outerSrc);
for (String dst : classGraph.successors(src)) {
String outerDst = getOuterClassName(dst);
if (outerSrc.equals(outerDst)) {
continue;
}
graph.putEdge(outerSrc, outerDst);
}
}
return ImmutableGraph.copyOf(graph);
}
示例3: createDepsGraph_periodInClassName
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
@Test
public void createDepsGraph_periodInClassName() throws IOException {
createSourceFiles("com/hello/", "com/hello/Dummy.java", "com/hello/ThreadSafety.java");
Path file1 =
writeFile(
workspace.resolve("com/hello/Dummy.java"),
"package com.hello;",
"import com.hello.ThreadSafety;",
"class Dummy {",
" @ThreadSafety.ThreadHostile",
" void methodA() {}",
"}");
JavaSourceFileParser parser = createParser(file1);
ImmutableGraph<String> actual = parser.getClassToClass();
MutableGraph<String> expected = newGraph();
expected.putEdge("com.hello.Dummy", "com.hello.ThreadSafety");
assertThatGraphsEqual(actual, expected);
assertThat(parser.getUnresolvedClassNames()).isEmpty();
}
示例4: bijectiveClassRuleMapping
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/** Tests behavior of graph processor when each class is mapped to its own build rule. */
@Test
public void bijectiveClassRuleMapping() {
MutableGraph<String> classgraph = GraphBuilder.directed().allowsSelfLoops(false).build();
classgraph.putEdge("com.A", "com.B");
classgraph.putEdge("com.B", "com.C");
GraphProcessor processor = new GraphProcessor(ImmutableGraph.copyOf(classgraph));
String packagePath = "/java/com/";
BuildRule ruleA = newBuildRule(packagePath, "/java/com/A.java");
BuildRule ruleB = newBuildRule(packagePath, "/java/com/B.java");
BuildRule ruleC = newBuildRule(packagePath, "/java/com/C.java");
ClassToRuleResolver resolver = mock(ClassToRuleResolver.class);
when(resolver.resolve(classgraph.nodes()))
.thenReturn(ImmutableMap.of("com.A", ruleA, "com.B", ruleB, "com.C", ruleC));
Graph<BuildRule> actual = processor.createBuildRuleDAG(ImmutableList.of(resolver));
MutableGraph<BuildRule> expected = GraphBuilder.directed().allowsSelfLoops(false).build();
expected.putEdge(ruleA, ruleB);
expected.putEdge(ruleB, ruleC);
assertThatGraphsEqual(actual, expected);
}
示例5: emptyMapping
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/**
* Tests behavior of graph processor when no classes are mapped to build rules. The resulting DAG
* should be empty.
*/
@Test
public void emptyMapping() {
MutableGraph<String> classgraph = GraphBuilder.directed().allowsSelfLoops(false).build();
classgraph.putEdge("com.A", "com.B");
classgraph.putEdge("com.B", "com.C");
classgraph.putEdge("com.C", "com.D");
GraphProcessor processor = new GraphProcessor(ImmutableGraph.copyOf(classgraph));
ClassToRuleResolver resolver = mock(ClassToRuleResolver.class);
when(resolver.resolve(classgraph.nodes())).thenReturn(ImmutableMap.of());
Graph<BuildRule> actual = processor.createBuildRuleDAG(ImmutableList.of(resolver));
assertThat(actual.nodes()).isEmpty();
assertThat(actual.edges()).isEmpty();
}
示例6: graphWithInnerClass
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/**
* Tests behavior of resolver on a graph when an inner class is provided. Resolver should throw an
* Illegal State Exception in this event.
*/
@Test
public void graphWithInnerClass() throws IOException {
MutableGraph<String> classgraph = newGraph(String.class);
classgraph.putEdge("com.A$hello", "com.B");
try {
newResolver(classgraph, WHITELIST_DEFAULT, ImmutableMap.of());
fail("Expected an exception, but nothing was thrown.");
} catch (IllegalStateException e) {
assertThat(e)
.hasMessageThat()
.isEqualTo(
"Argument contained inner class name com.A$hello but expected no inner classes");
}
}
示例7: classGraphWithSelfLoopsResultingInSingleSourceFile
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
@Test
public void classGraphWithSelfLoopsResultingInSingleSourceFile() {
MutableGraph<String> graph = newGraph(String.class);
graph.putEdge("com.A", "com.B");
graph.putEdge("com.B", "com.A");
Map<String, Path> map =
ImmutableMap.of(
"com.A", Paths.get("A.java"),
"com.B", Paths.get("A.java"));
Graph<Path> actual = ClassToSourceGraphConsolidator.map(graph, map);
MutableGraph<Path> expected = newGraph(Path.class);
expected.addNode(Paths.get("A.java"));
assertEquivalent(actual, expected);
}
示例8: trimRemovesBlackListedClasses
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/** Tests whether the black listed class names are removed from the class graph. */
@Test
public void trimRemovesBlackListedClasses() {
MutableGraph<String> graph = newGraph();
graph.putEdge("com.BlackList", "com.WhiteList");
graph.putEdge("com.WhiteList", "com.BlackList");
Pattern blackList = Pattern.compile("BlackList");
Graph<String> actual =
preProcessClassGraph(ImmutableGraph.copyOf(graph), EVERYTHING, blackList);
MutableGraph<String> expected = newGraph();
expected.addNode("com.WhiteList");
assertEquivalent(actual, expected);
assertThat(actual.nodes()).doesNotContain("com.BlackList");
}
示例9: collapseMaintainsDepsOfOtherClassesOnInnerClasses
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/**
* Ensures the dependencies of other classes on inner classes are retained. For example, if a
* class A depends on an inner class B$Inner. Then, in the resulting graph, class A must depend on
* class B.
*/
@Test
public void collapseMaintainsDepsOfOtherClassesOnInnerClasses() {
MutableGraph<String> graph = newGraph();
graph.putEdge("Class", "Class$Inner");
graph.putEdge("OtherClass", "Class$Inner");
Graph<String> actual = preProcessClassGraph(ImmutableGraph.copyOf(graph), EVERYTHING, NOTHING);
assertThat(actual.nodes()).containsExactly("OtherClass", "Class");
assertThat(actual.edges()).containsExactly(EndpointPair.ordered("OtherClass", "Class"));
}
示例10: multipleResolversWithDifferingResolutions
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/**
* Tests behavior when a class is mapped to multiple build rules. The Graph Processor should
* ignore the mapping of the secondary resolver. This also tests whether the resolvers are called
* in an appropriate fashion. The first resolver should be called on the entire class graph. The
* second resolver should be called on an empty set. If it is called on any other argument, then
* this test will throw either a GraphProcessorException or a NullPointerException.
*/
@Test
public void multipleResolversWithDifferingResolutions() {
MutableGraph<String> classgraph = GraphBuilder.directed().allowsSelfLoops(false).build();
classgraph.putEdge("com.A", "com.B");
GraphProcessor processor = new GraphProcessor(ImmutableGraph.copyOf(classgraph));
String packagePath = "/java/com/";
BuildRule ruleA = newBuildRule(packagePath, "/java/com/A.java");
BuildRule ruleB = newBuildRule(packagePath, "/java/com/B.java");
ClassToRuleResolver resolver1 = mock(ClassToRuleResolver.class);
when(resolver1.resolve(classgraph.nodes()))
.thenReturn(ImmutableMap.of("com.A", ruleA, "com.B", ruleB));
ClassToRuleResolver resolver2 = mock(ClassToRuleResolver.class);
when(resolver2.resolve(classgraph.nodes())).thenReturn(ImmutableMap.of("com.B", ruleA));
when(resolver2.resolve(ImmutableSet.of())).thenReturn(ImmutableMap.of());
try {
Graph<BuildRule> actual =
processor.createBuildRuleDAG(ImmutableList.of(resolver1, resolver2));
MutableGraph<BuildRule> expected = GraphBuilder.directed().allowsSelfLoops(false).build();
expected.putEdge(ruleA, ruleB);
assertThatGraphsEqual(actual, expected);
} catch (GraphProcessorException e) {
fail(
"Threw a run time exception when class was mapped by multiple resolvers"
+ "Class should have been ignored after first resolver.");
}
}
示例11: putOnCycle
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/** Create a cycle in 'graph' comprised of classes from 'classes'. */
private static void putOnCycle(Collection<String> classes, MutableGraph<String> graph) {
if (classes.size() == 1) {
return;
}
ImmutableList<String> sortedClasses = Ordering.natural().immutableSortedCopy(classes);
for (int i = 1; i < sortedClasses.size(); i++) {
graph.putEdge(sortedClasses.get(i - 1), sortedClasses.get(i));
}
graph.putEdge(getLast(sortedClasses), sortedClasses.get(0));
}
示例12: multipleResolversWithOverlappingResolutions
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/**
* Tests behavior when multiple resolvers are used and they could potentially resolve overlapping
* classes. The second resolver if called with no argument, should error out. However, we want to
* assert that it is instead called with an argument (a set of classes to execute on).
*/
@Test
public void multipleResolversWithOverlappingResolutions() {
MutableGraph<String> classgraph = GraphBuilder.directed().allowsSelfLoops(false).build();
classgraph.putEdge("com.A", "com.B");
classgraph.putEdge("com.B", "com.C");
GraphProcessor processor = new GraphProcessor(ImmutableGraph.copyOf(classgraph));
String packagePath = "/java/com/";
BuildRule ruleA = newBuildRule(packagePath, "/java/com/A.java");
BuildRule ruleB = newBuildRule(packagePath, "/java/com/B.java");
BuildRule ruleC = newBuildRule(packagePath, "/java/com/C.java");
ClassToRuleResolver resolver = mock(ClassToRuleResolver.class);
when(resolver.resolve(classgraph.nodes()))
.thenReturn(ImmutableMap.of("com.A", ruleA, "com.B", ruleB));
ClassToRuleResolver resolver2 = mock(ClassToRuleResolver.class);
when(resolver2.resolve(classgraph.nodes()))
.thenReturn(ImmutableMap.of("com.B", ruleB, "com.C", ruleC));
when(resolver2.resolve(ImmutableSet.of("com.C"))).thenReturn(ImmutableMap.of("com.C", ruleC));
try {
Graph<BuildRule> actual = processor.createBuildRuleDAG(ImmutableList.of(resolver, resolver2));
MutableGraph<BuildRule> expected = GraphBuilder.directed().allowsSelfLoops(false).build();
expected.putEdge(ruleA, ruleB);
expected.putEdge(ruleB, ruleC);
assertThatGraphsEqual(actual, expected);
} catch (GraphProcessorException e) {
fail(
"Threw a run time exception when class was mapped by multiple resolvers"
+ "Class should have been ignored after first resolver.");
}
}
示例13: simpleDAGWithUniqueTargets
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/**
* Tests behavior of resolver on a graph where each class is uniquely mapped to a target.
* Resulting map should have each class uniquely mapped to a build rule.
*/
@Test
public void simpleDAGWithUniqueTargets() throws IOException {
MutableGraph<String> classgraph = newGraph(String.class);
classgraph.putEdge("com.A", "com.B");
classgraph.putEdge("com.B", "com.C");
ProjectClassToRuleResolver resolver =
newResolver(
classgraph,
WHITELIST_DEFAULT,
ImmutableMap.of(
"com.A",
workspace.resolve("java/com/A.java"),
"com.B",
workspace.resolve("java/com/B.java"),
"com.C",
workspace.resolve("java/com/C.java")));
ImmutableMap<String, BuildRule> actual = resolver.resolve(classgraph.nodes());
String packagePath = "/src/java/com/";
BuildRule ruleA = buildRule(packagePath, "/src/java/com/A.java");
BuildRule ruleB = buildRule(packagePath, "/src/java/com/B.java");
BuildRule ruleC = buildRule(packagePath, "/src/java/com/C.java");
assertThat(actual).containsExactly("com.A", ruleA, "com.B", ruleB, "com.C", ruleC);
}
示例14: collapseRemovesInnerClasses
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/** Ensures there are no inner classes outputted in preprocessed class graph */
@Test
public void collapseRemovesInnerClasses() {
MutableGraph<String> graph = newGraph();
graph.putEdge("Class", "Class$Inner");
graph.putEdge("Class$Inner", "Class");
Graph<String> actual = preProcessClassGraph(ImmutableGraph.copyOf(graph), EVERYTHING, NOTHING);
assertThat(actual.nodes()).containsExactly("Class");
assertThat(actual.edges()).isEmpty();
}
示例15: ignoresUnresolvedClass_exceedsThreshold
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/**
* If a class's source file cannot be found, then that class name should not be in the ensuing
* class. If more than the default threshold are unresolved, then it BFG should error out.
*/
@Test
public void ignoresUnresolvedClass_exceedsThreshold() throws IOException {
MutableGraph<String> classgraph = newGraph(String.class);
classgraph.putEdge("com.A", "com.DoesNotExist");
classgraph.putEdge("com.A", "com.DoesNotExistTwo");
classgraph.putEdge("com.A", "com.DoesNotExistThree");
ProjectClassToRuleResolver resolver =
newResolver(
classgraph,
WHITELIST_DEFAULT,
ImmutableMap.of("com.A", workspace.resolve("java/com/A.java")));
try {
resolver.resolve(classgraph.nodes());
fail("Expected an exception, but nothing was thrown.");
} catch (IllegalStateException e) {
assertThat(e)
.hasMessageThat()
.isEqualTo(
String.format(
"BUILD File Generator failed to map over %.0f percent of class names. "
+ "Check your white list and content roots",
UNRESOLVED_THRESHOLD * 100));
}
}