File tree Expand file tree Collapse file tree 2 files changed +61
-1
lines changed Expand file tree Collapse file tree 2 files changed +61
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 5
5
6
6
public class DiffUtil {
7
7
8
- public static List <Integer > getChangedLineNumList (String diffFilePath ) {
8
+ public static List <Integer > getChangedLineNumListInOldVersion (String diffFilePath ) {
9
9
10
10
List <Integer > changedLineNumList = new ArrayList <>();
11
11
try {
@@ -31,6 +31,32 @@ public static List<Integer> getChangedLineNumList(String diffFilePath) {
31
31
return changedLineNumList ;
32
32
}
33
33
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
+
34
60
public static List <String > getModifiedFileList (String diffFilePath ) {
35
61
/**
36
62
* can to be further improved in future
You can’t perform that action at this time.
0 commit comments