Interface NeighborhoodTestContext<Solution_>
- Type Parameters:
Solution_- the planning solution type
MoveProvider
using a bound planning solution instance.
Created via NeighborhoodTester.using(Object), this context binds a specific solution
instance to the evaluator and exposes extraction methods.
Once any particular move was retrieved using methods such as getMovesAsStream(),
it can optionally be executed using the MoveTestContext obtained via getMoveTestContext().
It is recommended to only execute moves temporarily,
as that will have no lasting impact on the iterator or the bound solution instance.
This class is NOT thread-safe.
This package and all of its contents are part of the Neighborhoods API, which is under development and is only offered as a preview feature. There are no guarantees for backward compatibility; any method or field may change or be removed without prior notice, although we will strive to avoid this as much as possible.
-
Method Summary
Modifier and TypeMethodDescriptionReturns an iterator over all moves provided by the givenMoveProviderfor the bound solution instance.getMovesAsIterator(Function<Move<Solution_>, Move_> moveCaster) As defined bygetMovesAsIterator(), but the provided function allows casting each move to a more specific subtype, avoiding the need for external casting in the test.As defined bygetMovesAsIterator(), but returns a list of all the moves in the iterator.getMovesAsList(Function<Move<Solution_>, Move_> moveCaster) As defined bygetMovesAsList(), but the provided function allows casting each move to a more specific subtype, avoiding the need for external casting in the test.As defined bygetMovesAsIterator(), but returns aStreamof all the moves in the iterator.getMovesAsStream(Function<Move<Solution_>, Move_> moveCaster) As defined bygetMovesAsStream(), but the provided function allows casting each move to a more specific subtype, avoiding the need for external casting in the test.May be used to execute moves retrieved from this context on the bound solution instance.
-
Method Details
-
getMovesAsIterator
Returns an iterator over all moves provided by the givenMoveProviderfor the bound solution instance. The order of moves is not defined and is driven by the underlyingMoveProvider, but it is guaranteed to be deterministic and reproducible across multiple invocations.- Returns:
- an iterator over all moves
-
getMovesAsStream
As defined bygetMovesAsIterator(), but returns aStreamof all the moves in the iterator. Parallel streams are not supported and the behavior of such stream is undefined.- Returns:
- a stream of all moves
-
getMovesAsList
As defined bygetMovesAsIterator(), but returns a list of all the moves in the iterator. In case of a large expected number of moves, consider usinggetMovesAsIterator()instead to prevent excessive memory use. -
getMovesAsIterator
<Move_ extends Move<Solution_>> Iterator<Move_> getMovesAsIterator(Function<Move<Solution_>, Move_> moveCaster) As defined bygetMovesAsIterator(), but the provided function allows casting each move to a more specific subtype, avoiding the need for external casting in the test. Only applicable if the underlyingMoveProvideronly provides moves of one particular subtype.- Type Parameters:
Move_- expected move subtype- Parameters:
moveCaster- function to cast each move to the expected subtype- Returns:
- an iterator over all moves
-
getMovesAsStream
default <Move_ extends Move<Solution_>> Stream<Move_> getMovesAsStream(Function<Move<Solution_>, Move_> moveCaster) As defined bygetMovesAsStream(), but the provided function allows casting each move to a more specific subtype, avoiding the need for external casting in the test. Only applicable if the underlyingMoveProvideronly provides moves of one particular subtype.- Type Parameters:
Move_- expected move subtype- Parameters:
moveCaster- function to cast each move to the expected subtype- Returns:
- a stream of all moves
-
getMovesAsList
default <Move_ extends Move<Solution_>> List<Move_> getMovesAsList(Function<Move<Solution_>, Move_> moveCaster) As defined bygetMovesAsList(), but the provided function allows casting each move to a more specific subtype, avoiding the need for external casting in the test. Only applicable if the underlyingMoveProvideronly provides moves of one particular subtype.- Type Parameters:
Move_- expected move subtype- Parameters:
moveCaster- function to cast each move to the expected subtype- Returns:
- a list of all moves
-
getMoveTestContext
MoveTestContext<Solution_> getMoveTestContext()May be used to execute moves retrieved from this context on the bound solution instance. When executing movespermanently, any non-exhausted iterators obtained from this context become invalid and their further behavior is undefined; new moves should be obtained instead, for example by callinggetMovesAsStream(). Temporary execution viaMoveTestContext.executeTemporarily(Move, Consumer)does not have this limitation. Java streams and lists obtained from this context are not affected by permanent execution of moves either. Move lists are based on the solution as it was at the time when they were obtained. Streams of moves only materialize when their terminal operation is invoked, and they reflect the latest state of the solution at that time.- Returns:
- the move run context for executing moves on the bound solution instance
-