本文整理汇总了Java中com.google.common.graph.MutableGraph.addNode方法的典型用法代码示例。如果您正苦于以下问题:Java MutableGraph.addNode方法的具体用法?Java MutableGraph.addNode怎么用?Java MutableGraph.addNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.graph.MutableGraph
的用法示例。
在下文中一共展示了MutableGraph.addNode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: map
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/**
* Converts the class file dependency graph into the source file dependency graph, by
* consolidating classes from the same source file. Given as input:
*
* <p>ul>
* <li>a directed graph where the nodes are classes (both inner and outer) and edges are
* dependencies between said classes
* <li>a mapping between outer class files and source files.
* </ul>
*
* This function outputs a directed graph where the nodes are source files and the edges are
* dependencies between said source files.
*/
// TODO(bazel-team): Migrate this function into Guava graph library
public static ImmutableGraph<Path> map(
Graph<String> classGraph, Map<String, Path> classToSourceFileMap) {
MutableGraph<Path> graph = GraphBuilder.directed().allowsSelfLoops(false).build();
for (String sourceNode : classGraph.nodes()) {
if (isInnerClass(sourceNode)) {
throw new GraphProcessorException(
String.format("Found inner class %s when mapping classes to source files", sourceNode));
}
Path sourcePath = classToSourceFileMap.get(sourceNode);
graph.addNode(sourcePath);
for (String successorNode : classGraph.successors(sourceNode)) {
Path successorPath = classToSourceFileMap.get(successorNode);
if (!sourcePath.equals(successorPath)) {
graph.putEdge(sourcePath, successorPath);
}
}
}
return ImmutableGraph.copyOf(graph);
}
示例2: 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);
}
示例3: 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);
}
示例4: createBuildRuleDAG
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/**
* Creates the build rule DAG using provided resolvers. Each resolver maps a top level class name
* to a build rule. We combine the resolvers to create one huge Map from class to rule.
*
* <p>We make the following stipulations. First, a class must not map to more than one build rule.
* Otherwise, we throw an error. However, a class need not map to any rule. In which case we will
* not include it in the resulting build rule Graph. Second, the resulting graph must not have
* cycles.
*
* <p>TODO(bazel-team) Report/Crash if the resulting graph has cycles.
*/
ImmutableGraph<BuildRule> createBuildRuleDAG(Iterable<ClassToRuleResolver> resolvers) {
ImmutableMap<String, BuildRule> ruleMap = createClassToRuleMap(resolvers);
MutableGraph<BuildRule> buildRuleDAG = GraphBuilder.directed().allowsSelfLoops(false).build();
for (String className : classGraph.nodes()) {
BuildRule srcRule = ruleMap.get(className);
if (srcRule == null) {
continue;
}
buildRuleDAG.addNode(srcRule);
for (String successor : classGraph.successors(className)) {
BuildRule dstRule = ruleMap.get(successor);
if (dstRule == null || srcRule.equals(dstRule)) {
continue;
}
buildRuleDAG.putEdge(srcRule, dstRule);
}
}
return ImmutableGraph.copyOf(buildRuleDAG);
}
示例5: 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");
}
示例6: trimRemovesTransitiveDepsOfBlackListedClasses
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
/**
* Tests whether black listed classes names as well as their non-whitelisted dependencies are
* removed from the class graph. In addition to not containing the black listed class, the
* resulting graph should also not contain nonwhite listed classes only black listed classes are
* dependent on. For example, say we were to have the following class graph
*
* <p>com.Whitelist --> com.Blacklist --> com.NonWhitelist
*
* <p>Then the resulting class graph should only contain com.Whitelist
*/
@Test
public void trimRemovesTransitiveDepsOfBlackListedClasses() {
MutableGraph<String> graph = newGraph();
graph.putEdge("com.BlackList", "com.OtherList");
graph.putEdge("com.WhiteList", "com.BlackList");
Pattern blackList = Pattern.compile("BlackList");
Pattern whiteList = Pattern.compile("WhiteList");
Graph<String> actual = preProcessClassGraph(ImmutableGraph.copyOf(graph), whiteList, blackList);
MutableGraph<String> expected = newGraph();
expected.addNode("com.WhiteList");
assertEquivalent(actual, expected);
assertThat(actual.nodes()).doesNotContain("com.BlackList");
assertThat(actual.nodes()).doesNotContain("com.OtherList");
}
示例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: classGraphWithOnlyOneClassResultingInSingleSourceFile
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
@Test
public void classGraphWithOnlyOneClassResultingInSingleSourceFile() {
MutableGraph<String> graph = newGraph(String.class);
graph.addNode("com.A");
Map<String, Path> map = ImmutableMap.of("com.A", 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);
}
示例9: addNodes
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
private void addNodes(final Tracer tracer, final ConcurrentHashMap<String, BuildRule> builder, final MutableGraph<BuildRule> graph, final Rules[] targets) throws Exception {
tracer.info(started(hashCode).toString());
for (final Rules target : targets) {
final BuildRule buildRule = target.build();
builder.put(buildRule.getName(), buildRule);
graph.addNode(buildRule);
}
tracer.info(finished(hashCode).toString());
}
示例10: main
import com.google.common.graph.MutableGraph; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Node rootNode = new Node("0","root");
Node node1 = new Node("1","node1");
Node node2 = new Node("2","node2");
Node node3 = new Node("3","node3");
Node node4 = new Node("4","node4");
GraphEdgeModel edge1 = new GraphEdgeModel(rootNode, node1);
GraphEdgeModel edge2 = new GraphEdgeModel(rootNode, node2);
GraphEdgeModel edge3 = new GraphEdgeModel(node1, node3);
GraphEdgeModel edge4 = new GraphEdgeModel(node3, node4);
GraphEdgeModel edge5 = new GraphEdgeModel(node2, node3);
GraphEdgeModel edge6 = new GraphEdgeModel(node4, node3);
List<GraphEdgeModel> list = new ArrayList<>();
list.add(edge1);
list.add(edge2);
list.add(edge3);
list.add(edge4);
list.add(edge5);
list.add(edge6);
MutableGraph<Node> graph1 = GraphBuilder.directed().build();
graph1.addNode(rootNode);
graph1.addNode(node1);
graph1.addNode(node2);
graph1.addNode(node3);
graph1.addNode(node4);
graph1.putEdge(rootNode, node1);
graph1.putEdge(rootNode, node2);
System.out.println(JsonUtils.pojoToJson(graph1));
for (int i = 0; i < 5; i++) {
try {
//checkCircle(rootNode, list, null);
GraphModel graph = new GraphModel();
graph.addNode(rootNode);
graph.addNode(node1);
graph.addNode(node2);
graph.addNode(node3);
graph.addNode(node4);
graph.setRelationEdges(list);
List<String> cycNodes = GraphModel.checkCircle(graph);
System.out.println(cycNodes);
} catch (GraphCircleReferenceException e) {
System.out.println(e.getMessage());
System.out.println(e.getErrObject().getFrom().getId()+"-------err-------->"+e.getErrObject().getTo().getId());
}
System.out.println("---------------");
}
}