Skip to content

Commit 96c59e9

Browse files
committed
update
1 parent b796adb commit 96c59e9

File tree

3 files changed

+72
-25
lines changed

3 files changed

+72
-25
lines changed

lib/utils/CSVUtil.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package javaToolkit.lib.utils;
22

33
import java.io.FileWriter;
4-
import java.io.Writer;
54
import java.nio.file.Path;
65
import java.util.ArrayList;
76
import java.util.List;

lib/utils/CollectionUtil.java

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,39 @@
44

55
public class CollectionUtil {
66

7-
/**
8-
* https://stackoverflow.com/a/109389/4315608
9-
*
10-
* @param map
11-
* @param <K>
12-
* @param <V>
13-
* @return
14-
*/
15-
public static <K, V> Map<K, V> sortByValue(Map<K, V> map) {
16-
List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet());
17-
Collections.sort(list, new Comparator<Object>() {
18-
@SuppressWarnings("unchecked")
19-
public int compare(Object o1, Object o2) {
20-
return ((Comparable<V>) ((Map.Entry<K, V>) (o1)).getValue()).compareTo(((Map.Entry<K, V>) (o2)).getValue());
21-
}
22-
});
7+
/**
8+
* https://stackoverflow.com/a/109389/4315608
9+
*
10+
* @param map
11+
* @param <K>
12+
* @param <V>
13+
* @return
14+
*/
15+
public static <K, V> Map<K, V> sortByValue(Map<K, V> map) {
16+
List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet());
17+
Collections.sort(list, new Comparator<Object>() {
18+
@SuppressWarnings("unchecked")
19+
public int compare(Object o1, Object o2) {
20+
return ((Comparable<V>) ((Map.Entry<K, V>) (o1)).getValue())
21+
.compareTo(((Map.Entry<K, V>) (o2)).getValue());
22+
}
23+
});
2324

24-
Map<K, V> result = new LinkedHashMap<>();
25-
for (Iterator<Map.Entry<K, V>> it = list.iterator(); it.hasNext(); ) {
26-
Map.Entry<K, V> entry = (Map.Entry<K, V>) it.next();
27-
result.put(entry.getKey(), entry.getValue());
28-
}
25+
Map<K, V> result = new LinkedHashMap<>();
26+
for (Iterator<Map.Entry<K, V>> it = list.iterator(); it.hasNext();) {
27+
Map.Entry<K, V> entry = (Map.Entry<K, V>) it.next();
28+
result.put(entry.getKey(), entry.getValue());
29+
}
2930

30-
return result;
31-
}
31+
return result;
32+
}
3233

34+
public static Set<Object> mergeMultipleSet(List<Set<Object>> multiSet) {
35+
Set<Object> mergeSet = new HashSet<>();
36+
for (Set<Object> set : multiSet) {
37+
mergeSet.addAll(set);
38+
}
39+
return mergeSet;
40+
}
3341

3442
}

lib/utils/GitUtil.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,31 @@
33
import java.nio.file.Path;
44
import java.nio.file.Paths;
55
import java.util.Arrays;
6+
import java.util.Date;
7+
import java.util.HashSet;
68
import java.util.List;
9+
import java.util.Set;
710

811
public class GitUtil {
912

13+
public static void main(String[] args) {
14+
Path repoDir = Paths.get("/data/bowen/data/PTBench-Data/data/2019/quarkusio#gizmo/raw_github");
15+
Set<String> mergeSet = new HashSet<>();
16+
Set<String> bugComs = new HashSet<String>(getComsWithSingleWordMatch(repoDir, "bug"));
17+
System.out.println("# bug coms " + String.valueOf(bugComs.size()));
18+
mergeSet.addAll(bugComs);
19+
Set<String> BugComs = new HashSet<String>(getComsWithSingleWordMatch(repoDir, "Bug"));
20+
System.out.println("# Bug coms " + String.valueOf(BugComs.size()));
21+
mergeSet.addAll(BugComs);
22+
Set<String> fixComs = new HashSet<String>(getComsWithSingleWordMatch(repoDir, "fix"));
23+
System.out.println("# fix coms " + String.valueOf(fixComs.size()));
24+
mergeSet.addAll(fixComs);
25+
Set<String> FixComs = new HashSet<String>(getComsWithSingleWordMatch(repoDir, "Fix"));
26+
System.out.println("# Fix coms " + String.valueOf(FixComs.size()));
27+
mergeSet.addAll(FixComs);
28+
System.out.println("# merge coms " + String.valueOf(mergeSet.size()));
29+
}
30+
1031
public static Boolean clone(String repoName, String usrName, Path targetDir) {
1132

1233
if (targetDir.toFile().exists()) {
@@ -32,9 +53,28 @@ public static Boolean clone(String repoName, String usrName, Path targetDir) {
3253
public static List<String> getAllCommitsSha(Path repoDir) {
3354

3455
String cmd = "timeout 300 git --no-pager log --all --pretty=format:\"%H\"";
35-
56+
57+
ProcessUtil.ProcessReporter pr = ProcessUtil.executeCMD(cmd, null, repoDir, 0);
58+
if (pr.exitCode == 0) {
59+
return Arrays.asList(pr.out.replace("\"", "").split("\n"));
60+
} else {
61+
FileUtil.writeStr2File(pr.out, Paths.get(repoDir.toString(), "getAllCommitsSha_out.txt"));
62+
FileUtil.writeStr2File(pr.err, Paths.get(repoDir.toString(), "getAllCommitsSha_err.txt"));
63+
// System.out.println("cmd " + cmd + "\n");
64+
// System.out.println("report \n" + pr.toString());
65+
return null;
66+
}
67+
}
68+
69+
public static List<String> getComsWithSingleWordMatch(Path repoDir, String word) {
70+
71+
String cmd = "timeout 300 git --no-pager log --all --pretty=format:\"%H\" --grep=" + word.trim();
72+
3673
ProcessUtil.ProcessReporter pr = ProcessUtil.executeCMD(cmd, null, repoDir, 0);
3774
if (pr.exitCode == 0) {
75+
if ("".equals(pr.out.trim())) {
76+
return null;
77+
}
3878
return Arrays.asList(pr.out.replace("\"", "").split("\n"));
3979
} else {
4080
FileUtil.writeStr2File(pr.out, Paths.get(repoDir.toString(), "getAllCommitsSha_out.txt"));

0 commit comments

Comments
 (0)