Package dev.zemco.codegame.evaluation
Class TimeoutSolutionEvaluatorDecorator
java.lang.Object
dev.zemco.codegame.evaluation.TimeoutSolutionEvaluatorDecorator
- All Implemented Interfaces:
ISolutionEvaluator
Enforces maximum step count for a given evaluation.
If maximum number of steps is surpassed, the evaluation is considered finished unsuccessfully
and
TimeoutException is thrown.- Author:
- Erik Zemčík
-
Constructor Summary
ConstructorsConstructorDescriptionTimeoutSolutionEvaluatorDecorator(ISolutionEvaluator wrappedEvaluator, int maxStepCount) Creates an instance ofTimeoutSolutionEvaluatorDecoratorwhich wraps an existingevaluator. -
Method Summary
Modifier and TypeMethodDescriptionReturns theexecution contextthat is being evaluated by the evaluator.booleanChecks if the evaluator has finished its evaluation.booleanChecks if the evaluation of theexecution contextis successful.voidstep()Steps the decorated evaluator if the maximum allowed number of steps was not reached.
-
Constructor Details
-
TimeoutSolutionEvaluatorDecorator
Creates an instance ofTimeoutSolutionEvaluatorDecoratorwhich wraps an existingevaluator.- Parameters:
wrappedEvaluator- evaluator to decoratemaxStepCount- maximum allowed number of steps to be enforced- Throws:
IllegalArgumentException- ifwrappedEvaluatorisnullor ifmaxStepCountis a negative integer
-
-
Method Details
-
hasFinished
public boolean hasFinished()Description copied from interface:ISolutionEvaluatorChecks if the evaluator has finished its evaluation.- Specified by:
hasFinishedin interfaceISolutionEvaluator- Returns:
- true if evaluator has finished, else false
-
isSuccessful
public boolean isSuccessful()Description copied from interface:ISolutionEvaluatorChecks if the evaluation of theexecution contextis successful. Result of this method should only be considered if the evaluatorhas finishedits evaluation.- Specified by:
isSuccessfulin interfaceISolutionEvaluator- Returns:
- true if the evaluation has ended and is successful, else false
-
getExecutionContext
Description copied from interface:ISolutionEvaluatorReturns theexecution contextthat is being evaluated by the evaluator.- Specified by:
getExecutionContextin interfaceISolutionEvaluator- Returns:
- evaluated execution context
-
step
public void step()Steps the decorated evaluator if the maximum allowed number of steps was not reached. If the maximum number of steps was reached, the evaluation is considered finished as a failure and theTimeoutExceptionis thrown with the details of the failure.- Specified by:
stepin interfaceISolutionEvaluator- Throws:
TimeoutException- if maximum allowed number of steps was reachedStepEvaluationException- if underlying execution threw an exception during the stepIllegalStateException- if step was attempted when evaluation has already finished- See Also:
-