OSDN Git Service

fix: code fixing for new feature
authorhizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Sat, 13 Nov 2021 15:01:38 +0000 (00:01 +0900)
committerhizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Sat, 13 Nov 2021 15:01:38 +0000 (00:01 +0900)
generated/albumCycle.json [new file with mode: 0644]
generated/database.json
src/com/ranfa/lib/EstimateAlbumTypeCycle.java
src/com/ranfa/lib/Scraping.java
src/com/ranfa/main/DelesteRandomSelector.java

diff --git a/generated/albumCycle.json b/generated/albumCycle.json
new file mode 100644 (file)
index 0000000..6d4508e
--- /dev/null
@@ -0,0 +1,5 @@
+{
+  "type" : "ALBUM A",
+  "daysLeft" : 0,
+  "dateDefinited" : "2021/11/13"
+}
\ No newline at end of file
index 6982028..6951d71 100644 (file)
   }, {
     "attribute" : "キュート",
     "name" : "Home Sweet Home",
-    "difficulty" : "MASTER+",
+    "difficulty" : "MASTER+",
     "level" : 28,
     "notes" : 771,
-    "albumType" : "Not-implemented"
+    "albumType" : "ALBUM A"
   }, {
     "attribute" : "キュート",
     "name" : "ギュっとMilky Way",
     "name" : "Let’s Sail Away!!!",
     "difficulty" : "MASTER+",
     "level" : 29,
-    "notes" : 992,実装
+    "notes" : 992,
     "albumType" : "Not-implemented"
   }, {
     "attribute" : "全タイプ",
     "level" : 28,
     "notes" : 669,
     "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "キュート",
+    "name" : "Home Sweet Home",
+    "difficulty" : "MASTER+",
+    "level" : 28,
+    "notes" : 777,
+    "albumType" : "ALBUM A"
+  }, {
+    "attribute" : "キュート",
+    "name" : "おかしな国のおかし屋さん",
+    "difficulty" : "MASTER+",
+    "level" : 27,
+    "notes" : 834,
+    "albumType" : "ALBUM A"
   } ]
 }
\ No newline at end of file
index c2d5612..b5755b2 100644 (file)
@@ -1,5 +1,7 @@
 package com.ranfa.lib;
 
+import static org.hamcrest.CoreMatchers.nullValue;
+
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Paths;
@@ -8,6 +10,7 @@ import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.ZoneId;
 import java.time.temporal.ChronoUnit;
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Date;
 
@@ -16,27 +19,24 @@ import javax.swing.JOptionPane;
 import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.ObjectWriter;
-import com.sun.org.apache.bcel.internal.generic.NEW;
-import com.sun.security.auth.NTDomainPrincipal;
 
 public class EstimateAlbumTypeCycle {
 
        private final static String CYCLEPATH = "generated/albumCycle.json";
-       private final static String DATEFORMAT = "YYYY:MM:DD";
+       private final static String DATEFORMAT = "YYYY/MM/dd";
        private final static SimpleDateFormat FORMAT = new SimpleDateFormat(DATEFORMAT);
 
        public final static String ALBUM_A = "ALBUM A";
        public final static String ALBUM_B = "ALBUM B";
        public final static String ALBUM_C = "ALBUM C";
 
-       public static void preInitialization() {
+       public static void Initialization() {
                if(Files.exists(Paths.get(CYCLEPATH)))
                        return;
                LimitedLog.println(EstimateAlbumTypeCycle.class + ":[INFO]: " + "Cycle definition file does not exist.Trying to ask you...");
                AlbumCycleDefinitionProperty property = new AlbumCycleDefinitionProperty();
                String inputType = JOptionPane.showInputDialog("現在のMASTER+のALBUMを入力してください。(A,B,C)");
-               if(!inputType.equals("A") || !inputType.equals("B") || !inputType.equals("C")) {
-
+               if(!(inputType.equals("A") || inputType.equals("B") || inputType.equals("C"))) {
                        LimitedLog.println(EstimateAlbumTypeCycle.class + ":[FATAL]; " + "inputType has invaild.Canceling initiate...");
                        return;
                }
@@ -58,7 +58,7 @@ public class EstimateAlbumTypeCycle {
                        e.printStackTrace();
                }
        }
-/*
+
        public static String getCurrentCycle() {
                if(Files.notExists(Paths.get(CYCLEPATH)))
                        throw new IllegalStateException("Program seems to have avoided first initiating. how could it have done?");
@@ -76,41 +76,43 @@ public class EstimateAlbumTypeCycle {
                presentCalendar.set(Calendar.SECOND, 0);
                presentCalendar.set(Calendar.MILLISECOND, 0);
                presentDate = presentCalendar.getTime();
-               Date definiteDate  = null;
-               try {
-                       definiteDate = FORMAT.parse(property.getDateDefinited());
-               } catch (ParseException e) {
-                       e.printStackTrace();
-               }
-               presentCalendar.setTime(definiteDate);
-               presentCalendar.setTime(presentDate);
-               presentCalendar.set(Calendar.HOUR_OF_DAY, 0);
-               presentCalendar.set(Calendar.MINUTE, 0);
-               presentCalendar.set(Calendar.SECOND, 0);
-               presentCalendar.set(Calendar.MILLISECOND, 0);
-               definiteDate = presentCalendar.getTime();
+               String dateDefinited = property.getDateDefinited();
+               String dates[] = dateDefinited.split("/");
+               presentCalendar.set(Integer.parseInt(dates[0]), Integer.parseInt(dates[1]) - 1, Integer.parseInt(dates[2]));
+               Date definiteDate = presentCalendar.getTime();
                switch(presentDate.compareTo(definiteDate)) {
                case 0:
                        return property.getType();
                case 1:
                        LocalDate presentLocalDate = presentDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        LocalDate definitedLocalDate = definiteDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
-                       long delta = ChronoUnit.DAYS.between(presentLocalDate, definitedLocalDate);
-                       if(delta < property.getDaysLeft())
+                       long delta = ChronoUnit.DAYS.between(definitedLocalDate, presentLocalDate);
+                       if(delta < property.getDaysLeft()) {
                                return property.getType();
+                       }
                        delta = delta - property.getDaysLeft();
-                       long cycleDelta = (delta / 14) % 3;
-                       if(cycleDelta == 0) {
-
+                       if(delta > Integer.MAX_VALUE) {
+                               JOptionPane.showMessageDialog(null, "ALBUM周期の推定に失敗しました。暫定的な措置として前回起動時のALBUM種類を表示します。\n(内部変数エラー:delta has the value that is more than Integer.MAX_VALUE.)");
+                               LimitedLog.println(EstimateAlbumTypeCycle.class + ":[FATAL]; " + "Valuable was overflowed.");
                        }
+                       String res = cycling(property.getType(), (int)delta);
+                       return res;
+               default:
+                       throw new IllegalStateException("Date delta has illegal value. the system clock might be incorrect?");
                }
        }
-*/
-
-       public static void initialization() {
-               if(Files.notExists(Paths.get(CYCLEPATH)))
-                       throw new IllegalStateException("Cycle data doesn't exist. but this is impossible.Please contact developer.");
 
+       private static String cycling(String currentType, int times) {
+               int cyclingDelta = times % 3;
+               String[] typeArray = {
+                               ALBUM_A,
+                               ALBUM_B,
+                               ALBUM_C
+               };
+               int currentIndex = Arrays.asList(typeArray).indexOf(currentType);
+               int nextIndex = currentIndex + cyclingDelta;
+               int nextIndexDelta = nextIndex % 3;
+               return typeArray[nextIndexDelta];
        }
 
 }
index ebac8c1..386b732 100644 (file)
@@ -16,6 +16,7 @@ import javax.swing.JOptionPane;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.select.Elements;
+import org.junit.internal.ArrayComparisonFailure;
 
 import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -183,6 +184,18 @@ public class Scraping {
                return res;
        }
 
+       public static ArrayList<Song> getSpecificAlbumTypeSongs(ArrayList<Song> data, String type) {
+               if(data == null)
+                       throw new IllegalArgumentException("type must not null.");
+               if(data.isEmpty())
+                       throw new IllegalArgumentException("ArrayList must not empty");
+               ArrayList<Song> res = new ArrayList<>();
+               data.stream()
+                       .filter(element -> element.getAlbumType().equals(type))
+                       .forEach(res::add);
+               return res;
+       }
+
        private static ArrayList<Song> getOnlyLevelSongs(ArrayList<Song> data, int level) {
                ArrayList<Song> res = new ArrayList<Song>();
                data.stream()
index 9d4b605..6591068 100644 (file)
@@ -1,10 +1,14 @@
 package com.ranfa.main;
 
+import static org.hamcrest.CoreMatchers.nullValue;
+
 import java.awt.BorderLayout;
 import java.awt.EventQueue;
 import java.awt.Font;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Random;
 import java.util.concurrent.CompletableFuture;
@@ -30,6 +34,7 @@ import com.jgoodies.forms.layout.FormLayout;
 import com.jgoodies.forms.layout.FormSpecs;
 import com.jgoodies.forms.layout.RowSpec;
 import com.ranfa.lib.CheckVersion;
+import com.ranfa.lib.EstimateAlbumTypeCycle;
 import com.ranfa.lib.LimitedLog;
 import com.ranfa.lib.Scraping;
 import com.ranfa.lib.SettingJSONProperty;
@@ -68,6 +73,8 @@ public class DelesteRandomSelector extends JFrame {
        private JTextArea textArea;
        private JScrollPane scrollPane;
        private CompletableFuture<Void> softwareUpdateFuture = null;
+       private CompletableFuture<Void> albumTypeEstimateFuture = null;
+       private String albumType = "計算中";
 
        /**
         * Launch the application.
@@ -125,6 +132,10 @@ public class DelesteRandomSelector extends JFrame {
                                + "\nSong Limit: " + property.getSongLimit()
                                + "\nSaveScoreLog: " + property.isSaveScoreLog()
                                + "\nOutputDebugSentences: " + property.isOutputDebugSentences());
+               EstimateAlbumTypeCycle.Initialization();
+               if(Files.exists(Paths.get("generated/albumCycle.json"))) {
+                       albumType = EstimateAlbumTypeCycle.getCurrentCycle();
+               }
                if(property.isCheckVersion()) {
                        softwareUpdateFuture = CompletableFuture.runAsync(() -> CheckVersion.needToBeUpdated(), es);
                }
@@ -159,6 +170,7 @@ public class DelesteRandomSelector extends JFrame {
                LimitedLog.println(this.getClass() + ":[DEBUG]: " + "Version:" + CheckVersion.getVersion());
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                setBounds(100, 100, property.getWindowWidth(), property.getWindowHeight());
+               // setBounds(100, 100, 640, 360);
                contentPane = new JPanel();
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setContentPane(contentPane);
@@ -268,9 +280,10 @@ public class DelesteRandomSelector extends JFrame {
                                        ArrayList<Song> specificlevelList = Scraping.getSpecificLevelSongs(fromJson, (Integer)spinnerLevel.getValue(), checkLessLv.isSelected(), checkMoreLv.isSelected());
                                        ArrayList<Song> specificDifficultyList = Scraping.getSpecificDifficultySongs(specificlevelList, comboDifficultySelect.getSelectedItem().toString());
                                        ArrayList<Song> specificAttributeList = Scraping.getSpecificAttributeSongs(specificDifficultyList, comboAttribute.getSelectedItem().toString());
+                                       ArrayList<Song> specificTypeList = Scraping.getSpecificAlbumTypeSongs(specificAttributeList, EstimateAlbumTypeCycle.getCurrentCycle());
                                        if(!selectedSongsList.isEmpty())
                                        selectedSongsList.clear();
-                               selectedSongsList.addAll(specificAttributeList);
+                               selectedSongsList.addAll((comboDifficultySelect.getSelectedItem().equals(Scraping.MASTERPLUS) || comboDifficultySelect.getSelectedItem().equals(Scraping.LEGACYMASTERPLUS)) ? specificTypeList : specificAttributeList);
                                LimitedLog.println(this.getClass() + ":[INFO]: " +"Songs are selected.We are Ready to go.");
                                JOptionPane.showMessageDialog(null, "絞り込み完了!「開始」をクリックすることで選曲できます!");
                        }
@@ -286,7 +299,8 @@ public class DelesteRandomSelector extends JFrame {
                                integratorArray = new String[property.getSongLimit()];
                                for(int i = 0; i < property.getSongLimit(); i++) {
                                        int randomInt = random.nextInt(selectedSongsList.size());
-                                       paneString = paneString + (i + 1) + "曲目: " + selectedSongsList.get(randomInt).getAttribute() + " [" + selectedSongsList.get(randomInt).getDifficulty() + "]「" + selectedSongsList.get(randomInt).getName() + "」!(Lv:" + selectedSongsList.get(randomInt).getLevel() + ")\n\n";
+                                       String typeString = comboDifficultySelect.getSelectedItem().equals(Scraping.MASTERPLUS) || comboDifficultySelect.getSelectedItem().equals(Scraping.LEGACYMASTERPLUS) ? EstimateAlbumTypeCycle.getCurrentCycle() : "";
+                                       paneString = paneString + (i + 1) + "曲目: " + selectedSongsList.get(randomInt).getAttribute() + " [" + selectedSongsList.get(randomInt).getDifficulty() + "]「" + selectedSongsList.get(randomInt).getName() + "」!(Lv:" + selectedSongsList.get(randomInt).getLevel() + " " + typeString + ")\n\n";
                                        integratorArray[i] = selectedSongsList.get(randomInt).getName() + "(Lv" + selectedSongsList.get(randomInt).getLevel() + ")\n";
                                }
                                paneString = paneString + "この" + property.getSongLimit() + "曲をプレイしましょう!!!";
@@ -357,7 +371,7 @@ public class DelesteRandomSelector extends JFrame {
                                                                btnExit = new JButton("終了");
                                                                btnExit.addActionListener(new ActionListener() {
                                                                        public void actionPerformed(ActionEvent e) {
-                                                                               if(softwareUpdateFuture.isDone()) {
+                                                                               if(softwareUpdateFuture.isDone() || albumTypeEstimateFuture.isDone()) {
                                                                                        LimitedLog.println(this.getClass() + ":[INFO]: " +"Requested Exit by Button");
                                                                                        System.exit(0);
                                                                                } else {
@@ -373,13 +387,14 @@ public class DelesteRandomSelector extends JFrame {
                panelCentre.setLayout(new BorderLayout(0, 0));
 
                textArea = new JTextArea();
-               textArea.setText("楽曲選択の手順\r\n1.難易度、属性、レベルを選択する\r\n2.「楽曲取り込み」ボタンを押す!\r\n3.「開始」ボタンを押す!\r\n4.選択された楽曲がここに表示されます!\r\n現在設定されている楽曲選択の最大数:" + property.getSongLimit());
+               textArea.setText("楽曲選択の手順\r\n1.難易度、属性、レベルを選択する\r\n2.「楽曲取り込み」ボタンを押す!\r\n3.「開始」ボタンを押す!\r\n4.選択された楽曲がここに表示されます!\r\n現在設定されている楽曲選択の最大数:" + property.getSongLimit() + "\n現在のMASTER+アルバム周期(推定):" + albumType);
                textArea.setEditable(false);
 
                scrollPane = new JScrollPane(textArea);
                panelCentre.add(scrollPane, BorderLayout.CENTER);
-               if(isFirst || !property.isCheckLibraryUpdates())
+               if(isFirst || !property.isCheckLibraryUpdates()) {
                        setEnabled.run();
+               }
        }
 
 }