Coverage details for net.sourceforge.demetrix.model.ProcessChain

LineHitsSource
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() {
6525        super();
6625        this.setName("process chain");
6725        this.tasks = new Vector();
6825        this.resources = new Vector();
6925        this.links = new Vector();
7025        this.nodesByName = new Hashtable();
7125        this.inputsByName = new Hashtable();
7225        this.outputsByName = new Hashtable();
73  
7425    }
75  
76     public String getName() {
77  
780        return this.name;
79  
80     }
81  
82     public void setName(String name) {
83  
8425        this.name = name;
85  
8625    }
87  
88     public void addResource(Resource resource) {
8914        String resourceName = null;
9014        this.resources.add(resource);
9114        resourceName = (String) resource.getProperty("name").getValue();
9214        if (resourceName != null) {
9313            this.nodesByName.put(
94                 resource.getProperty("name").getValue(),
95                 resource);
96         }
9714        this.addVertex(resource);
9814    }
99  
100     public void addResourceIfNotInProcessChain(Resource resource) {
1012        if (!this.resources.contains(resource)) {
1021            this.addResource(resource);
103         }
104  
1052    }
106  
107     public void addTask(Task task) {
108  
10923        this.tasks.add(task);
110  
11123        this.nodesByName.put(task.getProperty("name").getValue(), task);
11223        this.addVertex(task);
11323    }
114  
115     public void addLink(Link link) {
116  
1174        Vector inputs = null;
118  
1194        Vector outputs = null;
120  
1214        this.links.add(link);
1224        this.addEdge(link);
123         /**
124          * update inputsByName hashtable
125          */
126  
1274        inputs =
128             (Vector) this.inputsByName.get(
129                 link.getProperty(Link.DESTINATION_PROPERTY).getValue());
130  
1314        if (inputs == null) {
132  
1334            inputs = new Vector();
134  
1354            this.inputsByName.put(
136                 link.getProperty(Link.DESTINATION_PROPERTY).getValue(),
137                 inputs);
138  
139         }
140  
1414        inputs.add(
142             this.getNodeByName(
143                 link.getProperty(Link.SOURCE_PROPERTY).getValue().toString()));
144  
145         /**
146          * update outputsByName hashtable
147          */
148  
1494        outputs =
150             (Vector) this.outputsByName.get(
151                 link.getProperty(Link.SOURCE_PROPERTY).getValue());
152  
1534        if (outputs == null) {
154  
1554            outputs = new Vector();
156  
1574            this.outputsByName.put(
158                 link.getProperty(Link.SOURCE_PROPERTY).getValue(),
159                 outputs);
160  
161         }
162  
1634        outputs.add(
164             this.getNodeByName(
165                 link.getProperty(Link.DESTINATION_PROPERTY).toString()));
166  
1674    }
168  
169     public Vector getInputs(String nodeName) {
1702        Vector returnValue=null;
171         
1722        returnValue=(Vector) this.inputsByName.get(nodeName);
1732        if (returnValue==null)
174         {
1752            returnValue=new Vector();
176         }
1772        return returnValue;
178  
179     }
180  
181     public Vector getOutputs(String nodeName) {
1822        Vector returnValue=null;
1832        returnValue=(Vector) this.outputsByName.get(nodeName);
1842        if (returnValue==null)
185         {
1862            returnValue=new Vector();
187         }
1882        return returnValue;
189  
190     }
191  
192     public Vector getResources() {
193  
19440        return this.resources;
195  
196     }
197  
198     public Vector getTasks() {
199  
20041        return this.tasks;
201  
202     }
203  
204     public Vector getLinks() {
205  
2062        return this.links;
207  
208     }
209  
210     public ProcessChainNode getNodeByName(String nodeName) {
211  
2128        return (ProcessChainNode) this.nodesByName.get(nodeName);
213  
214     }
215  
216     public Vector getSystemOutputs() {
217  
2180        return this.getExternalFlows(false);
219  
220     }
221  
222     public Vector getSystemInputs() {
223  
2240        return this.getExternalFlows(true);
225  
226     }
227  
228     public static void linearizeList(
229         Collection collectionToLinearize,
230         Collection linearizedCollection) {
231  
2320        Iterator collectionToLinearizeIterator = null;
233  
2340        Iterator currentCollectionIterator = null;
235  
2360        Collection currentCollection = null;
237  
2380        Object currentCollectionItem = null;
239  
2400        collectionToLinearizeIterator = collectionToLinearize.iterator();
241  
2420        while (collectionToLinearizeIterator.hasNext()) {
243  
2440            currentCollection =
245                 (Collection) collectionToLinearizeIterator.next();
246  
2470            currentCollectionIterator = currentCollection.iterator();
248  
2490            while (currentCollectionIterator.hasNext()) {
250  
2510                currentCollectionItem = currentCollectionIterator.next();
252  
2530                if (!linearizedCollection.contains(currentCollectionItem)) {
254  
2550                    linearizedCollection.add(currentCollectionItem);
256  
257                 }
258  
259             }
260  
261         }
262  
2630    }
264  
265     private Vector getExternalFlows(boolean getInputs) {
266  
2670        Iterator inputsOrOutputsIterator = null;
268  
2690        Iterator resourcesIterator = null;
270  
2710        Object resource = null;
272  
2730        Vector linearizedList = null;
274  
2750        Vector linearizedResources = null;
276  
2770        Vector externalFlows = null;
278  
279         /**
280          * linearize list
281          */
282  
2830        linearizedList = new Vector();
284  
2850        if (getInputs) {
286  
2870            ProcessChain.linearizeList(
288                 this.outputsByName.values(),
289                 linearizedList);
290  
291         } else {
292  
2930            ProcessChain.linearizeList(
294                 this.inputsByName.values(),
295                 linearizedList);
296  
297         }
298  
2990        linearizedResources = new Vector();
300  
3010        if (getInputs) {
302  
3030            ProcessChain.linearizeList(
304                 this.inputsByName.values(),
305                 linearizedResources);
306  
307         } else {
308  
3090            ProcessChain.linearizeList(
310                 this.outputsByName.values(),
311                 linearizedResources);
312  
313         }
314  
315         /**
316          * get all external resources
317          */
318  
3190        resourcesIterator = linearizedResources.iterator();
320  
3210        externalFlows = new Vector();
322  
3230        while (resourcesIterator.hasNext()) {
324  
3250            resource = resourcesIterator.next();
326  
3270            if (!linearizedList.contains(resource)) {
328  
3290                externalFlows.add(resource);
330  
331             }
332  
333         }
3340        return externalFlows;
335     }
336     public void removeTaskOrResource(Object vertex)
337     {
3389        this.tasks.remove(vertex);
3399        this.resources.remove(vertex);
3409        this.removeVertex(vertex);
3419    }
342     public void removeLink(Link link)
343     {
3442        this.links.remove(link);
3452        this.removeEdge(link);
3462    }
347     public void addTaskOrResource(ProcessChainNode node)
348     {
3492        if (node instanceof Task)
350         {
3511            this.addTask((Task)node);
352         }
3531        else if (node instanceof Resource)
354         {
3551            this.addResource((Resource)node);
356         }
3572    }
358 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.