State.java
001 /*
002  * State.java
003  *
004  * Copyright (c) 1998-2005, The University of Sheffield.
005  *
006  * This file is part of GATE (see http://gate.ac.uk/), and is free
007  * software, licenced under the GNU Library General Public License,
008  * Version 2, June1991.
009  *
010  * A copy of this licence is included in the distribution in the file
011  * licence.html, and is also available at http://gate.ac.uk/gate/licence.html.
012  *
013  * Valentin Tablan, October 2000
014  *
015  * $Id: State.java 6491 2005-01-11 13:51:38Z ian $
016  */
017 package guk.im;
018 
019 import java.util.HashMap;
020 import java.util.Map;
021 
022 /**
023  * A state of the {@link LocaleHandler} FSM.
024  *
025  */
026 public class State{
027 
028   /**
029    * Creates a new state
030    *
031    @param isFinal
032    */
033   public State(boolean isFinal ){
034     this.finalState = isFinal;
035   }
036 
037   /**
038    * Default constructor; creates a non final state
039    *
040    */
041   public State(){
042     this.finalState = false;
043   }
044 
045   /**
046    * Adds anew action to this state.
047    *
048    @param key
049    @param action
050    */
051   public Action addAction(Key key, Action action){
052     return (Action)transitionFunction.put(key, action);
053   }
054 
055   /**
056    * Gets the action this state will activate for a given {@link Key}
057    *
058    @param key
059    */
060   public Action getNext(Key key){
061     return (Action)transitionFunction.get(key);
062   }
063 
064   /**
065    * Is this state final?
066    *
067    */
068   public boolean isFinal(){
069     return finalState;
070   }
071 
072   /**
073    * Has this state any actions?
074    *
075    */
076   public boolean hasNext(){
077     return !transitionFunction.isEmpty();
078   }
079 
080   /**
081    * Sets the final attribute.
082    *
083    @param pFinal
084    */
085   public void setFinal(boolean pFinal){
086     finalState = pFinal;
087   }
088   //maps from Key to Action
089   /**
090    * The transition function for this state.
091    *
092    */
093   Map transitionFunction = new HashMap();
094 
095   /**
096    * Is this state final?
097    *
098    */
099   boolean finalState;
100 }//class State