Merge pull request #965 from Ali-RS/Ali-RS-patch-1

Added AppStateManager.getState(class, failOnMiss)
accellbaker
Paul Speed 6 years ago committed by GitHub
commit f44fdb35e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      jme3-core/src/main/java/com/jme3/app/state/AppStateManager.java
  2. 6
      jme3-core/src/main/java/com/jme3/app/state/BaseAppState.java

@ -210,6 +210,18 @@ public class AppStateManager {
* @return First attached state that is an instance of stateClass
*/
public <T extends AppState> T getState(Class<T> stateClass){
return getState(stateClass, false);
}
/**
* Returns the first state that is an instance of subclass of the specified class.
* @param <T>
* @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 extends AppState> T getState(Class<T> 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;
}

@ -142,7 +142,11 @@ public abstract class BaseAppState implements AppState {
}
public final <T extends AppState> T getState( Class<T> type ) {
return getStateManager().getState(type);
return getState( type, false );
}
public final <T extends AppState> T getState( Class<T> type, boolean failOnMiss ) {
return getStateManager().getState( type, failOnMiss );
}
@Override

Loading…
Cancel
Save