Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.safehaus.chop.api;
  
  
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Set;
  
 
The runner States and its possible state transitions: hence its state machine.
 
 public enum State {
     // inactive ==> (load signal) ==> ready
     INACTIVE( 3, new Signal[] { . }, new Integer[] { 0 } ),
 
     // stopped ==> (reset signal) ==> ready
     STOPPED( 2, new Signal[] { . }, new Integer[] { 0 } ),
 
     // running ==> (stop signal) ==> stopped
     // running ==> (completed signal) ==> ready
     RUNNING( 1, new Signal[] { .. }, new Integer[] { 2, 0 } ),
 
     // ready ==> (load signal) ==> ready
     // ready ==> (start signal) ==> running
     READY( 0, new Signal[] { .. }, new Integer[] { 0, 1 } );
 
     private static final Logger LOG = LoggerFactory.getLoggerState.class );
 
     private final int id;
     private final Map<SignalIntegertrantab;
     private final Set<Signalaccepts;
 
 
     private Stateint idSignal[] signalsInteger[] states ) {
         this. = id;
          = getTrantabsignalsstates );
          = new HashSet<Signal>( signals.length );
         Collections.addAllsignals );
     }
 
 
     public int getId() {
         return ;
     }


    
Check to see if the state accepts a signal: meaning is the signal a valid signal to produce a state transition.

Parameters:
signal the signal to check
Returns:
true if the signal will be accepted, false otherwise
 
     public boolean acceptsSignal signal ) {
         Preconditions.checkNotNullsignal"Signal parameter cannot be null: state = {}"toString() );
         return .containssignal );
     }


    
Check to see if the state accepts a signal: in other words is the signal a valid signal to produce a state transition and does that transition lead to the supplied 'next' state parameter.

Parameters:
signal the signal to check
next the next state to transit to
Returns:
true if the signal will be accepted and the next state will be the supplied state, false otherwise
 
     public boolean acceptsSignal signalState next ) {
         if ( signal == null || next == null ) {
             return false;
         }
 
         if ( ! .containssignal ) ) {
             return false;
         }
 
         Integer id = .getsignal );
         if ( id == null ) {
             return false;
         }
 
         State realNext = getid );
 
         if ( realNext == null ) {
             return false;
         }
 
         return realNext.equalsnext );
     }
 
 
     public State getInteger id ) {
        Preconditions.checkNotNullid"The id cannot be null: state = {}"toString() );
        switch ( id ) {
            case 0:
                return ;
            case 1:
                return ;
            case 2:
                return ;
            case 3:
                return ;
        }
        throw new RuntimeException"Should never get here!" );
    }
    public State nextSignal signal ) {
        Preconditions.checkNotNullsignal"The signal cannot be null: state = {}"toString() );
        Integer id = .getsignal );
        .info"Got signal {} in {} state: id = " + idsignaltoString() );
        return getid );
    }
    private static Map<SignalIntegergetTrantabSignal[] signalsInteger[] states ) {
        Map<SignalIntegertrantab = new HashMap<SignalInteger>( signals.length );
        for ( int ii = 0; ii < signals.lengthii++ ) {
            trantab.putsignals[ii], states[ii] );
        }
        return Collections.unmodifiableMaptrantab );
    }
New to GrepCode? Check out our FAQ X