Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java @ 108:9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
artifacts/trunk@1297 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 07 Feb 2011 11:20:31 +0000 |
parents | ece0fdb07975 |
children | 2ce31a9414ff |
comparison
equal
deleted
inserted
replaced
107:39d9391059bd | 108:9ece61d918b1 |
---|---|
23 */ | 23 */ |
24 protected Map<String, List> states; | 24 protected Map<String, List> states; |
25 | 25 |
26 | 26 |
27 /** | 27 /** |
28 * A map that contains all existing states. The key of this map is the ID of | |
29 * the state, its value is the state itself. | |
30 */ | |
31 protected Map<String, State> allStates; | |
32 | |
33 | |
34 /** | |
28 * The default constructor. | 35 * The default constructor. |
29 */ | 36 */ |
30 public StateEngine() { | 37 public StateEngine() { |
31 states = new HashMap<String, List>(); | 38 states = new HashMap<String, List>(); |
39 allStates = new HashMap<String, State>(); | |
40 } | |
41 | |
42 | |
43 /** | |
44 * This method adds a state into the map <i>allStates</i>. | |
45 * | |
46 * @param state The state to add. | |
47 */ | |
48 protected void addState(State state) { | |
49 allStates.put(state.getID(), state); | |
50 } | |
51 | |
52 | |
53 /** | |
54 * Returns the state based on its ID. | |
55 * | |
56 * @param stateId The ID of the desired state. | |
57 * | |
58 * @return the state. | |
59 */ | |
60 public State getState(String stateId) { | |
61 return allStates.get(stateId); | |
32 } | 62 } |
33 | 63 |
34 | 64 |
35 /** | 65 /** |
36 * Add new states for a specific artifact. | 66 * Add new states for a specific artifact. |
38 * @param artifact The name of the artifact. | 68 * @param artifact The name of the artifact. |
39 * @param states A list of states that the artifact can reach. | 69 * @param states A list of states that the artifact can reach. |
40 * | 70 * |
41 * @return true, if the states were added, otherwise false. | 71 * @return true, if the states were added, otherwise false. |
42 */ | 72 */ |
43 public boolean addStates(String artifact, List states) { | 73 public boolean addStates(String artifact, List<State> states) { |
44 List tmp = this.states.get(artifact); | 74 List tmp = this.states.get(artifact); |
45 | 75 |
46 if (tmp != null) { | 76 if (tmp != null) { |
47 logger.info( | 77 logger.info( |
48 "States for the artifact '" + artifact + "' already stored."); | 78 "States for the artifact '" + artifact + "' already stored."); |
49 | 79 |
50 return false; | 80 return false; |
81 } | |
82 | |
83 // add the state to the map with all existing states | |
84 for (State s: states) { | |
85 addState(s); | |
51 } | 86 } |
52 | 87 |
53 logger.debug("Add new states for the artifact '" + artifact + "'"); | 88 logger.debug("Add new states for the artifact '" + artifact + "'"); |
54 return this.states.put(artifact, states) != null; | 89 return this.states.put(artifact, states) != null; |
55 } | 90 } |