refactoring WaitForScore

This commit is contained in:
Lorenzo Iovino 2017-07-12 17:07:12 +02:00
parent eac6e43420
commit e2070cf597
17 changed files with 757 additions and 410 deletions

View file

@ -1,48 +1,45 @@
package utilities;
import java.io.*;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Date;
/**
* Created by loke on 15/06/2017.
* Author: Lorenzo Iovino on 15/06/2017.
* Description: This is a module for logging the System output in files
*/
public class Logger {
private static File logFile;
private static String name;
private final File logFile;
private final String name;
private static PrintWriter out;
private static BufferedWriter bw;
private static FileWriter fw;
private Boolean debug;
public Logger(File logFile, String name) throws IOException {
public Logger(File logFile, String name, Boolean debug) throws IOException {
this.logFile = logFile;
this.name = name;
this.debug = debug;
}
public synchronized static void write(String msg){
public synchronized void write(String msg){
try {
fw = new FileWriter(logFile, true);
bw = new BufferedWriter(fw);
out = new PrintWriter(bw);
Date d = new Date();
out.append("LOGGER ("+name+"): " + d.toString() + " - " + msg + "\n");
System.out.println("LOGGER ("+name+"): " + d.toString() + " - " + msg + "\n");
if(debug) {
System.out.println("LOGGER (" + name + "): " + d.toString() + " - " + msg + "\n");
}
} catch (IOException e) {
e.printStackTrace();
}
finally {
out.close();
try {
out.close();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();

View file

@ -0,0 +1,21 @@
package utilities;
import javafx.util.Pair;
import javax.swing.*;
/**
* Author: Lorenzo Iovino on 12/07/2017.
* Description: This is a module of parse utilities for different purposes
*/
public class Parse {
//Parse score and split by ":" character
public static DefaultListModel<Pair<String, Integer>> score(DefaultListModel<String> score) {
DefaultListModel<Pair<String, Integer>> list = new DefaultListModel<>();
for (int i = 0; i < score.size() - 1; i++) {
String[] splitted = score.get(i).split(":");
list.addElement(new Pair<>(splitted[0], new Integer(splitted[1])));
}
return list;
}
}