Line | Hits | Source |
---|---|---|
1 | /******************************************************************************* | |
2 | * Demetrix process modelling system | |
3 | * | |
4 | * Copyright (c) 2003, 2004 Dimitri A. Pissarenko | |
5 | * | |
6 | * This file is part of Demetrix. | |
7 | * | |
8 | * Demetrix is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2.1 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * Demetrix is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with Demetrix; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | * | |
22 | * For further information you may | |
23 | * | |
24 | * - send an e-mail in Russian, German or English to dimitri.pissarenko@gmx.net | |
25 | * - look at http://sourceforge.net/projects/demetrix/ | |
26 | * - look at http://demetrix.sourceforge.net/ | |
27 | * - look at http://members.inode.at/d.pissarenko/ | |
28 | * | |
29 | *****************************************************************************/ | |
30 | ||
31 | package net.sourceforge.demetrix.model; | |
32 | ||
33 | import java.util.Collection; | |
34 | ||
35 | import java.util.Hashtable; | |
36 | ||
37 | import java.util.Iterator; | |
38 | ||
39 | import java.util.Vector; | |
40 | ||
41 | import org._3pq.jgrapht.graph.ListenableDirectedGraph; | |
42 | ||
43 | /** | |
44 | * @author Dimitri Pissarenko | |
45 | * | |
46 | */ | |
47 | ||
48 | public class ProcessChain extends ListenableDirectedGraph { | |
49 | ||
50 | private String name; | |
51 | ||
52 | private Vector tasks; | |
53 | ||
54 | private Vector resources; | |
55 | ||
56 | private Vector links; | |
57 | ||
58 | private Hashtable nodesByName; | |
59 | ||
60 | private Hashtable inputsByName; | |
61 | ||
62 | private Hashtable outputsByName; | |
63 | ||
64 | public ProcessChain() { | |
65 | 25 | super(); |
66 | 25 | this.setName("process chain"); |
67 | 25 | this.tasks = new Vector(); |
68 | 25 | this.resources = new Vector(); |
69 | 25 | this.links = new Vector(); |
70 | 25 | this.nodesByName = new Hashtable(); |
71 | 25 | this.inputsByName = new Hashtable(); |
72 | 25 | this.outputsByName = new Hashtable(); |
73 | ||
74 | 25 | } |
75 | ||
76 | public String getName() { | |
77 | ||
78 | 0 | return this.name; |
79 | ||
80 | } | |
81 | ||
82 | public void setName(String name) { | |
83 | ||
84 | 25 | this.name = name; |
85 | ||
86 | 25 | } |
87 | ||
88 | public void addResource(Resource resource) { | |
89 | 14 | String resourceName = null; |
90 | 14 | this.resources.add(resource); |
91 | 14 | resourceName = (String) resource.getProperty("name").getValue(); |
92 | 14 | if (resourceName != null) { |
93 | 13 | this.nodesByName.put( |
94 | resource.getProperty("name").getValue(), | |
95 | resource); | |
96 | } | |
97 | 14 | this.addVertex(resource); |
98 | 14 | } |
99 | ||
100 | public void addResourceIfNotInProcessChain(Resource resource) { | |
101 | 2 | if (!this.resources.contains(resource)) { |
102 | 1 | this.addResource(resource); |
103 | } | |
104 | ||
105 | 2 | } |
106 | ||
107 | public void addTask(Task task) { | |
108 | ||
109 | 23 | this.tasks.add(task); |
110 | ||
111 | 23 | this.nodesByName.put(task.getProperty("name").getValue(), task); |
112 | 23 | this.addVertex(task); |
113 | 23 | } |
114 | ||
115 | public void addLink(Link link) { | |
116 | ||
117 | 4 | Vector inputs = null; |
118 | ||
119 | 4 | Vector outputs = null; |
120 | ||
121 | 4 | this.links.add(link); |
122 | 4 | this.addEdge(link); |
123 | /** | |
124 | * update inputsByName hashtable | |
125 | */ | |
126 | ||
127 | 4 | inputs = |
128 | (Vector) this.inputsByName.get( | |
129 | link.getProperty(Link.DESTINATION_PROPERTY).getValue()); | |
130 | ||
131 | 4 | if (inputs == null) { |
132 | ||
133 | 4 | inputs = new Vector(); |
134 | ||
135 | 4 | this.inputsByName.put( |
136 | link.getProperty(Link.DESTINATION_PROPERTY).getValue(), | |
137 | inputs); | |
138 | ||
139 | } | |
140 | ||
141 | 4 | inputs.add( |
142 | this.getNodeByName( | |
143 | link.getProperty(Link.SOURCE_PROPERTY).getValue().toString())); | |
144 | ||
145 | /** | |
146 | * update outputsByName hashtable | |
147 | */ | |
148 | ||
149 | 4 | outputs = |
150 | (Vector) this.outputsByName.get( | |
151 | link.getProperty(Link.SOURCE_PROPERTY).getValue()); | |
152 | ||
153 | 4 | if (outputs == null) { |
154 | ||
155 | 4 | outputs = new Vector(); |
156 | ||
157 | 4 | this.outputsByName.put( |
158 | link.getProperty(Link.SOURCE_PROPERTY).getValue(), | |
159 | outputs); | |
160 | ||
161 | } | |
162 | ||
163 | 4 | outputs.add( |
164 | this.getNodeByName( | |
165 | link.getProperty(Link.DESTINATION_PROPERTY).toString())); | |
166 | ||
167 | 4 | } |
168 | ||
169 | public Vector getInputs(String nodeName) { | |
170 | 2 | Vector returnValue=null; |
171 | ||
172 | 2 | returnValue=(Vector) this.inputsByName.get(nodeName); |
173 | 2 | if (returnValue==null) |
174 | { | |
175 | 2 | returnValue=new Vector(); |
176 | } | |
177 | 2 | return returnValue; |
178 | ||
179 | } | |
180 | ||
181 | public Vector getOutputs(String nodeName) { | |
182 | 2 | Vector returnValue=null; |
183 | 2 | returnValue=(Vector) this.outputsByName.get(nodeName); |
184 | 2 | if (returnValue==null) |
185 | { | |
186 | 2 | returnValue=new Vector(); |
187 | } | |
188 | 2 | return returnValue; |
189 | ||
190 | } | |
191 | ||
192 | public Vector getResources() { | |
193 | ||
194 | 40 | return this.resources; |
195 | ||
196 | } | |
197 | ||
198 | public Vector getTasks() { | |
199 | ||
200 | 41 | return this.tasks; |
201 | ||
202 | } | |
203 | ||
204 | public Vector getLinks() { | |
205 | ||
206 | 2 | return this.links; |
207 | ||
208 | } | |
209 | ||
210 | public ProcessChainNode getNodeByName(String nodeName) { | |
211 | ||
212 | 8 | return (ProcessChainNode) this.nodesByName.get(nodeName); |
213 | ||
214 | } | |
215 | ||
216 | public Vector getSystemOutputs() { | |
217 | ||
218 | 0 | return this.getExternalFlows(false); |
219 | ||
220 | } | |
221 | ||
222 | public Vector getSystemInputs() { | |
223 | ||
224 | 0 | return this.getExternalFlows(true); |
225 | ||
226 | } | |
227 | ||
228 | public static void linearizeList( | |
229 | Collection collectionToLinearize, | |
230 | Collection linearizedCollection) { | |
231 | ||
232 | 0 | Iterator collectionToLinearizeIterator = null; |
233 | ||
234 | 0 | Iterator currentCollectionIterator = null; |
235 | ||
236 | 0 | Collection currentCollection = null; |
237 | ||
238 | 0 | Object currentCollectionItem = null; |
239 | ||
240 | 0 | collectionToLinearizeIterator = collectionToLinearize.iterator(); |
241 | ||
242 | 0 | while (collectionToLinearizeIterator.hasNext()) { |
243 | ||
244 | 0 | currentCollection = |
245 | (Collection) collectionToLinearizeIterator.next(); | |
246 | ||
247 | 0 | currentCollectionIterator = currentCollection.iterator(); |
248 | ||
249 | 0 | while (currentCollectionIterator.hasNext()) { |
250 | ||
251 | 0 | currentCollectionItem = currentCollectionIterator.next(); |
252 | ||
253 | 0 | if (!linearizedCollection.contains(currentCollectionItem)) { |
254 | ||
255 | 0 | linearizedCollection.add(currentCollectionItem); |
256 | ||
257 | } | |
258 | ||
259 | } | |
260 | ||
261 | } | |
262 | ||
263 | 0 | } |
264 | ||
265 | private Vector getExternalFlows(boolean getInputs) { | |
266 | ||
267 | 0 | Iterator inputsOrOutputsIterator = null; |
268 | ||
269 | 0 | Iterator resourcesIterator = null; |
270 | ||
271 | 0 | Object resource = null; |
272 | ||
273 | 0 | Vector linearizedList = null; |
274 | ||
275 | 0 | Vector linearizedResources = null; |
276 | ||
277 | 0 | Vector externalFlows = null; |
278 | ||
279 | /** | |
280 | * linearize list | |
281 | */ | |
282 | ||
283 | 0 | linearizedList = new Vector(); |
284 | ||
285 | 0 | if (getInputs) { |
286 | ||
287 | 0 | ProcessChain.linearizeList( |
288 | this.outputsByName.values(), | |
289 | linearizedList); | |
290 | ||
291 | } else { | |
292 | ||
293 | 0 | ProcessChain.linearizeList( |
294 | this.inputsByName.values(), | |
295 | linearizedList); | |
296 | ||
297 | } | |
298 | ||
299 | 0 | linearizedResources = new Vector(); |
300 | ||
301 | 0 | if (getInputs) { |
302 | ||
303 | 0 | ProcessChain.linearizeList( |
304 | this.inputsByName.values(), | |
305 | linearizedResources); | |
306 | ||
307 | } else { | |
308 | ||
309 | 0 | ProcessChain.linearizeList( |
310 | this.outputsByName.values(), | |
311 | linearizedResources); | |
312 | ||
313 | } | |
314 | ||
315 | /** | |
316 | * get all external resources | |
317 | */ | |
318 | ||
319 | 0 | resourcesIterator = linearizedResources.iterator(); |
320 | ||
321 | 0 | externalFlows = new Vector(); |
322 | ||
323 | 0 | while (resourcesIterator.hasNext()) { |
324 | ||
325 | 0 | resource = resourcesIterator.next(); |
326 | ||
327 | 0 | if (!linearizedList.contains(resource)) { |
328 | ||
329 | 0 | externalFlows.add(resource); |
330 | ||
331 | } | |
332 | ||
333 | } | |
334 | 0 | return externalFlows; |
335 | } | |
336 | public void removeTaskOrResource(Object vertex) | |
337 | { | |
338 | 9 | this.tasks.remove(vertex); |
339 | 9 | this.resources.remove(vertex); |
340 | 9 | this.removeVertex(vertex); |
341 | 9 | } |
342 | public void removeLink(Link link) | |
343 | { | |
344 | 2 | this.links.remove(link); |
345 | 2 | this.removeEdge(link); |
346 | 2 | } |
347 | public void addTaskOrResource(ProcessChainNode node) | |
348 | { | |
349 | 2 | if (node instanceof Task) |
350 | { | |
351 | 1 | this.addTask((Task)node); |
352 | } | |
353 | 1 | else if (node instanceof Resource) |
354 | { | |
355 | 1 | this.addResource((Resource)node); |
356 | } | |
357 | 2 | } |
358 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |