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

LineHitsSource
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  */
351public 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  
571    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  
822        BipartiteGraph bpg = (BipartiteGraph) g;
832        BipartiteVertex op = (BipartiteVertex) opposite,
842            su = (BipartiteVertex) superVertex;
85  
86         CollapsedBipartiteEdge bpe;
87         // order is important.
882        if (bpg.getPartition(su) == BipartiteGraph.CLASSA) {
892            bpe =
90                 (CollapsedBipartiteEdge) bpg.addBipartiteEdge(
91                     new CollapsedBipartiteEdge(su, op, relevantEdges));
92         } else {
930            bpe =
94                 (CollapsedBipartiteEdge) bpg.addBipartiteEdge(
95                     new CollapsedBipartiteEdge(op, su, relevantEdges));
96         }
972        annotateEdge(bpe, relevantEdges);
982    }
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) {
1061        BipartiteGraph.Choice choice = null;
1071        BipartiteGraph bpg = (BipartiteGraph) g;
1081        for (Iterator iter = rootSet.iterator(); iter.hasNext();) {
1094            BipartiteVertex v = (BipartiteVertex) iter.next();
1104            if (choice == null) {
1111                choice = bpg.getPartition(v);
112             } else {
1133                if (choice != bpg.getPartition(v)) {
1140                    throw new FatalException("All vertices must be in the same partition");
115                 }
116             }
117         }
118  
1191        CollapsedBipartiteVertex cbv = new CollapsedBipartiteVertex(rootSet);
1201        bpg.addVertex(cbv, choice);
1211        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.