Skip to content
Snippets Groups Projects
Commit a5959dde authored by Lukas Köhler's avatar Lukas Köhler
Browse files

chg refactoring for new checkstyles

parent 6e8aae55
Branches
No related tags found
1 merge request!42020 03 02 major update
Showing with 374 additions and 341 deletions
......@@ -3,8 +3,7 @@ package de.hda.fbi.db2.api;
import java.util.List;
/**
* API Class for lab01
* Created by l.koehler on 05.08.2019.
* API Class for lab01 Created by l.koehler on 05.08.2019.
*/
public abstract class Lab01Data {
......
......@@ -3,12 +3,12 @@ package de.hda.fbi.db2.api;
import javax.persistence.EntityManager;
/**
* API Class for lab02
* Created by l.koehler on 05.08.2019.
* API Class for lab02 Created by l.koehler on 05.08.2019.
*/
public abstract class Lab02EntityManager {
public void init() {}
public void init() {
}
/**
* You can use the data from lab01, this variable will be automatically set.
......@@ -16,7 +16,7 @@ public abstract class Lab02EntityManager {
protected Lab01Data lab01Data;
/**
* Setter for Lab01Data; Don't overwrite, you will break the automation!
* Setter for Lab01Data; Don't overwrite, you will break the automation.
*
* @param lab01Data lab01Data
*/
......
......@@ -3,12 +3,12 @@ package de.hda.fbi.db2.api;
import java.util.List;
/**
* API Class for lab03
* Created by l.koehler on 05.08.2019.
* API Class for lab03 Created by l.koehler on 05.08.2019.
*/
public abstract class Lab03Game {
public void init() {}
public void init() {
}
/**
* You can use the data from lab01, this variable will be automatically set.
......@@ -16,8 +16,8 @@ public abstract class Lab03Game {
protected Lab01Data lab01Data;
/**
* You can use the EntityManager or other stuff from lab02,
* this variable will be automatically set.
* You can use the EntityManager or other stuff from lab02, this variable will be automatically
* set.
*/
protected Lab02EntityManager lab02EntityManager;
......@@ -40,29 +40,19 @@ public abstract class Lab03Game {
}
/**
* This method should create a game. For this you have to do the following things:
* - Ask for player
* - Ask for categories
* - Ask for maximum questions per category and choose questions
* <p>
* You do not have to play the game here. This should only create a game
* This method should create a game. For this you have to do the following things: - Ask for
* player - Ask for categories - Ask for maximum questions per category and choose questions
*
* <p>You do not have to play the game here. This should only create a game
*
* @return the game entity object. IMPORTANT: This has to be a entity.
*/
public abstract Object createGame();
/**
* Here you have to play the game 'game'.
*
* @param game the game that should be played
*/
public abstract void playGame(Object game);
/**
* This should create a game with the given arguments.
* You do not have to read data from console.
* The game should be create only with the given arguments.
* You do not have to play the game here.
* This should create a game with the given arguments. You do not have to read data from console.
* The game should be create only with the given arguments. You do not have to play the game
* here.
*
* @param playerName name of the player
* @param questions chosen questions
......@@ -70,6 +60,13 @@ public abstract class Lab03Game {
*/
public abstract Object createGame(String playerName, List<Object> questions);
/**
* Here you have to play the game 'game'.
*
* @param game the game that should be played
*/
public abstract void playGame(Object game);
/**
* Simulate a game play. You do not have to read anything from console.
*
......@@ -103,6 +100,7 @@ public abstract class Lab03Game {
/**
* persist the game object in the database.
*
* @param game given game
*/
public abstract void persistGame(Object game);
......
package de.hda.fbi.db2.api;
/**
*
* Api for MassData.
*/
public abstract class Lab04MassData {
public void init() {}
public void init() {
}
/**
* You can use the data from lab01, this variable will be automatically set.
......@@ -13,8 +14,8 @@ public abstract class Lab04MassData {
protected Lab01Data lab01Data;
/**
* You can use the EntityManager or other stuff from lab02,
* this variable will be automatically set.
* You can use the EntityManager or other stuff from lab02, this variable will be automatically
* set.
*/
protected Lab02EntityManager lab02EntityManager;
......
package de.hda.fbi.db2.controller;
import de.hda.fbi.db2.api.Lab01Data;
import de.hda.fbi.db2.api.Lab02EntityManager;
import de.hda.fbi.db2.api.Lab03Game;
import de.hda.fbi.db2.api.Lab04MassData;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
......@@ -7,10 +11,6 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import de.hda.fbi.db2.api.Lab01Data;
import de.hda.fbi.db2.api.Lab02EntityManager;
import de.hda.fbi.db2.api.Lab03Game;
import de.hda.fbi.db2.api.Lab04MassData;
/**
* Controller Created by l.koehler on 05.08.2019.
......@@ -19,6 +19,11 @@ public class Controller {
private static Controller controller;
/**
* Singleton Pattern.
*
* @return a singleton Pattern instance
*/
public static synchronized Controller getInstance() {
if (controller == null) {
controller = new Controller();
......@@ -46,6 +51,7 @@ public class Controller {
findImplementations();
}
@SuppressWarnings("deprecation")
private void findImplementations() {
try {
Enumeration<URL> elements = Thread.currentThread().getContextClassLoader()
......@@ -123,6 +129,9 @@ public class Controller {
return classes;
}
/**
* reads the csv data.
*/
public void readCsv() {
if (lab01Data == null) {
System.err.println("Could not find Lab01Data Implementation");
......@@ -156,6 +165,9 @@ public class Controller {
return lab04MassData;
}
/**
* starts the main menu.
*/
public void startMenu() {
if (lab01Data == null) {
System.err.println("Could not find Lab01Data Implementation");
......@@ -178,6 +190,9 @@ public class Controller {
menuController.showMenu();
}
/**
* persist data.
*/
public void persistData() {
if (lab01Data == null) {
System.err.println("Could not find Lab01Data Implementation");
......@@ -192,8 +207,7 @@ public class Controller {
String schemaGeneration = (String) lab02EntityManager.getEntityManager().getProperties()
.get("javax.persistence.schema-generation.database.action");
if (schemaGeneration.equals("drop-and-create") ||
schemaGeneration.equals("create")) {
if (schemaGeneration.equals("drop-and-create") || schemaGeneration.equals("create")) {
lab02EntityManager.persistData();
}
isPersisted = true;
......@@ -207,6 +221,9 @@ public class Controller {
return isPersisted;
}
/**
* creates massdata.
*/
public void createMassData() {
if (lab01Data == null) {
System.err.println("Could not find Lab01Data Implementation");
......
......@@ -16,17 +16,20 @@ import java.util.stream.Collectors;
* Created by a.hofmann on 03.10.2016.
*/
public class CsvDataReader {
private static final String SPLIT_CHARACTER = ";";
private static final Logger log = Logger.getLogger(CsvDataReader.class.getName());
private CsvDataReader() {}
private CsvDataReader() {
}
/**
* Lists all available csv files in the resource folder.
* <strong>WARNING:</strong> May won't work on your machine
*
* @return list of csv filenames
* @throws IOException
* @throws URISyntaxException
* @throws IOException ioException
* @throws URISyntaxException uriSyntaxException
*/
public static List<String> getAvailableFiles() throws IOException, URISyntaxException {
final Enumeration<URL> en = CsvDataReader.class.getClassLoader().getResources("");
......@@ -52,11 +55,12 @@ public class CsvDataReader {
/**
* Reads the given embedded file and returns its content in an accessible form.
*
* @param otherFile filename of csv file in resource folder
* @return content of the related file as a list of split strings including
* the CSV-header at first position.
* @throws URISyntaxException
* @throws IOException
* @return content of the related file as a list of split strings including the CSV-header at
* first position.
* @throws URISyntaxException uRISyntaxException
* @throws IOException iOException
*/
public static List<String[]> read(String otherFile) throws IOException, URISyntaxException {
try {
......@@ -77,12 +81,13 @@ public class CsvDataReader {
}
/**
* Reads the embedded <code>Wissenstest_sample200.csv</code> file and
* returns its content in an accessible form.
* @return content of the related file as a list of split strings including
* the CSV-header at first position.
* @throws URISyntaxException
* @throws IOException
* Reads the embedded <code>Wissenstest_sample200.csv</code> file and returns its content in an
* accessible form.
*
* @return content of the related file as a list of split strings including the CSV-header at
* first position.
* @throws URISyntaxException uRISyntaxException
* @throws IOException iOException
*/
public static List<String[]> read() throws URISyntaxException, IOException {
final URL resource = CsvDataReader.class.getResource("/Wissenstest_sample200.csv");
......
package de.hda.fbi.db2.controller;
import de.hda.fbi.db2.api.Lab03Game;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import de.hda.fbi.db2.api.Lab03Game;
import java.nio.charset.StandardCharsets;
/**
* MenuController
* Created by l.koehler on 05.08.2019.
* MenuController Created by l.koehler on 05.08.2019.
*/
public class MenuController {
......@@ -17,6 +16,9 @@ public class MenuController {
this.controller = controller;
}
/**
* shows the menu.
*/
public void showMenu() {
do {
System.out.println("Choose your Destiny?");
......
......@@ -2,12 +2,12 @@ package de.hda.fbi.db2.test;
import static org.junit.Assert.assertEquals;
import de.hda.fbi.db2.controller.Controller;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import de.hda.fbi.db2.controller.Controller;
/**
* Created by l.koehler on 05.08.2019.
......@@ -17,6 +17,9 @@ public class Lab01Test {
private static Controller controller;
/**
* Lab01Test init.
*/
@BeforeClass
public static void init() {
controller = Controller.getInstance();
......
......@@ -52,6 +52,9 @@ public class Lab02Test {
Lab02Test.answerEntity = answerEntity;
}
/**
* Lab02Test init.
*/
@BeforeClass
public static void init() {
controller = Controller.getInstance();
......@@ -181,7 +184,7 @@ public class Lab02Test {
return;
}
} catch (Exception ignored) {
//This is expected
}
}
......@@ -315,6 +318,7 @@ public class Lab02Test {
}
}
} catch (Exception ignored) {
//This is expected
}
}
Assert.fail("Could not find name in category");
......
package de.hda.fbi.db2.test;
import de.hda.fbi.db2.api.Lab01Data;
import de.hda.fbi.db2.api.Lab03Game;
import de.hda.fbi.db2.controller.Controller;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.metamodel.Attribute;
......@@ -14,9 +17,6 @@ import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import de.hda.fbi.db2.api.Lab01Data;
import de.hda.fbi.db2.api.Lab03Game;
import de.hda.fbi.db2.controller.Controller;
/**
* Created by l.koehler on 05.08.2019.
......@@ -34,6 +34,9 @@ public class Lab03Test {
Lab03Test.gameEntity = gameEntity;
}
/**
* Lab03Test init.
*/
@BeforeClass
public static void init() {
controller = Controller.getInstance();
......@@ -164,8 +167,8 @@ public class Lab03Test {
}
for (EmbeddableType embeddable : metaData.getEmbeddables()) {
if (embeddable.getJavaType().getSimpleName().toLowerCase().equals("answer") ||
embeddable.getJavaType().getSimpleName().toLowerCase().equals("answers")) {
if (embeddable.getJavaType().getSimpleName().toLowerCase().equals("answer")
|| embeddable.getJavaType().getSimpleName().toLowerCase().equals("answers")) {
answerEntity = embeddable;
}
}
......@@ -185,6 +188,7 @@ public class Lab03Test {
correct = true;
}
} catch (Exception ignored) {
//This is expected
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment