-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWritePathResult.java
More file actions
executable file
·66 lines (60 loc) · 2.35 KB
/
Copy pathWritePathResult.java
File metadata and controls
executable file
·66 lines (60 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class WritePathResult {
private static int count = 0;
public static void ergodicDir(File dir, PrintWriter targetFilePW, Map<String, String> API2IndexMap) throws IOException {
if(dir.isDirectory()){
for(File file : dir.listFiles()){
if(file.isDirectory()){
System.out.println("ergodicDir...");
ergodicDir(file, targetFilePW, API2IndexMap);
}
if(file.isFile() && file.getName().endsWith("dot")){
System.out.println("processing " + ++count + " data");
writePath(file, targetFilePW, API2IndexMap);
}
}
}
else {
if(dir.isFile() && dir.getName().endsWith("dot")){
System.out.println("processing " + ++count + " data");
writePath(dir, targetFilePW, API2IndexMap);
}
}
}
private static void writePath(File groumFile, PrintWriter targetFilePW, Map<String, String> API2IndexMap) throws IOException {
ConstructGroum CG = new ConstructGroum();
Groum groum = CG.constructGroum(groumFile.getAbsolutePath(), API2IndexMap);
if(groum != null) {
Map<String, GroumNode> nodeMap = groum.getNodeMap();
List<String> startList = null;
for (String id : nodeMap.keySet()) {
startList = new ArrayList<>();
startList.add(id);
List<List<String>> outList = GetPath.getAllPath(groum, startList, 4);
writeFile(outList, targetFilePW);
}
}
}
private static String convertListToString(List<String> list) {
StringBuilder sB = new StringBuilder();
boolean ifStarted = false;
for (String item : list) {
if (ifStarted) {
sB.append(",");
}
sB.append(item);
if (!ifStarted) ifStarted = true;
}
return sB.toString();
}
private static void writeFile(List<List<String>> outList, PrintWriter targetFilePW) throws IOException {
String tempStr = null;
for (List<String> path : outList) {
tempStr = convertListToString(path);
targetFilePW.println(tempStr);
}
}
}