Skip to content

Commit

Permalink
don't change state if the requested key is already the active one
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Jan 7, 2025
1 parent 5d04d6e commit 20f4d12
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/org/ois/core/state/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public void changeState(String key, Object... params) {
if (key == null || !this.states.containsKey(key)) {
throw new IllegalArgumentException("Can't find state '" + key + "' in the registered states.");
}
if (key.equals(getCurrentStateKey())) {
// The current state is the key that requesting to change, no need to change
return;
}
nextState = key;
nextStateParams = params;
}
Expand Down Expand Up @@ -285,6 +289,18 @@ public IState getCurrentState() {
return this.states.get(this.stateStack.peek());
}

/**
* Returns the current active state key.
*
* @return the current state key, or null if no active state exists
*/
public String getCurrentStateKey() {
if (!hasActiveState()) {
return null;
}
return this.stateStack.peek();
}

/**
* Checks whether there is an active state in the state stack.
*
Expand Down

0 comments on commit 20f4d12

Please sign in to comment.