Skip to content

Commit

Permalink
refactor: Add utility failed solution method
Browse files Browse the repository at this point in the history
  • Loading branch information
Elscrux committed Dec 29, 2024
1 parent 96b6962 commit c983324
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
9 changes: 9 additions & 0 deletions src/main/java/edu/kit/provideq/toolbox/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public <InputT> Solution(ProblemSolver<InputT, S> problemSolver) {
this.solverName = problemSolver.getName();
}

public static <InputT, S> Solution<S> failed(
ProblemSolver<InputT, S> problemSolver,
String text) {
var solution = new Solution<S>(problemSolver);
solution.fail();
solution.setDebugData(text);
return solution;
}

public UUID getId() {
return this.id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ public Mono<Solution<String>> solve(

// Return if no token is provided
if (planQkToken.isEmpty()) {
var solution = new Solution<>(this);
solution.setDebugData("No PlanQK token provided.");
solution.abort();
return Mono.just(solution);
return Mono.just(Solution.failed(this, "No PlanQK token provided."));
}

// Convert problem data string to buffered reader
Expand All @@ -74,10 +71,7 @@ public Mono<Solution<String>> solve(
try {
kipuQubo = parseKipuQubo(lpReader);
} catch (ConversionException e) {
var solution = new Solution<>(this);
solution.setDebugData(e.getMessage());
solution.abort();
return Mono.just(solution);
return Mono.just(Solution.failed(this, e.getMessage()));
}

var kipuQuboRequest = new KipuQuboRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ public Mono<Solution<String>> solve(

// Return if no token is provided
if (planQkToken.isEmpty()) {
var solution = new Solution<>(this);
solution.setDebugData("No PlanQK token provided.");
solution.abort();
return Mono.just(solution);
return Mono.just(Solution.failed(this, "No PlanQK token provided."));
}

// Convert problem data string to buffered reader
Expand All @@ -73,10 +70,7 @@ public Mono<Solution<String>> solve(
try {
quantagoniaQubo = parseQuantagoniaQubo(lpReader);
} catch (ConversionException e) {
var solution = new Solution<>(this);
solution.setDebugData(e.getMessage());
solution.abort();
return Mono.just(solution);
return Mono.just(Solution.failed(this, e.getMessage()));
}

PlanQkApi api = new PlanQkApi();
Expand Down

0 comments on commit c983324

Please sign in to comment.