Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cebf350

Browse files
codingforkind@163.comcodingforkind@163.com
codingforkind@163.com
authored and
codingforkind@163.com
committed
re
1 parent 57af9c4 commit cebf350

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

‎mirror-common/src/main/java/cn/com/mirror/Mirror.java‎

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public class Mirror {
3737

3838
private Unit unit;
3939
private Pair pair;
40-
private Map<String, NodeFactory> nodeFactoryMap;
4140

4241
private final Integer poolSize = 2;
4342
private ExecutorService executorService = Executors.newFixedThreadPool(poolSize);
@@ -47,7 +46,6 @@ public Mirror() {
4746
}
4847

4948
public Mirror(ProjectProperty projectProperty) {
50-
this.nodeFactoryMap = new HashMap<>();
5149
this.projectProperty = projectProperty;
5250

5351
CountDownLatch countDownLatch = new CountDownLatch(poolSize);
@@ -72,15 +70,16 @@ public Mirror(ProjectProperty projectProperty) {
7270
}
7371

7472
// mapping vertex to graph node
75-
public void mappingVertex2GraphNode() {
73+
public Map<String, NodeFactory> mappingVertex2GraphNode() {
74+
Map<String, NodeFactory> nodeFactoryMap = new HashMap<>();
7675
// analyze the project
7776
for (Map.Entry<String, Map<Vertex, Set<Vertex>>> ctrlEdgeEntry : pair.getCtrlEdges().entrySet()) {
7877
Map<Vertex, Set<Vertex>> edgeMap = ctrlEdgeEntry.getValue();
7978

8079
// one target one node factory
8180
String targetPath = ctrlEdgeEntry.getKey();
82-
if (null == this.nodeFactoryMap.get(targetPath)) {
83-
this.nodeFactoryMap.put(targetPath, new NodeFactory());
81+
if (null == nodeFactoryMap.get(targetPath)) {
82+
nodeFactoryMap.put(targetPath, new NodeFactory());
8483
}
8584

8685
for (Map.Entry<Vertex, Set<Vertex>> edges : edgeMap.entrySet()) {
@@ -90,32 +89,32 @@ public void mappingVertex2GraphNode() {
9089
Set<Vertex> headVtxSet = edges.getValue();
9190
for (Vertex headVtx : headVtxSet) {
9291
Base headBase = getBaseElement(headVtx);
93-
touchEdge(tailBase, headBase);
92+
touchEdge(tailBase, headBase, nodeFactoryMap.get(targetPath));
9493
}
9594
}
96-
97-
if (this.projectProperty.getEnableWriteGraphDB()) {
98-
write2GraphDB(targetPath);
99-
}
100-
10195
}
10296
// end
97+
if (this.projectProperty.getEnableWriteGraphDB()) {
98+
write2GraphDB(nodeFactoryMap);
99+
}
103100

101+
return nodeFactoryMap;
104102
}
105103

106-
private void write2GraphDB(StringtargetPath) {
104+
private void write2GraphDB(Map<String, NodeFactory> nodeFactoryMap) {
107105
// mappingVertex2GraphNode
108106
GraphEngine graphEngine = new GraphEngine();
109-
Map<Base, BaseNode> nodeCache = this.nodeFactoryMap.get(targetPath).getNodeCache();
110-
for (BaseNode baseNode : nodeCache.values()) {
111-
// if (baseNode instanceof ClassNode) {
112-
graphEngine.write(baseNode);
113-
// }
114-
}// mappingVertex2GraphNode end
107+
for (String targetPath : nodeFactoryMap.keySet()) {
108+
Map<Base, BaseNode> nodeCache = nodeFactoryMap.get(targetPath).getNodeCache();
109+
for (BaseNode baseNode : nodeCache.values()) {
110+
if (baseNode instanceof ClassNode) {
111+
graphEngine.write(baseNode);
112+
}
113+
}// mappingVertex2GraphNode end
114+
}
115115
}
116116

117-
private void touchEdge(Base tailBase, Base headBase) {
118-
NodeFactory nodeFactory = this.nodeFactoryMap.get(tailBase.getTargetPath());
117+
private void touchEdge(Base tailBase, Base headBase, NodeFactory nodeFactory) {
119118
BaseNode tailNode = nodeFactory.newNode(tailBase);
120119
BaseNode headNode = nodeFactory.newNode(headBase);
121120

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /