refactor: changed returnType of checkRequestAndApply to optional

This commit is contained in:
Yannik Bretschneider 2021-06-01 16:34:08 +02:00
parent 842db2439a
commit 141469c11f

View File

@ -8,6 +8,7 @@ import uulm.teamname.marvelous.gamelibrary.json.config.ScenarioConfig;
import uulm.teamname.marvelous.gamelibrary.requests.Request; import uulm.teamname.marvelous.gamelibrary.requests.Request;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Optional;
/** Represents a game instance. */ /** Represents a game instance. */
public class GameInstance { public class GameInstance {
@ -32,14 +33,14 @@ public class GameInstance {
* @param requests The requests to check * @param requests The requests to check
* @return The list of resulting {@link Event}s or `null` if the check failed * @return The list of resulting {@link Event}s or `null` if the check failed
*/ */
public ArrayList<Event> checkRequestsAndApply(Request... requests) { public Optional<ArrayList<Event>> checkRequestsAndApply(Request... requests) {
if(manager.processRequests(requests, true)) { if(manager.processRequests(requests, true)) {
ArrayList<Event> result = manager.apply(); ArrayList<Event> result = manager.apply();
result.addAll(manager.checkPostPhase()); result.addAll(manager.checkPostPhase());
return result; return Optional.of(result);
} }
return null; return Optional.empty();
} }
/** /**