当前位置: 首页>>代码示例>>Java>>正文


Java MutableGraph.putEdge方法代码示例

本文整理汇总了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);
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:19,代码来源:ClassGraphPreprocessor.java

示例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);
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:17,代码来源:ClassGraphPreprocessor.java

示例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();
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:22,代码来源:JavaSourceFileParserTest.java

示例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);
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:26,代码来源:GraphProcessorTest.java

示例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();
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:21,代码来源:GraphProcessorTest.java

示例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");
  }
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:20,代码来源:ProjectClassToRuleResolverTest.java

示例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);
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:18,代码来源:ClassToSourceGraphConsolidatorTest.java

示例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");
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:19,代码来源:ClassGraphPreprocessorTest.java

示例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"));
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:17,代码来源:ClassGraphPreprocessorTest.java

示例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.");
  }
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:38,代码来源:GraphProcessorTest.java

示例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));
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:14,代码来源:JavaSourceFileParser.java

示例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.");
  }
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:39,代码来源:GraphProcessorTest.java

示例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);
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:32,代码来源:ProjectClassToRuleResolverTest.java

示例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();
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:13,代码来源:ClassGraphPreprocessorTest.java

示例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));
  }
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:31,代码来源:ProjectClassToRuleResolverTest.java


注:本文中的com.google.common.graph.MutableGraph.putEdge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。