From a61813ebd86e01f168efc09a51d1db0a0f4c8cc9 Mon Sep 17 00:00:00 2001 From: Ali-RS Date: Mon, 3 Dec 2018 12:47:01 +0330 Subject: [PATCH] Added AppStateManager.getState(class, failOnMiss) that can optionally throw an exception if the state does not exist. --- .../java/com/jme3/app/state/AppStateManager.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/jme3-core/src/main/java/com/jme3/app/state/AppStateManager.java b/jme3-core/src/main/java/com/jme3/app/state/AppStateManager.java index 177fcb22f..df7eeb4b2 100644 --- a/jme3-core/src/main/java/com/jme3/app/state/AppStateManager.java +++ b/jme3-core/src/main/java/com/jme3/app/state/AppStateManager.java @@ -210,6 +210,18 @@ public class AppStateManager { * @return First attached state that is an instance of stateClass */ public T getState(Class stateClass){ + return getState(stateClass, false); + } + + /** + * Returns the first state that is an instance of subclass of the specified class. + * @param + * @param stateClass + * @param failOnMiss + * @return First attached state that is an instance of stateClass. If failOnMiss is true + * then an IllegalArgumentException is thrown if the state is not attached. + */ + public T getState(Class stateClass, boolean failOnMiss){ synchronized (states){ AppState[] array = getStates(); for (AppState state : array) { @@ -229,6 +241,10 @@ public class AppStateManager { } } } + + if(failOnMiss) { + throw new IllegalArgumentException("State not found for:" + stateClass); + } return null; }