// Path: src/main/java/tenhouvisualizer/Main.java
// public class Main extends Application {
// 
//     private final static Logger log = LoggerFactory.getLogger(Main.class);
// 
//     public static DatabaseService databaseService;
//     public static Properties properties;
// 
//     public static void main(String[] args) {
//         launch(args);
//     }
// 
//     @Override
//     public void start(Stage stage) throws IOException {
//         log.info("start!");
// 
//         properties = new Properties();
//         File configationFile = new File("./tenhouvisualizer.properties");
//         if (configationFile.isFile()) {
//             try (InputStream is = new FileInputStream(configationFile)) {
//                 properties.load(is);
//             }
//         }
//         if (!properties.containsKey("css")) {
//             properties.setProperty("css", "/darcula.css");
//         }
// 
//         try {
//             Main.databaseService = new DatabaseService(new File("./tenhouvisualizer.sqlite"));
//         } catch (ClassNotFoundException | SQLException e) {
//             e.printStackTrace();
//         }
// 
//         Parent root = FXMLLoader.load(getClass().getResource("/app.fxml"));
//         root.getStylesheets().add(this.getClass().getResource(Main.properties.getProperty("css")).toExternalForm());
//         Scene scene = new Scene(root);
//         stage.setScene(scene);
//         stage.setTitle("Tenhou Visualizer");
//         stage.show();
//     }
// 
//     @Override
//     public void stop() throws Exception {
//         super.stop();
//         Main.databaseService.close();
//         log.info("stop!");
//     }
// }


import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tenhouvisualizer.Main;
import java.net.URL;
import java.util.*;
import java.util.regex.Pattern;
            matchMinField.setText(String.valueOf(DEFAULT_MATCH_MIN));
        }
        if (isNotSmallNumberString(showMaxField.getText())) {
            showMaxField.setText(String.valueOf(DEFAULT_SHOW_MAX));
        }

        boolean isSanma = sanmaRadioButton.isSelected();
        boolean isTonnan = tonnanRadioButton.isSelected();
        String playerName = filterField.getText();
        int matchMin = Integer.parseInt(matchMinField.getText());
        int showMax = Integer.parseInt(showMaxField.getText());

        rankingTableView.setItems(rankWinnerAndLoser(isSanma, isTonnan, playerName, matchMin, showMax));
    }

    public void clear(ActionEvent actionEvent) {
        sanmaRadioButton.setSelected(true);
        tonnanRadioButton.setSelected(true);
        filterField.clear();
        matchMinField.setText(String.valueOf(DEFAULT_MATCH_MIN));
        showMaxField.setText(String.valueOf(DEFAULT_SHOW_MAX));
    }

    public void clearFilterField(ActionEvent actionEvent) {
        filterField.clear();
        filterField.requestFocus();
    }

    private ObservableList<Donation> rankWinnerAndLoser(boolean isSanma, boolean isTonnan, String playerName,
                                                        int matchMin, int showMax) {
// Path: src/main/java/tenhouvisualizer/Main.java
// public class Main extends Application {
// 
//     private final static Logger log = LoggerFactory.getLogger(Main.class);
// 
//     public static DatabaseService databaseService;
//     public static Properties properties;
// 
//     public static void main(String[] args) {
//         launch(args);
//     }
// 
//     @Override
//     public void start(Stage stage) throws IOException {
//         log.info("start!");
// 
//         properties = new Properties();
//         File configationFile = new File("./tenhouvisualizer.properties");
//         if (configationFile.isFile()) {
//             try (InputStream is = new FileInputStream(configationFile)) {
//                 properties.load(is);
//             }
//         }
//         if (!properties.containsKey("css")) {
//             properties.setProperty("css", "/darcula.css");
//         }
// 
//         try {
//             Main.databaseService = new DatabaseService(new File("./tenhouvisualizer.sqlite"));
//         } catch (ClassNotFoundException | SQLException e) {
//             e.printStackTrace();
//         }
// 
//         Parent root = FXMLLoader.load(getClass().getResource("/app.fxml"));
//         root.getStylesheets().add(this.getClass().getResource(Main.properties.getProperty("css")).toExternalForm());
//         Scene scene = new Scene(root);
//         stage.setScene(scene);
//         stage.setTitle("Tenhou Visualizer");
//         stage.show();
//     }
// 
//     @Override
//     public void stop() throws Exception {
//         super.stop();
//         Main.databaseService.close();
//         log.info("stop!");
//     }
// }


// Path: src/main/java/tenhouvisualizer/app/donatationranker/DonationRankerController.java
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tenhouvisualizer.Main;
import java.net.URL;
import java.util.*;
import java.util.regex.Pattern;

            matchMinField.setText(String.valueOf(DEFAULT_MATCH_MIN));
        }
        if (isNotSmallNumberString(showMaxField.getText())) {
            showMaxField.setText(String.valueOf(DEFAULT_SHOW_MAX));
        }

        boolean isSanma = sanmaRadioButton.isSelected();
        boolean isTonnan = tonnanRadioButton.isSelected();
        String playerName = filterField.getText();
        int matchMin = Integer.parseInt(matchMinField.getText());
        int showMax = Integer.parseInt(showMaxField.getText());

        rankingTableView.setItems(rankWinnerAndLoser(isSanma, isTonnan, playerName, matchMin, showMax));
    }

    public void clear(ActionEvent actionEvent) {
        sanmaRadioButton.setSelected(true);
        tonnanRadioButton.setSelected(true);
        filterField.clear();
        matchMinField.setText(String.valueOf(DEFAULT_MATCH_MIN));
        showMaxField.setText(String.valueOf(DEFAULT_SHOW_MAX));
    }

    public void clearFilterField(ActionEvent actionEvent) {
        filterField.clear();
        filterField.requestFocus();
    }

    private ObservableList<Donation> rankWinnerAndLoser(boolean isSanma, boolean isTonnan, String playerName,
                                                        int matchMin, int showMax) {
        List<String[]> list = Main.databaseService.findWinnerAndLoser(isSanma, isTonnan, playerName);