| 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 | 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) { | |
| 32 | 16 | super(underlyingGraph); |
| 33 | 16 | } |
| 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) { | |
| 41 | 0 | 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) { | |
| 51 | 0 | ClusterSet newClusterSet = new VertexClusterSet(anotherGraph); |
| 52 | 0 | for (Iterator cIt=iterator();cIt.hasNext();) { |
| 53 | 0 | Set cluster = (Set) cIt.next(); |
| 54 | 0 | Set newCluster = new HashSet(); |
| 55 | 0 | for (Iterator vIt=cluster.iterator();vIt.hasNext();) { |
| 56 | 0 | ArchetypeVertex vertex = (ArchetypeVertex) vIt.next(); |
| 57 | 0 | ArchetypeVertex equivalentVertex = vertex.getEqualVertex(anotherGraph); |
| 58 | 0 | if (equivalentVertex == null) { |
| 59 | 0 | throw new IllegalArgumentException("Can not create equivalent cluster set because equivalent vertices could not be found in the other graph."); |
| 60 | } | |
| 61 | 0 | newCluster.add(equivalentVertex); |
| 62 | } | |
| 63 | 0 | newClusterSet.addCluster(newCluster); |
| 64 | } | |
| 65 | 0 | return newClusterSet; |
| 66 | ||
| 67 | } | |
| 68 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |