Skip to content

Commit 8dd6e9e

Browse files
committed
插件代码拼接工具
1 parent dc33f73 commit 8dd6e9e

3 files changed

Lines changed: 77 additions & 208 deletions

File tree

src/test/Main.java

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,67 @@
11
package test;
22

3+
import utils.FileUtils;
4+
5+
import java.io.File;
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
import java.util.Locale;
9+
310
public class Main {
411

5-
static class Value{
6-
int i;
12+
static class WdSubject {
13+
String name;
14+
String startTime;
15+
String errorTime;
16+
int diffMonth;
717
}
818

919
public static void main(String[] args) throws Exception {
10-
Main main = new Main();
11-
main.first();
20+
System.out.println(Integer.toHexString(Integer.MAX_VALUE));
1221
}
1322

14-
private void first() {
15-
int i = 5;
16-
Value v = new Value();
17-
v.i = 25;
18-
second(v, i);
19-
System.out.println(v.i);
23+
private static void test() {
24+
ArrayList<String> strings = FileUtils.readToStringLines(new File("temp/wd.txt"));
25+
int index = 0;
26+
WdSubject subject = new WdSubject();
27+
assert strings != null;
28+
List<WdSubject> subjects = new ArrayList<>();
29+
for (String string : strings) {
30+
switch (index) {
31+
case 2:
32+
subject.errorTime = string;
33+
break;
34+
case 3:
35+
subject.startTime = string;
36+
subject.diffMonth = calculateDiff(subject);
37+
subject = new WdSubject();
38+
subjects.add(subject);
39+
break;
40+
41+
}
42+
if(index == 6) {
43+
index = 0;
44+
} else {
45+
index ++;
46+
}
47+
}
48+
49+
int count = 0;
50+
for (WdSubject sub : subjects) {
51+
if(sub.diffMonth <= 12) {
52+
count ++;
53+
}
54+
}
55+
System.out.println(count + " / " + subjects.size());
56+
System.out.println(1f*count/subjects.size()*100 + "%");
2057
}
2158

22-
private void second(Value v, int i) {
23-
i = 0;
24-
v.i = 20;
25-
Value val = new Value();
26-
v = val;
27-
System.out.println(v.i + "" + i);
59+
private static int calculateDiff(WdSubject subject) {
60+
int errorYear = Integer.parseInt(subject.errorTime.split("-")[0]);
61+
int startYear = Integer.parseInt(subject.startTime.split("-")[0]);
62+
int errorMonth = Integer.parseInt(subject.errorTime.split("-")[1]);
63+
int startMonth = Integer.parseInt(subject.startTime.split("-")[1]);
64+
return (errorYear-startYear)*12+(errorMonth-startMonth);
2865
}
2966

3067
}

src/utils/FileUtils.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
package utils;
2-
import java.io.BufferedReader;
3-
import java.io.BufferedWriter;
4-
import java.io.File;
5-
import java.io.FileInputStream;
6-
import java.io.FileNotFoundException;
7-
import java.io.FileOutputStream;
8-
import java.io.FileReader;
9-
import java.io.IOException;
10-
import java.io.InputStream;
11-
import java.io.OutputStreamWriter;
12-
import java.io.UnsupportedEncodingException;
2+
3+
import java.io.*;
134
import java.nio.channels.FileChannel;
145
import java.text.DecimalFormat;
156
import java.util.ArrayList;
@@ -19,7 +10,28 @@
1910
public class FileUtils {
2011

2112
public static void main(String[] args) {
22-
batchRename("E:\\work\\icons", "video_living_%s");
13+
StringBuilder sb = new StringBuilder();
14+
ArrayList<String> lines = readToStringLines(new File(
15+
"E:\\work\\ChildrenRead\\app\\src\\main\\java\\com\\diandian\\childrenread\\db\\BookDao.java"));
16+
17+
for (String line : lines) {
18+
if(line.trim().length() == 0) {
19+
sb.append("sb.append(\"\\n\");").append("\n");
20+
continue;
21+
}
22+
23+
int count = 0;
24+
for (char c : line.toCharArray()) {
25+
if(c == ' ') count ++;
26+
else break;
27+
}
28+
int tabCount = count/4;
29+
30+
String text = "sb.append(StringUtils.formatSingleLine(%d, \"%s\"));";
31+
sb.append(String.format(text, tabCount, line.trim())).append("\n");
32+
}
33+
System.out.println(sb.toString());
34+
2335
}
2436

2537
/**

temp/db/entities/Book.java

Lines changed: 0 additions & 180 deletions
This file was deleted.

0 commit comments

Comments
 (0)