Skip to content

Commit

Permalink
refactor: make SubProblems an internal class
Browse files Browse the repository at this point in the history
  • Loading branch information
schweikart committed Apr 3, 2024
1 parent 400a212 commit 6d8b6c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/main/java/edu/kit/provideq/toolbox/meta/Problem.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
/**
* A problem encapsulates an input for a given problem type.
* The problem can be solved using a matching ProblemSolver.
* The {@link Problem} class is essentially a state machine allowing different operations like
* configuring the input and solver, and starting or stopping the solution process.
*
* @param <InputT> the data type of the problem's input.
* @param <ResultT> the data type of the problem's solution.
Expand All @@ -38,6 +40,7 @@ public Problem(ProblemType<InputT, ResultT> type) {

this.observers = new HashSet<>();

// Sub-routine management and sub-routine-call handling are outsourced to the SubProblems class
Consumer<Problem<?, ?>> notifyAdded = addedSubProblem -> this.observers.forEach(
observer -> observer.onSubProblemAdded(this, addedSubProblem));
Consumer<Problem<?, ?>> notifyRemoved = removedSubProblem -> this.observers.forEach(
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/edu/kit/provideq/toolbox/meta/SubProblems.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@
import reactor.core.publisher.Mono;

/**
* This class manages the mapping from sub-routine calls to problems.
* This internal class manages sub-problems and sub-routine calls of a {@link Problem}.
*
* @apiNote This class is neither intended to be used by other classes than {@link Problem} nor to
* be extended or replaced.
* @implNote {@link SubProblems} is separate to {@link Problem} as it deals with another level of
* abstraction.
* {@link Problem} is essentially a state machine for the solution process of a problem and
* {@link SubProblems} deals with the type-safe wiring between sub-routines and sub-problems.
* Additionally, having {@link SubProblems} implement the {@link SubRoutineResolver} interface
* avoids interface pollution in the {@link Problem} class.
*/
public class SubProblems<InputT, ResultT>
final class SubProblems<InputT, ResultT>
implements SubRoutineResolver, ProblemObserver<InputT, ResultT> {

private static class SubProblemEntry<SubInputT, SubResultT> {
Expand Down

0 comments on commit 6d8b6c0

Please sign in to comment.