Skip to content

Commit

Permalink
Merge pull request #15 from hizumiaoba/TestBranch
Browse files Browse the repository at this point in the history
feat: Async update function
  • Loading branch information
hizumiaoba authored Sep 12, 2021
2 parents 2619d61 + ff93bc2 commit 44ab0df
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 18 deletions.
86 changes: 85 additions & 1 deletion database.json
Original file line number Diff line number Diff line change
Expand Up @@ -11504,7 +11504,7 @@
}, {
"attribute" : "全タイプ",
"name" : "Hungry Bambi",
"difficulty" : "MASTER+",
"difficulty" : "ⓁMASTER+",
"level" : 30,
"notes" : 999
}, {
Expand Down Expand Up @@ -11975,5 +11975,89 @@
"difficulty" : "MASTER+",
"level" : 28,
"notes" : 803
}, {
"attribute" : "全タイプ",
"name" : "星環世界",
"difficulty" : "DEBUT",
"level" : 7,
"notes" : 103
}, {
"attribute" : "全タイプ",
"name" : "星環世界",
"difficulty" : "REGULAR",
"level" : 13,
"notes" : 175
}, {
"attribute" : "全タイプ",
"name" : "星環世界",
"difficulty" : "PRO",
"level" : 17,
"notes" : 335
}, {
"attribute" : "全タイプ",
"name" : "星環世界",
"difficulty" : "MASTER",
"level" : 25,
"notes" : 590
}, {
"attribute" : "全タイプ",
"name" : "星環世界",
"difficulty" : "MASTER+",
"level" : 29,
"notes" : 900
}, {
"attribute" : "全タイプ",
"name" : "星環世界",
"difficulty" : "PIANO",
"level" : 26,
"notes" : 702
}, {
"attribute" : "全タイプ",
"name" : "星環世界",
"difficulty" : "FORTE",
"level" : 31,
"notes" : 1053
}, {
"attribute" : "全タイプ",
"name" : "イリュージョニスタ!",
"difficulty" : "WITCH",
"level" : 28,
"notes" : 652
}, {
"attribute" : "全タイプ",
"name" : "Hungry Bambi",
"difficulty" : "MASTER+",
"level" : 30,
"notes" : 999
}, {
"attribute" : "パッション",
"name" : "Shinobi 4.0 忍者のすゝめ",
"difficulty" : "MASTER+",
"level" : 29,
"notes" : 999
}, {
"attribute" : "パッション",
"name" : "にょわにょわーるど☆",
"difficulty" : "DEBUT",
"level" : 7,
"notes" : 101
}, {
"attribute" : "パッション",
"name" : "にょわにょわーるど☆",
"difficulty" : "REGULAR",
"level" : 12,
"notes" : 172
}, {
"attribute" : "パッション",
"name" : "にょわにょわーるど☆",
"difficulty" : "PRO",
"level" : 17,
"notes" : 340
}, {
"attribute" : "パッション",
"name" : "にょわにょわーるど☆",
"difficulty" : "MASTER",
"level" : 24,
"notes" : 541
} ]
}
37 changes: 20 additions & 17 deletions src/com/ranfa/main/DelesteRandomSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.BiConsumer;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
Expand All @@ -40,7 +38,7 @@
import com.ranfa.lib.TwitterIntegration;
import com.ranfa.lib.Version;

@Version(major = 1, minor = 0, patch = 2)
@Version(major = 1, minor = 1, patch = 0)
public class DelesteRandomSelector extends JFrame {

private static ArrayList<Song> selectedSongsList = new ArrayList<Song>();
Expand Down Expand Up @@ -96,6 +94,7 @@ public void run() {
* Create the frame.
*/
public DelesteRandomSelector() {
ExecutorService es = Executors.newWorkStealingPool();
if(!Settings.fileExists() && !Settings.writeDownJSON()) {
JOptionPane.showMessageDialog(this, "Exception:NullPointerException\nCannot Keep up! Please re-download this Application!");
throw new NullPointerException("FATAL: cannot continue!");
Expand All @@ -122,23 +121,27 @@ public DelesteRandomSelector() {
JOptionPane.showMessageDialog(this, "Exception:NullPointerException\\nCannot Keep up! Please re-download this Application!");
throw new NullPointerException("FATAL: cannot continue!");
}
} else if(Scraping.getFromJson().size() < Scraping.getWholeData().size()) {
LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Update detected.Initiate update process...");
Path path = Paths.get(Scraping.getDBPath());
try {
Files.delete(path);
} catch (IOException e1) {
LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[FATAL]: " + "Exception while updating library.\n" + e1.getLocalizedMessage());
JOptionPane.showMessageDialog(null, "データベースファイルをアップデートできませんでした。ファイルの削除権限があるかどうか確認してください。\n" + e1.getLocalizedMessage());
}
Scraping.writeToJson(Scraping.getWholeData());
LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Library update completed.");
}
ExecutorService es = Executors.newWorkStealingPool();
CompletableFuture<ArrayList<Song>> updateFuture = CompletableFuture.supplyAsync(() -> Scraping.getWholeData(), es);
CompletableFuture<ArrayList<Song>> updateLocalFuture = CompletableFuture.supplyAsync(() -> Scraping.getFromJson(), es);
BiConsumer<ArrayList<Song>, ArrayList<Song>> updateConsumer = (list1, list2) -> {
if(list1.size() > list2.size()) {
Scraping.writeToJson(list1);
}
};
CompletableFuture<ArrayList<Song>> getFromJsonFuture = CompletableFuture.supplyAsync(() -> Scraping.getFromJson(), es);
CompletableFuture<ArrayList<Song>> getWholeDataFuture = CompletableFuture.supplyAsync(() -> Scraping.getWholeData(), es);
getWholeDataFuture.thenAcceptAsync(list -> LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: Scraping data size:" + list.size()), es);
getFromJsonFuture.thenAcceptAsync(list -> LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: Currently database size:" + list.size()), es);
try {
updateConsumer.accept(updateFuture.get(), updateLocalFuture.get());
} catch (InterruptedException e1) {
// TODO 自動生成された catch ブロック
e1.printStackTrace();
} catch (ExecutionException e1) {
// TODO 自動生成された catch ブロック
e1.printStackTrace();
}
LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[DEBUG]: " + "Version:" + getVersion());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 640, 360);
Expand Down

0 comments on commit 44ab0df

Please sign in to comment.