Skip to content

Commit 053688a

Browse files
committed
update
1 parent 6ce968f commit 053688a

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

lib/utils/CollectionUtil.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package javaToolkit.lib.utils;
2+
3+
import java.util.*;
4+
5+
public class CollectionUtil {
6+
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+
});
23+
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+
}
29+
30+
return result;
31+
}
32+
33+
34+
}

lib/utils/DiffUtil.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
public class DiffUtil {
77

8-
public static List<Integer> getChangedLineNumList(String diffFilePath) {
8+
public static List<Integer> getChangedLineNumListInOldVersion(String diffFilePath) {
99

1010
List<Integer> changedLineNumList = new ArrayList<>();
1111
try {
@@ -31,6 +31,32 @@ public static List<Integer> getChangedLineNumList(String diffFilePath) {
3131
return changedLineNumList;
3232
}
3333

34+
public static List<Integer> getChangedLineNumListInNewVersion(String diffFilePath) {
35+
36+
List<Integer> changedLineNumList = new ArrayList<>();
37+
try {
38+
List<String> diffFileStrList = FileUtil.readFileToStrList(diffFilePath);
39+
for (String line : diffFileStrList) {
40+
if (line.startsWith("@@")) {
41+
for (String tmp : line.split(" ")) {
42+
if (tmp.trim().startsWith("+")) {
43+
if (tmp.contains(",")) {
44+
changedLineNumList.add(Integer.valueOf(tmp.trim().replace("-", "").split(",")[0]));
45+
} else {
46+
changedLineNumList.add(Integer.valueOf(tmp.trim().replace("-", "")));
47+
}
48+
}
49+
}
50+
}
51+
}
52+
} catch (Exception e) {
53+
// TODO: handle exception
54+
System.out.println(diffFilePath);
55+
System.exit(0);
56+
}
57+
return changedLineNumList;
58+
}
59+
3460
public static List<String> getModifiedFileList(String diffFilePath) {
3561
/**
3662
* can to be further improved in future

0 commit comments

Comments
 (0)