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

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 3, 2004
12  */
13 package edu.uci.ics.jung.algorithms.blockmodel;
14  
15 import java.util.*;
16 import java.util.HashSet;
17 import java.util.Iterator;
18 import java.util.Set;
19  
20 import edu.uci.ics.jung.graph.Graph;
21 import edu.uci.ics.jung.graph.Vertex;
22  
23 /**
24  * An EquivalenceRelation holds a number of Equivalent vertices from the
25  * same graph.
26  *
27  * created Feb 3, 2004
28  * @author danyelf
29  */
30 public class EquivalenceRelation {
31  
32     private Set equivalenceSets;
33     private Graph graph;
34  
35     /**
36      * Input is the basic data structure underneath: a Set of Sets.
37      * The sets must be mutually exclusive, non-empty,
38      * and contain only vertices from the graph. A reference to the
39      * underlying sets is maintained; be careful not to accidently
40      * modify them after the ER is created.
41      */
429    public EquivalenceRelation(Set rv, Graph g) {
439        this.equivalenceSets = Collections.unmodifiableSet( rv );
449        this.graph = g;
459    }
46  
47     /**
48      * Returns the common graph to which all the vertices belong
49      */
50     public Graph getGraph() {
512        return graph;
52     }
53  
54     /**
55      * Returns the set of vertices that do not belong to an particular equivalence class.
56      * Takes O(n) time by walking through the whole graph and checking all vertices that
57      * are not in any equivalence relation.
58      */
59     public Set getSingletonVertices() {
605        Set allVerticesInEquivalence = new HashSet();
615        for (Iterator iter = equivalenceSets.iterator(); iter.hasNext();) {
626            Set s = (Set) iter.next();
636            allVerticesInEquivalence.addAll(s);
64         }
655        Set allVertices = new HashSet(graph.getVertices());
665        allVertices.removeAll(allVerticesInEquivalence);
675        return allVertices;
68     }
69  
70     /**
71      * Iterates through all the equivalence sets. Does not return any singletons.
72      * @return an Iterator of Sets of vertices.
73      */
74     public Iterator getAllEquivalences() {
756        return equivalenceSets.iterator();
76     }
77  
78     /**
79      * Returns the part of the relation that contains this vertex: it is, of course, a Set
80      * If the vertex does not belong to any relation, null is returned.
81      */
82     public Set getEquivalenceRelationContaining(Vertex v) {
8316        for (Iterator iter = equivalenceSets.iterator(); iter.hasNext();) {
8422            Set s = (Set) iter.next();
8522            if (s.contains(v))
8613                return s;
87         }
883        return null;
89     }
90  
91     /**
92      * Returns the number of relations defined.
93      */
94     public int numRelations() {
955        return equivalenceSets.size();
96     }
97     
98     public String toString() {
990        return "Equivalence: " + equivalenceSets;
100     }
101  
102 }

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.