Skip to content

Commit de26c31

Browse files
committed
规范代码。
1 parent 157d78d commit de26c31

31 files changed

Lines changed: 150 additions & 97 deletions

src/main/java/com/xwintop/xJavaFxTool/controller/debugTools/HttpToolController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class HttpToolController extends HttpToolView {
4545
private ObservableList<Map<String, String>> paramsDatatableData = FXCollections.observableArrayList();
4646
private ObservableList<Map<String, String>> paramsHeadertableData = FXCollections.observableArrayList();
4747
private ObservableList<Map<String, String>> paramsCookietableData = FXCollections.observableArrayList();
48+
private static Pattern p = Pattern.compile("\\s*|\t|\r|\n");
4849

4950
@Override
5051
public void initialize(URL location, ResourceBundle resources) {
@@ -97,7 +98,6 @@ public void changed(ObservableValue<? extends Boolean> observable, Boolean oldVa
9798
setTableViewOnMouseClicked(paramsCookieTableView, paramsCookietableData);
9899
MenuItem compressJsonMenuItem = new MenuItem("压缩JSON");
99100
compressJsonMenuItem.setOnAction(event -> {
100-
Pattern p = Pattern.compile("\\s*|\t|\r|\n");
101101
Matcher m = p.matcher(ResponseBodyTextArea.getText());
102102
ResponseBodyTextArea.setText(m.replaceAll(""));
103103
});

src/main/java/com/xwintop/xJavaFxTool/controller/developTools/xTransferTool/TransferToolController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private void initEvent() {
139139
return;
140140
}
141141
if (event.getButton() == MouseButton.PRIMARY) {
142-
if (selectedItem.getValue().equals("TaskConfig列表") || selectedItem.getValue().endsWith("service.yml") || selectedItem.getValue().endsWith("datasource.yml")) {
142+
if ("TaskConfig列表".equals(selectedItem.getValue()) || selectedItem.getValue().endsWith("service.yml") || selectedItem.getValue().endsWith("datasource.yml")) {
143143
selectedItem.setExpanded(!selectedItem.isExpanded());
144144
} else {
145145
if (selectedItem.getParent().getValue().endsWith("service.yml") || selectedItem.getParent().getValue().endsWith("datasource.yml")) {
@@ -163,7 +163,7 @@ private void initEvent() {
163163
});
164164
});
165165
ContextMenu contextMenu = new ContextMenu(menu_UnfoldAll, menu_FoldAll);
166-
if (selectedItem.getValue().equals("TaskConfig列表")) {
166+
if ("TaskConfig列表".equals(selectedItem.getValue())) {
167167
MenuItem menu_AddFile = new MenuItem("添加任务配置文件");
168168
menu_AddFile.setOnAction(event1 -> {
169169
String fileName = "taskConf" + DateFormatUtils.format(new Date(), "MMddHHmm") + "service.yml";
@@ -185,7 +185,7 @@ private void initEvent() {
185185
});
186186
contextMenu.getItems().add(menu_AddDataSourceFile);
187187
} else {
188-
if (selectedItem.getValue().endsWith("service.yml") || selectedItem.getValue().endsWith("datasource.yml") || selectedItem.getParent().getValue().equals("TaskConfig列表")) {
188+
if (selectedItem.getValue().endsWith("service.yml") || selectedItem.getValue().endsWith("datasource.yml") || "TaskConfig列表".equals(selectedItem.getParent().getValue())) {
189189
MenuItem menu_ViewFile = new MenuItem("查看文件内容");
190190
menu_ViewFile.setOnAction(event1 -> {
191191
transferToolService.addTaskFileTextArea(selectedItem.getValue(), transferToolService.getTaskConfigFileStringMap().get(selectedItem.getValue()));
@@ -379,7 +379,7 @@ private void initEvent() {
379379
});
380380
contextMenu.getItems().add(menu_SaveFile);
381381
}
382-
if (!selectedItem.getValue().endsWith("service.yml") && !selectedItem.getValue().equals("TaskConfig列表") && !selectedItem.getValue().endsWith("datasource.yml") && !selectedItem.getParent().getValue().equals("TaskConfig列表")) {
382+
if (!selectedItem.getValue().endsWith("service.yml") && !"TaskConfig列表".equals(selectedItem.getValue()) && !selectedItem.getValue().endsWith("datasource.yml") && !"TaskConfig列表".equals(selectedItem.getParent().getValue())) {
383383
if (selectedItem.getParent().getValue().endsWith("service.yml")) {
384384
MenuItem menu_Copy = new MenuItem("复制选中行");
385385
menu_Copy.setOnAction(event1 -> {

src/main/java/com/xwintop/xJavaFxTool/controller/littleTools/EncryptAndDecryptController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private void encrptyAction(ActionEvent event) {// 加密
140140
} else if ("文件加密SHA1".equals(curCrypto)) {
141141
decrptyTextArea.setText(DigestUtils.sha1Hex(new FileInputStream(new File(string))));
142142
} else if ("摩斯密码".equals(curCrypto)) {
143-
decrptyTextArea.setText(MorseConventer.Encryption(string));
143+
decrptyTextArea.setText(MorseConventer.encryption(string));
144144
} else if ("Druid加密".equals(curCrypto)) {
145145
String[] arr = ConfigTools.genKeyPair(512);
146146
StringBuilder decrptyStr = new StringBuilder();
@@ -194,7 +194,7 @@ private void decrptyAction(ActionEvent event) {// 解密
194194
DES des = SecureUtil.des(keyByte);
195195
encrptyTextArea.setText(des.decryptStr(string, Charset.forName(charSet)));
196196
} else if ("摩斯密码".equals(curCrypto)) {
197-
encrptyTextArea.setText(MorseConventer.Decryption(string));
197+
encrptyTextArea.setText(MorseConventer.decryption(string));
198198
} else if ("Druid加密".equals(curCrypto)) {
199199
encrptyTextArea.setText(ConfigTools.decrypt(keyTextField.getText(), string));
200200
} else {

src/main/java/com/xwintop/xJavaFxTool/controller/littleTools/ImageToolController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private void addTableData(File file){
123123
String resolution = ""+image.getWidth()+"×"+image.getHeight();
124124
Map<String, String> rowValue = new HashMap<>();
125125
rowValue.put("name", file.getName());
126-
rowValue.put("size", "" + FileUtil.FormetFileSize(file.length()));
126+
rowValue.put("size", "" + FileUtil.formetFileSize(file.length()));
127127
rowValue.put("resolution", resolution);
128128
rowValue.put("fullPath", file.getAbsolutePath());
129129
tableData.add(rowValue);

src/main/java/com/xwintop/xJavaFxTool/manager/script/ScriptEngineType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ public String getValue() {
2020
}
2121
public static ScriptEngineType getEnum(String value) {
2222
ScriptEngineType e = null;
23-
for (ScriptEngineType e1 : ScriptEngineType.values())
23+
for (ScriptEngineType e1 : ScriptEngineType.values()) {
2424
if (e1.value.equals(value)) {
2525
e = e1;
2626
break;
2727
}
28+
}
2829
return e;
2930
}
3031
}

src/main/java/com/xwintop/xJavaFxTool/services/assistTools/WechatJumpGameToolService.java

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public void adbConnectAction() {
5353
new Thread(new Runnable() {
5454
byte[] cache = new byte[1024];
5555

56+
@Override
5657
public void run() {
5758
try {
5859
int i;
@@ -134,14 +135,18 @@ private String scanPic(File pic) throws Exception {
134135
//扫描获取黑棋位置
135136
for (int i = 50; i < width; i++) {
136137
for (int flag = 0, j = height * 3 / 4; j > height / 3; j -= 5) {
137-
if (!colorDiff(bi.getRGB(i, j), 55 << 16 | 58 << 8 | 100)) flag++;
138+
if (!colorDiff(bi.getRGB(i, j), 55 << 16 | 58 << 8 | 100)) {
139+
flag++;
140+
}
138141
if (flag > 3) {
139142
x1 = i + 13 * r;
140143
y1 = j + 2 * r;
141144
break;
142145
}
143146
}
144-
if (x1 > 0) break;
147+
if (x1 > 0) {
148+
break;
149+
}
145150
}
146151
Graphics2D g2d = bi.createGraphics();
147152
g2d.setColor(Color.BLUE);
@@ -163,10 +168,17 @@ private String scanPic(File pic) throws Exception {
163168
if (x2 > 0) {//找到了目标块顶点
164169
int p2 = bi.getRGB(x2, y2 - 10), j, max = -1;
165170
for (; i < y1 - 50 * r; i += 5) {
166-
for (j = x2; colorDiff(bi.getRGB(j, i), p2) && j < x2 + 200 * r; ) j++;
167-
if (max < 0 && j - x2 > 0) x2 = x2 + (j - x2) / 2;//修正顶点横坐标
168-
if (max < j - x2) max = j - x2;//找到目标块最长宽度
169-
else break;
171+
for (j = x2; colorDiff(bi.getRGB(j, i), p2) && j < x2 + 200 * r; ) {
172+
j++;
173+
}
174+
if (max < 0 && j - x2 > 0) {
175+
x2 = x2 + (j - x2) / 2;//修正顶点横坐标
176+
}
177+
if (max < j - x2) {
178+
max = j - x2;//找到目标块最长宽度
179+
} else {
180+
break;
181+
}
170182
}
171183
g2d.drawLine(x2, y2, x2, i);
172184
y2 = i - 5;
@@ -178,13 +190,23 @@ private String scanPic(File pic) throws Exception {
178190
ImageIO.write(bi, "png", new FileOutputStream(pic));//保存成图片
179191
double distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
180192
if (x1 < 50 || y1 < 50 || x2 < 50 || y2 < 50 || distance < 100) {
181-
if (!restart) throw new Exception("scan error:" + x1 + "|" + y1 + "|" + x2 + "|" + y2);
193+
if (!restart) {
194+
throw new Exception("scan error:" + x1 + "|" + y1 + "|" + x2 + "|" + y2);
195+
}
182196
int x = width / 2, y = height * 3 / 4, z = 9 * height / 10, i = y;//获取开始按钮位置,自动重新开始
183-
while ((i += 20) < z) if (bi.getRGB(x, i) == -1 && bi.getRGB(x + 20, i + 20) == -1) break;
184-
if (i == y - 20 || i == z) throw new Exception("scan error:game not start");
197+
while ((i += 20) < z) {
198+
if (bi.getRGB(x, i) == -1 && bi.getRGB(x + 20, i + 20) == -1) {
199+
break;
200+
}
201+
}
202+
if (i == y - 20 || i == z) {
203+
throw new Exception("scan error:game not start");
204+
}
185205
return x + " " + i + " " + x + " " + i + " 100";
186206
}
187-
if (distance < 150) distance = 150;
207+
if (distance < 150) {
208+
distance = 150;
209+
}
188210
return x1 + " " + y1 + " " + x2 + " " + y2 + " " + (int) (distance * rate);
189211
}
190212

@@ -198,11 +220,15 @@ private File getScreenPic() throws Exception {
198220
File pic = new File(path + "pic.png");
199221
if (pic.exists()) {//备份一下之前的一张图片
200222
File back = new File(path + System.currentTimeMillis() + ".png");
201-
if (!back.exists() || back.delete()) pic.renameTo(back);
223+
if (!back.exists() || back.delete()) {
224+
pic.renameTo(back);
225+
}
202226
}
203227
exec(adb + " shell screencap -p /sdcard/screen.png");
204228
exec(adb + " pull /sdcard/screen.png " + pic.getAbsolutePath());
205-
if (!pic.exists()) throw new Exception("error getScreenPic");
229+
if (!pic.exists()) {
230+
throw new Exception("error getScreenPic");
231+
}
206232
return pic;
207233
}
208234

@@ -212,9 +238,13 @@ private void exec(String cmd) throws Exception {
212238
System.out.println(cmd);
213239
ps = Runtime.getRuntime().exec(cmd.split(" "));
214240
int code = ps.waitFor();
215-
if (code != 0) throw new Exception("exec error(code=" + code + "): " + cmd);
241+
if (code != 0) {
242+
throw new Exception("exec error(code=" + code + "): " + cmd);
243+
}
216244
} finally {
217-
if (ps != null) ps.destroy();
245+
if (ps != null) {
246+
ps.destroy();
247+
}
218248
}
219249
}
220250

src/main/java/com/xwintop/xJavaFxTool/services/codeTools/WebSourcesToolService.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class WebSourcesToolService {
3232
private WebSourcesToolController webSourcesToolController;
3333
private final OkHttpClient client = new OkHttpClient();
3434
private String sourcesFilePathString = "D://TestXf//";
35+
private static Pattern srcPattern = Pattern.compile("src *= *['\"]*(\\S+)[\"']", Pattern.CASE_INSENSITIVE); // 不区分大小写
36+
private static Pattern hrefPattern = Pattern.compile("href *= *['\"]*(\\S+)[\"']", Pattern.CASE_INSENSITIVE); // 不区分大小写
3537

3638
public WebSourcesToolService(WebSourcesToolController webSourcesToolController) {
3739
this.webSourcesToolController = webSourcesToolController;
@@ -42,29 +44,27 @@ public void downloadHtmlSources() throws Exception {
4244
String urlString = webSourcesToolController.getUrlTextField().getText().trim();
4345
Request request = new Request.Builder().url(urlString).build();
4446
Response response = client.newCall(request).execute();
45-
if (!response.isSuccessful())
46-
throw new IOException("Unexpected code " + response);
47+
if (!response.isSuccessful()) {
48+
throw new IOException("Unexpected code " + response);
49+
}
4750
String indexHtml = response.body().string();
4851
new File(sourcesFilePathString).mkdirs();
4952
File indexHtmlFile = new File(sourcesFilePathString + "index.html");
5053
// FileUtils.touch(indexHtmlFile);
5154
FileUtils.writeStringToFile(indexHtmlFile, indexHtml, Charset.defaultCharset());
52-
Pattern srcPattern = Pattern.compile("src *= *['\"]*(\\S+)[\"']", Pattern.CASE_INSENSITIVE); // 不区分大小写
55+
5356
// 用Pattern类的matcher()方法生成一个Matcher对象
5457
Matcher srcMatcher = srcPattern.matcher(indexHtml);
5558
while (srcMatcher.find()) {
5659
String str0 = srcMatcher.group();
5760
String str1 = srcMatcher.group(1); // 捕获的子序列
58-
System.out.println(str0);
59-
System.out.println(str1);
6061
saveSourcesFile(urlString,str1);
6162
}
6263
FileUtils.writeStringToFile(indexHtmlFile, indexHtml, Charset.defaultCharset());
63-
Pattern hrefPattern = Pattern.compile("href *= *['\"]*(\\S+)[\"']", Pattern.CASE_INSENSITIVE); // 不区分大小写
64+
6465
Matcher hrefMatcher = hrefPattern.matcher(indexHtml);
6566
while (hrefMatcher.find()) {
6667
String str1 = hrefMatcher.group(1); // 捕获的子序列
67-
System.out.println(str1);
6868
saveSourcesFile(urlString,str1);
6969
}
7070
}
@@ -86,8 +86,9 @@ private void saveSourcesFile(String url, String sourcesUrl) throws Exception {
8686
}
8787
Request request = new Request.Builder().url(url+"/"+sUrlStrings[sUrlStrings.length-1]).build();
8888
Response response = client.newCall(request).execute();
89-
if (!response.isSuccessful())
90-
throw new IOException("Unexpected code " + response);
89+
if (!response.isSuccessful()) {
90+
throw new IOException("Unexpected code " + response);
91+
}
9192
File sourcesFile = new File(sourcesIndexPathFile, "/" + sUrlStrings[sUrlStrings.length-1]);
9293
FileUtils.touch(sourcesFile);
9394
FileUtils.writeByteArrayToFile(sourcesFile, response.body().bytes());

src/main/java/com/xwintop/xJavaFxTool/services/debugTools/ActiveMqToolService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ public void sendAction() {
142142
TooltipUtil.showToast("发送失败:" + e.getMessage());
143143
} finally {
144144
try {
145-
if (null != connection)
145+
if (null != connection) {
146146
connection.close();
147+
}
147148
} catch (Throwable ignore) {
148149
}
149150
}

src/main/java/com/xwintop/xJavaFxTool/services/debugTools/SwitchHostsToolService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.io.File;
1616
import java.io.IOException;
1717
import java.io.InputStreamReader;
18+
import java.nio.charset.Charset;
1819
import java.util.Optional;
1920

2021
/**
@@ -42,7 +43,7 @@ public class SwitchHostsToolService {
4243

4344
public void reloadSystemHosts() throws Exception {
4445
String fileName = this.getHostsFilePath();
45-
String systemHostString = FileUtils.readFileToString(new File(fileName));
46+
String systemHostString = FileUtils.readFileToString(new File(fileName), Charset.defaultCharset());
4647
// switchHostsToolController.getHostTextArea().setText(systemHostString);
4748
switchHostsToolController.getHostTextArea().clear();
4849
switchHostsToolController.getHostTextArea().replaceText(0, 0, systemHostString);

0 commit comments

Comments
 (0)