# Coverage details for edu.uci.ics.jung.algorithms.blockmodel.BipartiteGraphCollapser

Line | Hits | Source
--- | --- | ---
1 |  | `/*`
2 |  | `* Copyright (c) 2003, the JUNG Project and the Regents of the University`
3 |  | `* of California`
4 |  | `* All rights reserved.`
5 |  | `*`
6 |  | `* This software is open-source under the BSD license; see either`
7 |  | `* "license.txt" or`
8 |  | `* http://jung.sourceforge.net/license.txt for a description.`
9 |  | `*/`
10 |  | `/*`
11 |  | `* Created on Feb 8, 2004`
12 |  | `*/`
13 |  | `package edu.uci.ics.jung.algorithms.blockmodel;`
14 |  | ``
15 |  | `import java.util.Iterator;`
16 |  | `import java.util.Set;`
17 |  | ``
18 |  | `import edu.uci.ics.jung.exceptions.FatalException;`
19 |  | `import edu.uci.ics.jung.graph.Graph;`
20 |  | `import edu.uci.ics.jung.graph.Vertex;`
21 |  | `import edu.uci.ics.jung.graph.impl.BipartiteEdge;`
22 |  | `import edu.uci.ics.jung.graph.impl.BipartiteGraph;`
23 |  | `import edu.uci.ics.jung.graph.impl.BipartiteVertex;`
24 |  | ``
25 |  | `/**`
26 |  | `* A variant of the GraphCollapser that overrides two`
27 |  | `* minor functions and defines CollapsedBipartiteEdge and`
28 |  | `* CollapsedBipartiteVertex. This models the basic procedure`
29 |  | `* for tweaking the GraphCollapser to your own (nefarious)`
30 |  | `* purposes.`
31 |  | `*`
32 |  | `* created Feb 8, 2004`
33 |  | `* @author danyelf`
34 |  | `*/`
35 | 1 | `public class BipartiteGraphCollapser extends GraphCollapser {`
36 |  | ``
37 |  | `public class CollapsedBipartiteEdge`
38 |  | `extends BipartiteEdge`
39 |  | `implements CollapsedEdge {`
40 |  | ``
41 |  | `private Set relevantEdges;`
42 |  | ``
43 |  | `public CollapsedBipartiteEdge(`
44 |  | `BipartiteVertex a,`
45 |  | `BipartiteVertex b,`
46 |  | `Set edges) {`
47 |  | `super(a, b);`
48 |  | `this.relevantEdges = edges;`
49 |  | `}`
50 |  | ``
51 |  | `public Set getRelevantEdges() {`
52 |  | `return relevantEdges;`
53 |  | `}`
54 |  | ``
55 |  | `}`
56 |  | ``
57 | 1 | `public class CollapsedBipartiteVertex`
58 |  | `extends BipartiteVertex`
59 |  | `implements CollapsedVertex {`
60 |  | ``
61 |  | `private Set rootSet;`
62 |  | ``
63 |  | `public CollapsedBipartiteVertex(Set rootSet) {`
64 |  | `this.rootSet = rootSet;`
65 |  | `}`
66 |  | ``
67 |  | `public Set getRootSet() {`
68 |  | `return rootSet;`
69 |  | `}`
70 |  | ``
71 |  | `}`
72 |  | ``
73 |  | `/**`
74 |  | `* @see edu.uci.ics.jung.graph.algorithms.blockmodel.GraphCollapser#addUndirectedEdge(edu.uci.ics.jung.graph.Graph, edu.uci.ics.jung.graph.Vertex, edu.uci.ics.jung.graph.Vertex, java.util.Set)`
75 |  | `*/`
76 |  | `protected void createUndirectedEdge(`
77 |  | `Graph g,`
78 |  | `CollapsedVertex superVertex,`
79 |  | `Vertex opposite,`
80 |  | `Set relevantEdges) {`
81 |  | ``
82 | 2 | `BipartiteGraph bpg = (BipartiteGraph) g;`
83 | 2 | `BipartiteVertex op = (BipartiteVertex) opposite,`
84 | 2 | `su = (BipartiteVertex) superVertex;`
85 |  | ``
86 |  | `CollapsedBipartiteEdge bpe;`
87 |  | `// order is important.`
88 | 2 | `if (bpg.getPartition(su) == BipartiteGraph.CLASSA) {`
89 | 2 | `bpe =`
90 |  | `(CollapsedBipartiteEdge) bpg.addBipartiteEdge(`
91 |  | `new CollapsedBipartiteEdge(su, op, relevantEdges));`
92 |  | `} else {`
93 | 0 | `bpe =`
94 |  | `(CollapsedBipartiteEdge) bpg.addBipartiteEdge(`
95 |  | `new CollapsedBipartiteEdge(op, su, relevantEdges));`
96 |  | `}`
97 | 2 | `annotateEdge(bpe, relevantEdges);`
98 | 2 | `}`
99 |  | ``
100 |  | `/**`
101 |  | `*`
102 |  | `* It must be the case that all members of rootSet are in the same partition.`
103 |  | `* @see edu.uci.ics.jung.graph.algorithms.blockmodel.GraphCollapser#getCollapsedVertex(edu.uci.ics.jung.graph.Graph, java.util.Set)`
104 |  | `*/`
105 |  | `protected CollapsedVertex createCollapsedVertex(Graph g, Set rootSet) {`
106 | 1 | `BipartiteGraph.Choice choice = null;`
107 | 1 | `BipartiteGraph bpg = (BipartiteGraph) g;`
108 | 1 | `for (Iterator iter = rootSet.iterator(); iter.hasNext();) {`
109 | 4 | `BipartiteVertex v = (BipartiteVertex) iter.next();`
110 | 4 | `if (choice == null) {`
111 | 1 | `choice = bpg.getPartition(v);`
112 |  | `} else {`
113 | 3 | `if (choice != bpg.getPartition(v)) {`
114 | 0 | `throw new FatalException("All vertices must be in the same partition");`
115 |  | `}`
116 |  | `}`
117 |  | `}`
118 |  | ``
119 | 1 | `CollapsedBipartiteVertex cbv = new CollapsedBipartiteVertex(rootSet);`
120 | 1 | `bpg.addVertex(cbv, choice);`
121 | 1 | `return cbv;`
122 |  | `}`
123 |  | ``
124 |  | `}`

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.