annotate artifact-database/src/main/java/org/dive4elements/artifactdatabase/state/StateEngine.java @ 570:584591f8203c 3.2.x

Upgrade to Log4j 2
author Tom Gottfried <tom@intevation.de>
date Mon, 28 Feb 2022 17:41:14 +0100
parents 415df0fc4fa1
children
rev   line source
475
415df0fc4fa1 Fixed maven group ids
Sascha L. Teichmann <teichmann@intevation.de>
parents: 473
diff changeset
1 package org.dive4elements.artifactdatabase.state;
104
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
570
584591f8203c Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 475
diff changeset
8 import org.apache.logging.log4j.Logger;
584591f8203c Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 475
diff changeset
9 import org.apache.logging.log4j.LogManager;
104
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
475
415df0fc4fa1 Fixed maven group ids
Sascha L. Teichmann <teichmann@intevation.de>
parents: 473
diff changeset
11 import org.dive4elements.artifactdatabase.data.StateData;
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
12
5420b96dd0b3 Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 347
diff changeset
13
104
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 /**
347
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
15 * 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
16 * 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
17 *
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 * @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
19 */
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 public class StateEngine {
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 /** The logger used in this class. */
570
584591f8203c Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 475
diff changeset
23 private static Logger logger = LogManager.getLogger(StateEngine.class);
104
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 /**
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 * 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
27 * 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
28 * can reach.
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 */
272
2ce31a9414ff Use generics more precisely
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 108
diff changeset
30 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
31
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 /**
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
34 * 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
35 * 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
36 */
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 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
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
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
40 /**
104
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 * The default constructor.
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 */
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 public StateEngine() {
272
2ce31a9414ff Use generics more precisely
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 108
diff changeset
44 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
45 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
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 /**
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 * 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
51 *
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 * @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
53 */
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 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
55 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
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 /**
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 * 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
61 *
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 * @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
63 *
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 * @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
65 */
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 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
67 return allStates.get(stateId);
104
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
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70
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
71 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
72 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
73
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 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
75 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
76 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
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
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 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
80 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
81
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 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
83 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
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
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 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
88 "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
89 "' 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
90
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 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
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
5420b96dd0b3 Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 347
diff changeset
94
104
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 /**
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 * 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
97 *
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 * @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
99 * @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
100 *
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 * @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
102 */
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
103 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
104 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
105
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 if (tmp != null) {
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 logger.info(
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 "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
109
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 return false;
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 }
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112
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
113 // 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
114 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
115 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
116 }
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
117
104
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 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
119 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
120 }
106
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 /**
ece0fdb07975 Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 104
diff changeset
124 * 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
125 *
347
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
126 * @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
127 *
ece0fdb07975 Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 104
diff changeset
128 * @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
129 * are existing for this <i>artifact</i>.
ece0fdb07975 Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 104
diff changeset
130 */
ece0fdb07975 Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 104
diff changeset
131 public List<State> getStates(String artifact) {
ece0fdb07975 Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 104
diff changeset
132 return states.get(artifact);
ece0fdb07975 Implementations to initialize and retrieve states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 104
diff changeset
133 }
347
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 /**
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
137 * 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
138 */
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
139 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
140 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
141 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
142
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
143 // 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
144 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
145 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
146
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
147 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
148 if (state == null) {
449
708de1779232 Add debug output for StateEngine
Björn Ricks <bjoern.ricks@intevation.de>
parents: 374
diff changeset
149 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
150 continue;
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
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
153 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
154 List<Facet> outFacets = output.getFacets();
449
708de1779232 Add debug output for StateEngine
Björn Ricks <bjoern.ricks@intevation.de>
parents: 374
diff changeset
155 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
156
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
157 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
158
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
159 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
160 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
161 }
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
162
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
163 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
164 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
165 }
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
166
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
167 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
168 }
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
169 }
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
170 return compatibilityMatrix;
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
171 }
104
26bfff409dd3 Added interfaces and engines used in concrete artifact packages.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
172 }
347
16ab243507e0 Let StateEngine compute compatibility matrix based on a list of states.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 272
diff changeset
173 // vim:set ts=4 sw=4 et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org