Skip to content
Snippets Groups Projects
Commit df4ced57 authored by Nicolai Hollup Brand's avatar Nicolai Hollup Brand :penguin:
Browse files

refactor: Use generics and return abstract superclasses where applicable

parent 5b7849a4
No related branches found
No related tags found
No related merge requests found
...@@ -14,11 +14,11 @@ import java.util.stream.Collectors; ...@@ -14,11 +14,11 @@ import java.util.stream.Collectors;
* Two armies fight each other. * Two armies fight each other.
* *
* @author Nicolai Brand * @author Nicolai Brand
* @version 16.05.2022 * @version 20.05.2022
*/ */
public class Army { public class Army {
private String name; private String name;
private ArrayList<Unit> units; private final ArrayList<Unit> units;
/** /**
* Default constructor * Default constructor
...@@ -40,10 +40,10 @@ public class Army { ...@@ -40,10 +40,10 @@ public class Army {
* @param units the units * @param units the units
* @throws IllegalArgumentException the illegal argument exception * @throws IllegalArgumentException the illegal argument exception
*/ */
public Army(String name, ArrayList<Unit> units) throws IllegalArgumentException { public Army(String name, List<Unit> units) throws IllegalArgumentException {
if (name.isBlank()) throw new IllegalArgumentException("Name can't be empty"); if (name.isBlank()) throw new IllegalArgumentException("Name can't be empty");
this.name = name; this.name = name;
this.units = units; this.units = (ArrayList<Unit>) units;
} }
/** /**
...@@ -178,7 +178,7 @@ public class Army { ...@@ -178,7 +178,7 @@ public class Army {
* *
* @return units, ArrayList<Unit>. * @return units, ArrayList<Unit>.
*/ */
public ArrayList<Unit> getUnits() { public List<Unit> getUnits() {
return units; return units;
} }
......
...@@ -29,7 +29,7 @@ import java.io.IOException; ...@@ -29,7 +29,7 @@ import java.io.IOException;
* of the data. * of the data.
* *
* @author Nicolai H. Brand. * @author Nicolai H. Brand.
* @version 19.05.2022 * @version 20.05.2022
*/ */
public final class DataHolderSingleton { public final class DataHolderSingleton {
...@@ -43,7 +43,7 @@ public final class DataHolderSingleton { ...@@ -43,7 +43,7 @@ public final class DataHolderSingleton {
private static Army armyOneCopy; private static Army armyOneCopy;
private static Army armyTwoCopy; private static Army armyTwoCopy;
private static Battle battle; private static Battle battle;
private static Logger battleLog = new Logger(true); private static Logger<String> battleLog = new Logger(true);
private final static StringProperty armyOnePath = new SimpleStringProperty("filename"); private final static StringProperty armyOnePath = new SimpleStringProperty("filename");
private final static StringProperty armyTwoPath = new SimpleStringProperty("filename"); private final static StringProperty armyTwoPath = new SimpleStringProperty("filename");
......
...@@ -14,8 +14,8 @@ import javafx.collections.ObservableList; ...@@ -14,8 +14,8 @@ import javafx.collections.ObservableList;
* @author Nicolai H. Brand. * @author Nicolai H. Brand.
* @version 20.05.2022. * @version 20.05.2022.
*/ */
public class Logger { public class Logger<T> {
private final ObservableList<String> log; private final ObservableList<T> log;
/* Will add new log items to index 0 of the array if reverse flag is set to true */ /* Will add new log items to index 0 of the array if reverse flag is set to true */
private final boolean REVERSE_FLAG; private final boolean REVERSE_FLAG;
...@@ -43,7 +43,7 @@ public class Logger { ...@@ -43,7 +43,7 @@ public class Logger {
* *
* @param item String, the new item to be added to the log. * @param item String, the new item to be added to the log.
*/ */
public void addLogItem(String item) { public void addLogItem(T item) {
if (REVERSE_FLAG) if (REVERSE_FLAG)
log.add(0, item); log.add(0, item);
else else
...@@ -59,7 +59,7 @@ public class Logger { ...@@ -59,7 +59,7 @@ public class Logger {
} }
// getter // getter
public ObservableList<String> getLog() { public ObservableList<T> getLog() {
return log; return log;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment