Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/org/dive4elements/artifactdatabase/transition/TransitionEngine.java @ 500:cbe3dfd3e1a6 3.0.15
Framework: Added a method to the transition engine to recursively collect all state id for a given artifact identifer and a state id. Goal is to create a predicate dc:state-successors-contains($artifict-type-identifer, 'winfo.calculation.select, $current-state-id).
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Tue, 27 Aug 2013 15:48:26 +0200 |
parents | 415df0fc4fa1 |
children | 584591f8203c |
comparison
equal
deleted
inserted
replaced
499:baffc9b6f379 | 500:cbe3dfd3e1a6 |
---|---|
1 package org.dive4elements.artifactdatabase.transition; | 1 package org.dive4elements.artifactdatabase.transition; |
2 | 2 |
3 import java.util.ArrayDeque; | |
3 import java.util.ArrayList; | 4 import java.util.ArrayList; |
5 import java.util.Deque; | |
4 import java.util.HashMap; | 6 import java.util.HashMap; |
7 import java.util.HashSet; | |
5 import java.util.List; | 8 import java.util.List; |
6 import java.util.Map; | 9 import java.util.Map; |
10 import java.util.Set; | |
7 | 11 |
8 import org.apache.log4j.Logger; | 12 import org.apache.log4j.Logger; |
9 | 13 |
10 import org.dive4elements.artifacts.Artifact; | 14 import org.dive4elements.artifacts.Artifact; |
11 | 15 |
103 } | 107 } |
104 | 108 |
105 return reachable; | 109 return reachable; |
106 } | 110 } |
107 | 111 |
112 /** Returns all recursive reachable state ids for | |
113 * a given pair of artifact id and state id. | |
114 */ | |
115 public Set<String> allRecursiveSuccessorStateIds( | |
116 String artifactIdentifier, | |
117 String stateId | |
118 ) { | |
119 HashSet<String> result = new HashSet<String>(); | |
120 | |
121 List<Transition> trans = transitions.get(artifactIdentifier); | |
122 | |
123 if (trans == null) { | |
124 return result; | |
125 } | |
126 | |
127 Map<String, Set<String>> succs = new HashMap<String, Set<String>>(); | |
128 | |
129 for (Transition t: trans) { | |
130 String from = t.getFrom(); | |
131 String to = t.getTo(); | |
132 | |
133 Set<String> s = succs.get(from); | |
134 if (s == null) { | |
135 s = new HashSet<String>(); | |
136 succs.put(from, s); | |
137 } | |
138 s.add(to); | |
139 } | |
140 | |
141 Set<String> start = succs.get(stateId); | |
142 | |
143 if (start == null) { | |
144 return result; | |
145 } | |
146 | |
147 Deque<String> open = new ArrayDeque<String>(start); | |
148 | |
149 while (!open.isEmpty()) { | |
150 String cand = open.pop(); | |
151 if (result.add(cand)) { | |
152 Set<String> s = succs.get(cand); | |
153 if (s != null) { | |
154 open.addAll(s); | |
155 } | |
156 } | |
157 } | |
158 | |
159 return result; | |
160 } | |
161 | |
108 | 162 |
109 /** | 163 /** |
110 * Determines if a state with a given identifier is reachable from a current | 164 * Determines if a state with a given identifier is reachable from a current |
111 * state. | 165 * state. |
112 * | 166 * |