array = getInitializing(); for (AppState state : array) { if (stateClass.isAssignableFrom(state.getClass())){
protected void initializePending(){ AppState[] array = getInitializing(); if (array.length == 0) return; synchronized( states ) { // Move the states that will be initialized // into the active array. In all but one case the // order doesn't matter but if we do this here then // a state can detach itself in initialize(). If we // did it after then it couldn't. List<AppState> transfer = Arrays.asList(array); states.addAll(transfer); initializing.removeAll(transfer); } for (AppState state : array) { state.initialize(this, app); } }
/** * Returns the first state that is an instance of subclass of the specified class. * @param <T> * @param stateClass * @return First attached state that is an instance of stateClass */ public <T extends AppState> T getState(Class<T> stateClass){ synchronized (states){ AppState[] array = getStates(); for (AppState state : array) { if (stateClass.isAssignableFrom(state.getClass())){ return (T) state; } } // This may be more trouble than its worth but I think // it's necessary for proper decoupling of states and provides // similar behavior to before where a state could be looked // up even if it wasn't initialized. -pspeed array = getInitializing(); for (AppState state : array) { if (stateClass.isAssignableFrom(state.getClass())){ return (T) state; } } } return null; }
/** * Returns the first state that is an instance of subclass of the specified class. * @param <T> * @param stateClass * @return First attached state that is an instance of stateClass */ public <T extends AppState> T getState(Class<T> stateClass){ synchronized (states){ AppState[] array = getStates(); for (AppState state : array) { if (stateClass.isAssignableFrom(state.getClass())){ return (T) state; } } // This may be more trouble than its worth but I think // it's necessary for proper decoupling of states and provides // similar behavior to before where a state could be looked // up even if it wasn't initialized. -pspeed array = getInitializing(); for (AppState state : array) { if (stateClass.isAssignableFrom(state.getClass())){ return (T) state; } } } return null; }
protected void initializePending(){ AppState[] array = getInitializing(); if (array.length == 0) return; synchronized( states ) { // Move the states that will be initialized // into the active array. In all but one case the // order doesn't matter but if we do this here then // a state can detach itself in initialize(). If we // did it after then it couldn't. List<AppState> transfer = Arrays.asList(array); states.addAll(transfer); initializing.removeAll(transfer); } for (AppState state : array) { state.initialize(this, app); } }
protected void initializePending(){ AppState[] array = getInitializing(); synchronized( states ) { // Move the states that will be initialized // into the active array. In all but one case the // order doesn't matter but if we do this here then // a state can detach itself in initialize(). If we // did it after then it couldn't. List<AppState> transfer = Arrays.asList(array); states.addAll(transfer); initializing.removeAll(transfer); } for (AppState state : array) { state.initialize(this, app); } }