Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java @ 464:d4facc5e52e6 2.9.17
Added tag 2.9.16 for changeset 86be4d8e44d4
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 05 Apr 2013 17:15:07 +0200 |
parents | 708de1779232 |
children |
rev | line source |
---|---|
104
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.artifactdatabase.state; |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
347
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
3 import java.util.ArrayList; |
104
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import java.util.HashMap; |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import java.util.List; |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import java.util.Map; |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import org.apache.log4j.Logger; |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 |
374
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
10 import de.intevation.artifactdatabase.data.StateData; |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
11 |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
12 |
104
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 /** |
347
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
14 * The StateEngine stores all states and associated information about |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
15 * outputs and facets for each Artifact. |
104
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 * |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 */ |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 public class StateEngine { |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 /** The logger used in this class. */ |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 private static Logger logger = Logger.getLogger(StateEngine.class); |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 /** |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 * A map that contains the states of the artifacts. The key of this map is |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 * the name of an artifact, its value is a list of all states the artifact |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 * can reach. |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 */ |
272
2ce31a9414ff
Use generics more precisely
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
108
diff
changeset
|
29 protected Map<String, List<State>> states; |
104
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 /** |
108
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
33 * A map that contains all existing states. The key of this map is the ID of |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
34 * the state, its value is the state itself. |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
35 */ |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
36 protected Map<String, State> allStates; |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
37 |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
38 |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
39 /** |
104
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 * The default constructor. |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 */ |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 public StateEngine() { |
272
2ce31a9414ff
Use generics more precisely
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
108
diff
changeset
|
43 states = new HashMap<String, List<State>>(); |
108
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
44 allStates = new HashMap<String, State>(); |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
45 } |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
46 |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
47 |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
48 /** |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
49 * This method adds a state into the map <i>allStates</i>. |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
50 * |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
51 * @param state The state to add. |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
52 */ |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
53 protected void addState(State state) { |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
54 allStates.put(state.getID(), state); |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
55 } |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
56 |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
57 |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
58 /** |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
59 * Returns the state based on its ID. |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
60 * |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
61 * @param stateId The ID of the desired state. |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
62 * |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
63 * @return the state. |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
64 */ |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
65 public State getState(String stateId) { |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
66 return allStates.get(stateId); |
104
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 } |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 |
374
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
70 public StateData getStateData(String artifact, String dataName) { |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
71 List<State> artifactStates = getStates(artifact); |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
72 |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
73 if (artifactStates == null || artifactStates.size() == 0) { |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
74 logger.warn("No States for Artifact '" + artifact + "' existing."); |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
75 return null; |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
76 } |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
77 |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
78 for (State state: artifactStates) { |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
79 StateData sd = state.getData(dataName); |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
80 |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
81 if (sd != null) { |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
82 return sd; |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
83 } |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
84 } |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
85 |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
86 logger.warn( |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
87 "No StateData for Artifact '" + artifact + |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
88 "' with name '" + dataName + "' existing."); |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
89 |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
90 return null; |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
91 } |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
92 |
5420b96dd0b3
Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
347
diff
changeset
|
93 |
104
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 /** |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 * Add new states for a specific artifact. |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 * |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 * @param artifact The name of the artifact. |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 * @param states A list of states that the artifact can reach. |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 * |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 * @return true, if the states were added, otherwise false. |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 */ |
108
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
102 public boolean addStates(String artifact, List<State> states) { |
104
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 List tmp = this.states.get(artifact); |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 if (tmp != null) { |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 logger.info( |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 "States for the artifact '" + artifact + "' already stored."); |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
109 return false; |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
110 } |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
111 |
108
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
112 // add the state to the map with all existing states |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
113 for (State s: states) { |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
114 addState(s); |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
115 } |
9ece61d918b1
Improved the StateEngine and the TransitionEngine to retrieve the reachable states of a current state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
106
diff
changeset
|
116 |
104
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
117 logger.debug("Add new states for the artifact '" + artifact + "'"); |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
118 return this.states.put(artifact, states) != null; |
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
119 } |
106
ece0fdb07975
Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
104
diff
changeset
|
120 |
ece0fdb07975
Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
104
diff
changeset
|
121 |
ece0fdb07975
Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
104
diff
changeset
|
122 /** |
ece0fdb07975
Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
104
diff
changeset
|
123 * Returns the state list of an artifact specified by its name. |
ece0fdb07975
Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
104
diff
changeset
|
124 * |
347
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
125 * @param artifact The name of the artifact (e.g. "winfo"). |
106
ece0fdb07975
Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
104
diff
changeset
|
126 * |
ece0fdb07975
Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
104
diff
changeset
|
127 * @return the list of states of this artifact or <i>null</i> if no states |
ece0fdb07975
Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
104
diff
changeset
|
128 * are existing for this <i>artifact</i>. |
ece0fdb07975
Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
104
diff
changeset
|
129 */ |
ece0fdb07975
Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
104
diff
changeset
|
130 public List<State> getStates(String artifact) { |
ece0fdb07975
Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
104
diff
changeset
|
131 return states.get(artifact); |
ece0fdb07975
Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
104
diff
changeset
|
132 } |
347
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
133 |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
134 |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
135 /** |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
136 * Return mapping of output to facets for an artifact in its states. |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
137 */ |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
138 public Map<String, List<String>> getCompatibleFacets(List<String> aStates) { |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
139 Map<String, List<String>> compatibilityMatrix = |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
140 new HashMap<String, List<String>>(); |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
141 |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
142 // For all states that the artifact had seen, add outputs facets. |
449
708de1779232
Add debug output for StateEngine
Björn Ricks <bjoern.ricks@intevation.de>
parents:
374
diff
changeset
|
143 logger.debug("Searching in " + aStates); |
347
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
144 for (String stateId: aStates) { |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
145 |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
146 State state = allStates.get(stateId); |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
147 if (state == null) { |
449
708de1779232
Add debug output for StateEngine
Björn Ricks <bjoern.ricks@intevation.de>
parents:
374
diff
changeset
|
148 logger.debug("No state found for id " + stateId); |
347
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
149 continue; |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
150 } |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
151 |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
152 for (Output output: state.getOutputs()) { |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
153 List<Facet> outFacets = output.getFacets(); |
449
708de1779232
Add debug output for StateEngine
Björn Ricks <bjoern.ricks@intevation.de>
parents:
374
diff
changeset
|
154 logger.debug("Facets for output " + output.getName() + " :" + outFacets); |
347
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
155 |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
156 List<String> oldFacets = compatibilityMatrix.get(output.getName()); |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
157 |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
158 if (oldFacets == null) { |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
159 oldFacets = new ArrayList<String>(); |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
160 } |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
161 |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
162 for (Facet facet: outFacets) { |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
163 oldFacets.add(facet.getName()); |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
164 } |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
165 |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
166 compatibilityMatrix.put(output.getName(), oldFacets); |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
167 } |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
168 } |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
169 return compatibilityMatrix; |
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
170 } |
104
26bfff409dd3
Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
171 } |
347
16ab243507e0
Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
272
diff
changeset
|
172 // vim:set ts=4 sw=4 et sta sts=4 fenc=utf8 : |