comparison artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java @ 347:16ab243507e0

Let StateEngine compute compatibility matrix based on a list of states. artifacts/trunk@3108 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 28 Oct 2011 10:08:35 +0000
parents 2ce31a9414ff
children 5420b96dd0b3
comparison
equal deleted inserted replaced
346:2d525562fae9 347:16ab243507e0
1 package de.intevation.artifactdatabase.state; 1 package de.intevation.artifactdatabase.state;
2 2
3 import java.util.ArrayList;
3 import java.util.HashMap; 4 import java.util.HashMap;
4 import java.util.List; 5 import java.util.List;
5 import java.util.Map; 6 import java.util.Map;
6 7
7 import org.apache.log4j.Logger; 8 import org.apache.log4j.Logger;
8 9
9 /** 10 /**
10 * The StateEngine stores all states for each Artifact. 11 * The StateEngine stores all states and associated information about
12 * outputs and facets for each Artifact.
11 * 13 *
12 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 14 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
13 */ 15 */
14 public class StateEngine { 16 public class StateEngine {
15 17
91 93
92 94
93 /** 95 /**
94 * Returns the state list of an artifact specified by its name. 96 * Returns the state list of an artifact specified by its name.
95 * 97 *
96 * @param artifact The name of the artifact. 98 * @param artifact The name of the artifact (e.g. "winfo").
97 * 99 *
98 * @return the list of states of this artifact or <i>null</i> if no states 100 * @return the list of states of this artifact or <i>null</i> if no states
99 * are existing for this <i>artifact</i>. 101 * are existing for this <i>artifact</i>.
100 */ 102 */
101 public List<State> getStates(String artifact) { 103 public List<State> getStates(String artifact) {
102 return states.get(artifact); 104 return states.get(artifact);
103 } 105 }
106
107
108 /**
109 * Return mapping of output to facets for an artifact in its states.
110 */
111 public Map<String, List<String>> getCompatibleFacets(List<String> aStates) {
112 Map<String, List<String>> compatibilityMatrix =
113 new HashMap<String, List<String>>();
114
115 // For all states that the artifact had seen, add outputs facets.
116 for (String stateId: aStates) {
117
118 State state = allStates.get(stateId);
119 if (state == null) {
120 continue;
121 }
122
123 for (Output output: state.getOutputs()) {
124 List<Facet> outFacets = output.getFacets();
125
126 List<String> oldFacets = compatibilityMatrix.get(output.getName());
127
128 if (oldFacets == null) {
129 oldFacets = new ArrayList<String>();
130 }
131
132 for (Facet facet: outFacets) {
133 oldFacets.add(facet.getName());
134 }
135
136 compatibilityMatrix.put(output.getName(), oldFacets);
137 }
138 }
139 return compatibilityMatrix;
140 }
104 } 141 }
105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 142 // vim:set ts=4 sw=4 et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org