Coverage details for edu.uci.ics.jung.graph.impl.KPartiteSparseGraph

LineHitsSource
1 /*
2  * Created on Mar 29, 2004
3  *
4  * Copyright (c) 2004, the JUNG Project and the Regents of the University
5  * of California
6  * All rights reserved.
7  *
8  * This software is open-source under the BSD license; see either
9  * "license.txt" or
10  * http://jung.sourceforge.net/license.txt for a description.
11  */
12 package edu.uci.ics.jung.graph.impl;
13  
14 import java.util.Collection;
15 import java.util.Iterator;
16  
17 import org.apache.commons.collections.Predicate;
18 import org.apache.commons.collections.functors.OnePredicate;
19  
20 import edu.uci.ics.jung.graph.Edge;
21 import edu.uci.ics.jung.graph.Graph;
22 import edu.uci.ics.jung.graph.KPartiteGraph;
23 import edu.uci.ics.jung.graph.Vertex;
24 import edu.uci.ics.jung.graph.predicates.KPartiteEdgePredicate;
25 import edu.uci.ics.jung.utils.SubsetManager;
26  
27  
28 /**
29  * An implementation of KPartiteGraph based on SparseGraph.
30  * This implementation optionally creates a subset for each partition
31  * specified in the constructor.
32  *
33  * <p>Vertex constraints imposed by this class: predicates in
34  * <code>partitions</code> constructor argument</p>
35  * <p>Edge constraints imposed by this class:
36  * <code>KPartiteEdgePredicate(partitions)</code></p>
37  *
38  * @author Joshua O'Madadhain
39  */
40 public class KPartiteSparseGraph extends SparseGraph implements KPartiteGraph
41 {
42     protected Collection partitions;
43  
44     /**
45      * Creates a KPartiteSparseGraph whose partitions are specified by
46      * the predicates in the <code>partitions</code> array. If the
47      * <code>subsets</code> argument is true, creates a subset for
48      * each partition.
49      */
50     public KPartiteSparseGraph(Collection partitions, boolean subsets)
51     {
5218        super();
5318        if (partitions.size() < 2)
540            throw new IllegalArgumentException("Constructor must " +
55                   "specify >= 2 vertex partition predicates");
5618        this.partitions = partitions;
57         
58         // each vertex added must satisfy exactly 1 partition-specific predicate
5918        getVertexConstraints().add(OnePredicate.getInstance(partitions));
60         
61         // each edge added must connect vertices in distinct partitions
62 // user_edge_requirements.add(new KPartiteEdgePredicate(partitions));
6318        getEdgeConstraints().add(new KPartiteEdgePredicate(partitions));
64         
65         // create a subset for each vertex predicate
6618        if (subsets)
67         {
6818            SubsetManager sm = SubsetManager.getInstance(this);
6918            for (Iterator p_iter = partitions.iterator(); p_iter.hasNext(); )
7036                sm.addVertexSubset((Predicate)p_iter.next());
71         }
7218    }
73     
74     /**
75      * <p>
76      * Creates a new <code>KPartiteSparseGraph</code> which contains all the
77      * vertices and edges in <code>g</code>. The new graph contains all the
78      * user data from the original graph and its components.
79      * </p>
80      * <p>
81      * This method performs no tagging or structural conversion. If
82      * <code>g</code> is not compatible with the constraints specified by
83      * <code>partitions</code>, this constructor will throw an
84      * <code>IllegalArgumentException</code>. Thus, each vertex in
85      * <code>g</code> must be a member of exactly one partition, and each edge
86      * must join vertices in distinct partitions.
87      * </p>
88      */
89     public KPartiteSparseGraph(Graph g, Collection partitions, boolean subsets)
90     {
914        this(partitions, subsets);
92         
934        addAllNotInitializers(getEdgeConstraints(), g.getEdgeConstraints());
944        addAllNotInitializers(getVertexConstraints(), g.getVertexConstraints());
954        for (Iterator iter = g.getVertices().iterator(); iter.hasNext();)
96         {
9716            Vertex av = (Vertex) iter.next();
9816            av.copy(this);
99         }
100         
1013        for (Iterator iter = g.getEdges().iterator(); iter.hasNext();)
102         {
1038            Edge ae = (Edge) iter.next();
1048            ae.copy(this);
105         }
106         
1071        this.importUserData(g);
1081    }
109     
110     public Collection getPartitions()
111     {
1123        return partitions;
113     }
114 }

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.