Class TwoPhaseActionSelector<T,U>
java.lang.Object
jfxutils.TwoPhaseActionSelector<T,U>
- Type Parameters:
T
- the type representing the source position (from)U
- the type representing the action to apply
- Direct Known Subclasses:
JFXTwoPhaseActionSelector
Utility class to determine the next action in two-phase action selection
puzzles.
It manages the state transitions between selecting a source position and
selecting an action to apply at that position.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Represents the current phase of the action selection process. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TwoPhaseActionSelector.Phase
The current phase of the action selection process. -
Constructor Summary
ConstructorsConstructorDescriptionTwoPhaseActionSelector
(TwoPhaseActionState<T, U> state) Creates aTwoPhaseActionSelector
to manage the action selection process for the given state. -
Method Summary
Modifier and TypeMethodDescriptionfinal U
Returns the action selected.final T
getFrom()
Returns the source position selected.getPhase()
Returns the current selection phase.final boolean
Returns whether the last selection (i.e, for the source or the target respectively) was invalid.final boolean
Returns whether the move is ready to be made.final void
makeMove()
Makes the move selected.final void
reset()
Resets the selection state, clearing both the source position and action selections.void
selectAction
(U action) Selects an action to be performed at the previously selected source position.void
selectFrom
(T from) Selects a source position from which an action will be performed.protected void
Sets the current selection phase.
-
Field Details
-
phase
The current phase of the action selection process.
-
-
Constructor Details
-
TwoPhaseActionSelector
Creates aTwoPhaseActionSelector
to manage the action selection process for the given state.- Parameters:
state
- the state on which actions will be performed
-
-
Method Details
-
getPhase
Returns the current selection phase.- Returns:
- the current selection phase
-
setPhase
Sets the current selection phase. The method is provided to be overridden by subclasses.- Parameters:
phase
- the current selection phase
-
isReadyToMove
public final boolean isReadyToMove()Returns whether the move is ready to be made.- Returns:
true
if the selection is in the READY_TO_MOVE phase,false
otherwise.
-
selectFrom
Selects a source position from which an action will be performed. If the position is valid for making a move, the selection process advances to the action selection phase.- Parameters:
from
- the position to select as the source
-
selectAction
Selects an action to be performed at the previously selected source position. If the action is valid for the selected source, the selection process advances to the ready-to-move phase.- Parameters:
action
- the action to perform at the selected source
-
getFrom
Returns the source position selected.- Returns:
- the source position selected
- Throws:
IllegalStateException
- if the selection is still in the SELECT_FROM phase, meaning no source has been selected yet.
-
getAction
Returns the action selected.- Returns:
- the action selected
- Throws:
IllegalStateException
- if the selection is not in the READY_TO_MOVE phase.
-
isInvalidSelection
public final boolean isInvalidSelection()Returns whether the last selection (i.e, for the source or the target respectively) was invalid.- Returns:
true
if the last selection was invalid,false
otherwise.
-
makeMove
public final void makeMove()Makes the move selected. If the move is not yet ready to be made, then anIllegalStateException
is thrown. -
reset
public final void reset()Resets the selection state, clearing both the source position and action selections.
-