Coverage details for edu.uci.ics.jung.algorithms.cluster.VertexClusterSet

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 package edu.uci.ics.jung.algorithms.cluster;
11  
12 import java.util.HashSet;
13 import java.util.Iterator;
14 import java.util.Set;
15  
16 import edu.uci.ics.jung.graph.ArchetypeGraph;
17 import edu.uci.ics.jung.graph.ArchetypeVertex;
18 import edu.uci.ics.jung.graph.Graph;
19 import edu.uci.ics.jung.utils.GraphUtils;
20  
21 /**
22  * A ClusterSet where each cluster is a set of vertices
23  * @author Scott White
24  */
25 public class VertexClusterSet extends ClusterSet {
26  
27     /**
28      * Constructs and initializes the set
29      * @param underlyingGraph
30      */
31     public VertexClusterSet(ArchetypeGraph underlyingGraph) {
3216        super(underlyingGraph);
3316    }
34  
35     /**
36      * Constructs a new graph from the given cluster
37      * @param index the position index of the cluster in the collection
38      * @return a new graph representing the cluster
39      */
40     public Graph getClusterAsNewSubGraph(int index) {
410        return GraphUtils.vertexSetToGraph(getCluster(index));
42     }
43  
44     /**
45      * Creates a new cluster set where each vertex and cluster in the new cluster set correspond 1-to-1 with
46      * those in the original graph
47      * @param anotherGraph a new graph whose vertices are equivalent to those in the original graph
48      * @return a new cluster set for the specified graph
49      */
50     public ClusterSet createEquivalentClusterSet(Graph anotherGraph) {
510        ClusterSet newClusterSet = new VertexClusterSet(anotherGraph);
520        for (Iterator cIt=iterator();cIt.hasNext();) {
530            Set cluster = (Set) cIt.next();
540            Set newCluster = new HashSet();
550            for (Iterator vIt=cluster.iterator();vIt.hasNext();) {
560                ArchetypeVertex vertex = (ArchetypeVertex) vIt.next();
570                ArchetypeVertex equivalentVertex = vertex.getEqualVertex(anotherGraph);
580                if (equivalentVertex == null) {
590                    throw new IllegalArgumentException("Can not create equivalent cluster set because equivalent vertices could not be found in the other graph.");
60                 }
610                newCluster.add(equivalentVertex);
62             }
630            newClusterSet.addCluster(newCluster);
64         }
650        return newClusterSet;
66  
67     }
68 }

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.