| State.java |
1 /*
2 * State.java
3 *
4 * Copyright (c) 1998-2005, The University of Sheffield.
5 *
6 * This file is part of GATE (see http://gate.ac.uk/), and is free
7 * software, licenced under the GNU Library General Public License,
8 * Version 2, June1991.
9 *
10 * A copy of this licence is included in the distribution in the file
11 * licence.html, and is also available at http://gate.ac.uk/gate/licence.html.
12 *
13 * Valentin Tablan, October 2000
14 *
15 * $Id: State.java,v 1.5 2005/01/11 13:51:38 ian Exp $
16 */
17 package guk.im;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 /**
23 * A state of the {@link LocaleHandler} FSM.
24 *
25 */
26 public class State{
27
28 /**
29 * Creates a new state
30 *
31 * @param isFinal
32 */
33 public State(boolean isFinal ){
34 this.finalState = isFinal;
35 }
36
37 /**
38 * Default constructor; creates a non final state
39 *
40 */
41 public State(){
42 this.finalState = false;
43 }
44
45 /**
46 * Adds anew action to this state.
47 *
48 * @param key
49 * @param action
50 */
51 public Action addAction(Key key, Action action){
52 return (Action)transitionFunction.put(key, action);
53 }
54
55 /**
56 * Gets the action this state will activate for a given {@link Key}
57 *
58 * @param key
59 */
60 public Action getNext(Key key){
61 return (Action)transitionFunction.get(key);
62 }
63
64 /**
65 * Is this state final?
66 *
67 */
68 public boolean isFinal(){
69 return finalState;
70 }
71
72 /**
73 * Has this state any actions?
74 *
75 */
76 public boolean hasNext(){
77 return !transitionFunction.isEmpty();
78 }
79
80 /**
81 * Sets the final attribute.
82 *
83 * @param pFinal
84 */
85 public void setFinal(boolean pFinal){
86 finalState = pFinal;
87 }
88 //maps from Key to Action
89 /**
90 * The transition function for this state.
91 *
92 */
93 Map transitionFunction = new HashMap();
94
95 /**
96 * Is this state final?
97 *
98 */
99 boolean finalState;
100 }//class State
101