diff --git a/src/main/java/org/ois/core/state/StateManager.java b/src/main/java/org/ois/core/state/StateManager.java index 5055696..f838259 100644 --- a/src/main/java/org/ois/core/state/StateManager.java +++ b/src/main/java/org/ois/core/state/StateManager.java @@ -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; } @@ -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. *