• R/O
  • HTTP
  • SSH
  • HTTPS

DelesteRandomSelector: Commit

開発Git


Commit MetaInfo

Revisionef466e879cfb0a42eb6522d79a2b428736aaadbc (tree)
Time2022-05-05 21:50:20
Authorhizumiaoba <56146205+hizumiaoba@user...>
Commiterhizumiaoba

Log Message

feat: add fileIO components

Change Summary

Incremental Difference

--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,6 @@ logs/
1111 twitterToken.json
1212 TwitterIntegration.java
1313 TwitterToken.java
14+
15+#Ignore local-generated record files
16+*.drs
--- /dev/null
+++ b/Crash-Report/2022-05-05-18-15-39.txt
@@ -0,0 +1,53 @@
1+---- DelesteRandomSelector Crash Report ----
2+// Shimamura Uzuki, I'll do my best!
3+
4+
5+Time: 22/05/05 18:15
6+Description: java.lang.IllegalArgumentException: Level must not negative.
7+
8+
9+These are simplified stack trace. (shown up to 5 lines. Full Stack trace is below.)
10+java.lang.IllegalStateException: java.util.concurrent.CompletionException: java.lang.IllegalArgumentException: Level must not negative.
11+ at com.ranfa.main.DelesteRandomSelector.lambda$20(DelesteRandomSelector.java:508)
12+ at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
13+ at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
14+ at java.base/java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:478)
15+ at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
16+
17+
18+A detailed walkthrough of the error, its code path and all known details is as follows:
19+---------------------------------------------------------------------------------------
20+
21+
22+Stacktrace:
23+ at com.ranfa.main.DelesteRandomSelector.lambda$20(DelesteRandomSelector.java:508)
24+ at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
25+ at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
26+ at java.base/java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:478)
27+ at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
28+ at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
29+ at java.base/java.lang.Thread.run(Thread.java:829)
30+Caused by: java.util.concurrent.CompletionException: java.lang.IllegalArgumentException: Level must not negative.
31+ at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:314)
32+ at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:319)
33+ at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1739)
34+ at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
35+ at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
36+ at java.base/java.lang.Thread.run(Thread.java:829)
37+Caused by: java.lang.IllegalArgumentException: Level must not negative.
38+ at com.ranfa.lib.database.Scraping.getSpecificLevelSongs(Scraping.java:176)
39+ at com.ranfa.main.DelesteRandomSelector.lambda$19(DelesteRandomSelector.java:493)
40+ at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1736)
41+ at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
42+ at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
43+ at java.base/java.lang.Thread.run(Thread.java:829)
44+
45+
46+-- System Details --
47+Details:
48+ DelesteRandomSelector Version: v4.0.3-Beta
49+ Operating System: Windows 11 (amd64) version 10.0
50+ Java Version: 11, Eclipse Adoptium
51+ Java VM Version: OpenJDK 64-Bit Server VM, version 11.0.14.1+1
52+ Memory: 75112704 bytes / 268435456 bytes up to 4273995776 bytes
53+ JVM Flags: 1 total: [-Dfile.encoding=UTF-8]
--- a/src/com/ranfa/main/DelesteRandomSelector.java
+++ b/src/com/ranfa/main/DelesteRandomSelector.java
@@ -22,10 +22,12 @@ import java.awt.EventQueue;
2222 import java.awt.Font;
2323 import java.awt.event.ActionEvent;
2424 import java.awt.event.ActionListener;
25+import java.io.File;
2526 import java.io.IOException;
2627 import java.net.URI;
2728 import java.net.URISyntaxException;
2829 import java.nio.file.Files;
30+import java.nio.file.Path;
2931 import java.nio.file.Paths;
3032 import java.text.Normalizer;
3133 import java.util.ArrayList;
@@ -43,6 +45,7 @@ import javax.swing.DefaultComboBoxModel;
4345 import javax.swing.JButton;
4446 import javax.swing.JCheckBox;
4547 import javax.swing.JComboBox;
48+import javax.swing.JFileChooser;
4649 import javax.swing.JFrame;
4750 import javax.swing.JLabel;
4851 import javax.swing.JOptionPane;
@@ -250,7 +253,8 @@ public class DelesteRandomSelector extends JFrame {
250253 private JLabel lblProduce;
251254 private JLabel lblPremium;
252255 private JButton button;
253- private JButton button_1;
256+ private JButton btnScoreFileOut;
257+ private JButton btnScoreReadFile;
254258
255259 /**
256260 * Launch the application.
@@ -947,11 +951,7 @@ public class DelesteRandomSelector extends JFrame {
947951 labelArrangeToolTip.setText(fetchMap.get("arrange"));
948952 labelMemberToolTip.setText("<html><body>" + fetchMap.get("member") + "</html></body>");
949953 }
950- }, es).whenCompleteAsync((ret, ex) -> {
951- if(ex != null) {
952- logger.error("Exception was thrown during concurrent process", ex);
953- }
954- }, es);
954+ }, es).whenCompleteAsync(this::whenCompleteProcess, es);
955955 });
956956
957957 btnPrevSongTool = new JButton("prev");
@@ -982,11 +982,7 @@ public class DelesteRandomSelector extends JFrame {
982982 labelArrangeToolTip.setText(fetchMap.get("arrange"));
983983 labelMemberToolTip.setText("<html><body>" + fetchMap.get("member") + "</html></body>");
984984 }
985- }, es).whenCompleteAsync((ret, ex) -> {
986- if(ex != null) {
987- logger.error("Exception was thrown during concurrent process", ex);
988- }
989- }, es);
985+ }, es).whenCompleteAsync(this::whenCompleteProcess, es);
990986 });
991987 btnPrevSongTool.setFont(new Font("UD デジタル 教科書体 NP-B", Font.PLAIN, 12));
992988 panelCenterTool.add(btnPrevSongTool, "10, 28");
@@ -1027,11 +1023,7 @@ public class DelesteRandomSelector extends JFrame {
10271023 JOptionPane.showMessageDialog(null, "このメッセージは仮です。Exception : " + e1.getClass().getSimpleName());
10281024 logger.error("Exception while opening default browser.", e1);
10291025 }
1030- }, es).whenCompleteAsync((ret, ex) -> {
1031- if(ex != null) {
1032- logger.warn("Exception was thrown during action events.", ex);
1033- }
1034- }, es);
1026+ }, es).whenCompleteAsync(this::whenCompleteProcess, es);
10351027 });
10361028 btnMoreInfoTool.setFont(new Font("UD デジタル 教科書体 NP-B", Font.PLAIN, 12));
10371029 panelCenterTool.add(btnMoreInfoTool, "25, 28");
@@ -1201,6 +1193,15 @@ public class DelesteRandomSelector extends JFrame {
12011193 labelScoreNotesDynamic = new JLabel("<dynamic>");
12021194 panelScoreCenter.add(labelScoreNotesDynamic, "12, 26");
12031195
1196+ labelScoreCurrentSongOrder = new JLabel("null");
1197+ panelScoreCenter.add(labelScoreCurrentSongOrder, "14, 28, center, default");
1198+
1199+ labelScoreSlash = new JLabel("/");
1200+ panelScoreCenter.add(labelScoreSlash, "16, 28, center, default");
1201+
1202+ labelScoreOrderMax = new JLabel(String.valueOf(property.getSongLimit()));
1203+ panelScoreCenter.add(labelScoreOrderMax, "18, 28, center, default");
1204+
12041205 lblPremium = new JLabel("premium");
12051206 panelScoreCenter.add(lblPremium, "4, 30, center, default");
12061207
@@ -1214,37 +1215,6 @@ public class DelesteRandomSelector extends JFrame {
12141215 labelPlayerScoreDynamic = new JLabel("<dynamic>");
12151216 panelScoreCenter.add(labelPlayerScoreDynamic, "12, 30");
12161217
1217- labelScoreCurrentSongOrder = new JLabel("null");
1218- panelScoreCenter.add(labelScoreCurrentSongOrder, "14, 30, center, default");
1219-
1220- labelScoreSlash = new JLabel("/");
1221- panelScoreCenter.add(labelScoreSlash, "16, 30, center, default");
1222-
1223- labelScoreOrderMax = new JLabel(String.valueOf(property.getSongLimit()));
1224- panelScoreCenter.add(labelScoreOrderMax, "18, 30, center, default");
1225-
1226- btnScorePrev = new JButton("Prev");
1227- btnScorePrev.addActionListener(new ActionListener() {
1228- @Override
1229- public void actionPerformed(ActionEvent e) {
1230- CompletableFuture.runAsync(() -> {
1231- int currentIndex = Integer.parseInt(labelScoreCurrentSongOrder.getText()) - 1;
1232- if(currentIndex != 0) {
1233- Song prevSong = toolIntegrateList.get(currentIndex - 1);
1234- logger.info("currently : {} Next: {}", currentIndex + 1, currentIndex);
1235- logger.info("prevSong: {}", prevSong);
1236- labelScoreSongnameDynamic.setText("<html><body>" + prevSong.getName() + "</body></html>");
1237- labelScoreAttributeDynamic.setText(prevSong.getAttribute());
1238- labelScoreDifficultyDynamic.setText(prevSong.getDifficulty());
1239- labelScoreLevelDynamic.setText(String.valueOf(prevSong.getLevel()));
1240- labelScoreNotesDynamic.setText(String.valueOf(prevSong.getNotes()));
1241- labelScoreCurrentSongOrder.setText(String.valueOf(currentIndex));
1242- }
1243- }, es);
1244- }
1245- });
1246- panelScoreCenter.add(btnScorePrev, "14, 32");
1247-
12481218 btnScoreNext = new JButton("Next");
12491219 btnScoreNext.addActionListener(new ActionListener() {
12501220 @Override
@@ -1265,74 +1235,38 @@ public class DelesteRandomSelector extends JFrame {
12651235 }, es);
12661236 }
12671237 });
1268- panelScoreCenter.add(btnScoreNext, "18, 32");
12691238
1270- labelPlayerFan = new JLabel("Estimated Fan");
1271- panelScoreCenter.add(labelPlayerFan, "10, 34, center, default");
1272-
1273- labelPlayerFanDynamic = new JLabel("<dynamic>");
1274- panelScoreCenter.add(labelPlayerFanDynamic, "12, 34");
1275-
1276- button = new JButton("自動計算");
1277- button.addActionListener(new ActionListener() {
1239+ btnScorePrev = new JButton("Prev");
1240+ btnScorePrev.addActionListener(new ActionListener() {
12781241 @Override
12791242 public void actionPerformed(ActionEvent e) {
12801243 CompletableFuture.runAsync(() -> {
1281- String scoreStr = fieldScoreUserPlayed.getText();
1282- String fanStr = fieldScoreEarnedFan.getText();
1283- if(scoreStr.isEmpty() && fanStr.isEmpty()) {
1284- logger.warn("there is no data to calculate.");
1285- JOptionPane.showMessageDialog(null, "計算できるデータが存在しません。スコアかファン数のどちらかは必ず入力してください。");
1286- return;
1287- }
1288- labelPlayerScoreDynamic.setText("Calculating...");
1289- labelPlayerFanDynamic.setText("Calculating...");
1290- String roomStr = fieldScoreRoom.getText();
1291- String centerStr = fieldScoreCenter.getText();
1292- String produceStr = fieldScoreProduce.getText();
1293- String premiumStr = fieldScorePremium.getText();
1294- if(!scoreStr.isEmpty()) {
1295- int score = Integer.parseInt(scoreStr);
1296- int room = roomStr.isEmpty() ? 100 : Integer.parseInt(roomStr);
1297- int center = centerStr.isEmpty() ? 100 : Integer.parseInt(centerStr);
1298- int produce = produceStr.isEmpty() ? 100 : Integer.parseInt(produceStr);
1299- int premium = premiumStr.isEmpty() ? 100 : Integer.parseInt(premiumStr);
1300- int res = FanCalc.fanAsync(score, room, center, produce, premium).join();
1301- labelPlayerScoreDynamic.setText(scoreStr);
1302- labelPlayerFanDynamic.setText(String.valueOf(res));
1303- } else {
1304- int fan = Integer.parseInt(fanStr);
1305- int room = roomStr.isEmpty() ? 100 : Integer.parseInt(fanStr);
1306- int center = centerStr.isEmpty() ? 100 : Integer.parseInt(centerStr);
1307- int produce = produceStr.isEmpty() ? 100 : Integer.parseInt(produceStr);
1308- int premium = premiumStr.isEmpty() ? 100 : Integer.parseInt(premiumStr);
1309- int res = FanCalc.scoreAsync(fan, 1, room, center, produce, premium).join();
1310- labelPlayerFanDynamic.setText(fanStr);
1311- labelPlayerScoreDynamic.setText(String.valueOf(res));
1312- }
1313- CompletableFuture.runAsync(() -> {
1314- int labelScore = Integer.parseInt(labelPlayerScoreDynamic.getText());
1315- int estimatedPRP = PRPCalc.calcPRPFromScore(labelScore);
1316- labelPlayerPRPDynamic.setText(String.valueOf(estimatedPRP));
1317- });
1318- }, es).whenComplete((ret, ex) -> {
1319- if(ex != null) {
1320- logger.error("Exception was thrown during concurrent process.", ex);
1321- JOptionPane.showMessageDialog(null, "イベント処理中に例外が発生しました。" + ex.getLocalizedMessage());
1244+ int currentIndex = Integer.parseInt(labelScoreCurrentSongOrder.getText()) - 1;
1245+ if(currentIndex != 0) {
1246+ Song prevSong = toolIntegrateList.get(currentIndex - 1);
1247+ logger.info("currently : {} Next: {}", currentIndex + 1, currentIndex);
1248+ logger.info("prevSong: {}", prevSong);
1249+ labelScoreSongnameDynamic.setText("<html><body>" + prevSong.getName() + "</body></html>");
1250+ labelScoreAttributeDynamic.setText(prevSong.getAttribute());
1251+ labelScoreDifficultyDynamic.setText(prevSong.getDifficulty());
1252+ labelScoreLevelDynamic.setText(String.valueOf(prevSong.getLevel()));
1253+ labelScoreNotesDynamic.setText(String.valueOf(prevSong.getNotes()));
1254+ labelScoreCurrentSongOrder.setText(String.valueOf(currentIndex));
13221255 }
1323- });
1256+ }, es);
13241257 }
13251258 });
1326- panelScoreCenter.add(button, "18, 36");
1259+ panelScoreCenter.add(btnScorePrev, "14, 30");
1260+ panelScoreCenter.add(btnScoreNext, "18, 30");
13271261
1328- labelPlayerPRP = new JLabel("Estimated PRP");
1329- panelScoreCenter.add(labelPlayerPRP, "10, 38, center, default");
1262+ labelPlayerFan = new JLabel("Estimated Fan");
1263+ panelScoreCenter.add(labelPlayerFan, "10, 34, center, default");
13301264
1331- labelPlayerPRPDynamic = new JLabel("<dynamic>");
1332- panelScoreCenter.add(labelPlayerPRPDynamic, "12, 38");
1265+ labelPlayerFanDynamic = new JLabel("<dynamic>");
1266+ panelScoreCenter.add(labelPlayerFanDynamic, "12, 34");
13331267
1334- button_1 = new JButton("ファイルへ保存");
1335- button_1.addActionListener(e -> {
1268+ btnScoreFileOut = new JButton("ファイルへ保存");
1269+ btnScoreFileOut.addActionListener(e -> {
13361270 CompletableFuture.runAsync(() -> {
13371271 int currIndex = Integer.parseInt(labelScoreCurrentSongOrder.getText()) - 1;
13381272 Song curr = toolIntegrateList.get(currIndex);
@@ -1349,9 +1283,47 @@ public class DelesteRandomSelector extends JFrame {
13491283 logger.error("There was a problem during writing object file.", e1);
13501284 JOptionPane.showMessageDialog(null, "ファイル生成中にエラーが発生しました。この状況が頻発する場合は開発サイトへご連絡ください。");
13511285 }
1352- }, es);
1286+ }, es).whenCompleteAsync(this::whenCompleteProcess, es);
1287+ });
1288+
1289+ button = new JButton("自動計算");
1290+ button.addActionListener(e -> {
1291+ CompletableFuture.runAsync(() -> scoreCalcDetail(), es).whenCompleteAsync(this::whenCompleteProcess, es);
1292+ });
1293+ panelScoreCenter.add(button, "18, 34");
1294+ panelScoreCenter.add(btnScoreFileOut, "18, 36");
1295+
1296+ labelPlayerPRP = new JLabel("Estimated PRP");
1297+ panelScoreCenter.add(labelPlayerPRP, "10, 38, center, default");
1298+
1299+ labelPlayerPRPDynamic = new JLabel("<dynamic>");
1300+ panelScoreCenter.add(labelPlayerPRPDynamic, "12, 38");
1301+
1302+ btnScoreReadFile = new JButton("ファイル読込…");
1303+ btnScoreReadFile.addActionListener(e -> {
1304+ CompletableFuture.runAsync(() -> {
1305+ JFileChooser chooser = new JFileChooser(Paths.get("").toFile());
1306+ int option = chooser.showOpenDialog(this);
1307+ logger.info("user selected : {}", option);
1308+ switch (option) {
1309+ case JFileChooser.APPROVE_OPTION:
1310+ File file = chooser.getSelectedFile();
1311+ Path current = Paths.get("");
1312+ Path path = Path.of(file.getAbsolutePath());
1313+ path.relativize(current);
1314+ OutputDataStructure s = FileIO.read(path.normalize().toString());
1315+ labelScoreSongnameDynamic.setText(s.getSongname());
1316+ labelScoreLevelDynamic.setText(String.valueOf(s.getLevel()));
1317+ labelScoreDifficultyDynamic.setText(s.getDifficulty());
1318+ labelScoreAttributeDynamic.setText(s.getAttribute());
1319+ CompletableFuture.runAsync(() -> scoreCalcDetail(), es);
1320+ break;
1321+ default:
1322+ logger.warn("There is no options we can do");
1323+ }
1324+ }, es).whenCompleteAsync(this::whenCompleteProcess, es);
13531325 });
1354- panelScoreCenter.add(button_1, "18, 38");
1326+ panelScoreCenter.add(btnScoreReadFile, "18, 38");
13551327
13561328 label = new JLabel("<html><body>デレステに表示されている百分率をそのまま入力してください</body></html>");
13571329 panelScoreCenter.add(label, "6, 40");
@@ -1359,4 +1331,63 @@ public class DelesteRandomSelector extends JFrame {
13591331 setEnabled.run();
13601332 }
13611333 }
1334+
1335+ /**
1336+ * 非同期処理完了後の例外発生確認用のメソッド
1337+ * <p>
1338+ * 使用箇所が複数に渡るため抽出
1339+ * @param ret 前非同期処理での戻り値
1340+ * @param ex (存在するならば)スローされた例外
1341+ */
1342+ private void whenCompleteProcess(Void ret, Throwable ex) {
1343+ if(ex != null) {
1344+ logger.error("Exception was thrown during concurrent process.", ex);
1345+ JOptionPane.showMessageDialog(null, "イベント処理中に例外が発生しました。" + ex.getLocalizedMessage(), "内部処理エラー", ERROR);
1346+ }
1347+ }
1348+
1349+ /**
1350+ * score表示部において詳細情報を計算し表示するメソッド
1351+ * <p>
1352+ * 複数の{@link ActionEvent}で使用するため抽出
1353+ */
1354+ private void scoreCalcDetail() {
1355+ String scoreStr = fieldScoreUserPlayed.getText();
1356+ String fanStr = fieldScoreEarnedFan.getText();
1357+ if(scoreStr.isEmpty() && fanStr.isEmpty()) {
1358+ logger.warn("there is no data to calculate.");
1359+ JOptionPane.showMessageDialog(null, "計算できるデータが存在しません。スコアかファン数のどちらかは必ず入力してください。");
1360+ return;
1361+ }
1362+ labelPlayerScoreDynamic.setText("Calculating...");
1363+ labelPlayerFanDynamic.setText("Calculating...");
1364+ String roomStr = fieldScoreRoom.getText();
1365+ String centerStr = fieldScoreCenter.getText();
1366+ String produceStr = fieldScoreProduce.getText();
1367+ String premiumStr = fieldScorePremium.getText();
1368+ if(!scoreStr.isEmpty()) {
1369+ int score = Integer.parseInt(scoreStr);
1370+ int room = roomStr.isEmpty() ? 100 : Integer.parseInt(roomStr);
1371+ int center = centerStr.isEmpty() ? 100 : Integer.parseInt(centerStr);
1372+ int produce = produceStr.isEmpty() ? 100 : Integer.parseInt(produceStr);
1373+ int premium = premiumStr.isEmpty() ? 100 : Integer.parseInt(premiumStr);
1374+ int res = FanCalc.fanAsync(score, room, center, produce, premium).join();
1375+ labelPlayerScoreDynamic.setText(scoreStr);
1376+ labelPlayerFanDynamic.setText(String.valueOf(res));
1377+ } else {
1378+ int fan = Integer.parseInt(fanStr);
1379+ int room = roomStr.isEmpty() ? 100 : Integer.parseInt(fanStr);
1380+ int center = centerStr.isEmpty() ? 100 : Integer.parseInt(centerStr);
1381+ int produce = produceStr.isEmpty() ? 100 : Integer.parseInt(produceStr);
1382+ int premium = premiumStr.isEmpty() ? 100 : Integer.parseInt(premiumStr);
1383+ int res = FanCalc.scoreAsync(fan, 1, room, center, produce, premium).join();
1384+ labelPlayerFanDynamic.setText(fanStr);
1385+ labelPlayerScoreDynamic.setText(String.valueOf(res));
1386+ }
1387+ CompletableFuture.runAsync(() -> {
1388+ int labelScore = Integer.parseInt(labelPlayerScoreDynamic.getText());
1389+ int estimatedPRP = PRPCalc.calcPRPFromScore(labelScore);
1390+ labelPlayerPRPDynamic.setText(String.valueOf(estimatedPRP));
1391+ });
1392+ }
13621393 }
Show on old repository browser