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

LineHitsSource
1 /*
2  * Created on Apr 27, 2005
3  *
4  * Copyright (c) 2005, 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.Collections;
15 import java.util.HashSet;
16 import java.util.Iterator;
17 import java.util.Set;
18  
19 import edu.uci.ics.jung.graph.Hyperedge;
20 import edu.uci.ics.jung.graph.Hypergraph;
21 import edu.uci.ics.jung.graph.Hypervertex;
22 import edu.uci.ics.jung.utils.GraphUtils;
23  
24 /**
25  * A basic implementation of <code>Hypergraph</code>. Edges
26  * and vertices are stored as <code>Set</code>s.
27  *
28  * @author Joshua O'Madadhain
29  */
30 public class SetHypergraph extends AbstractArchetypeGraph
31         implements Hypergraph
32 {
33     protected Set edges;
34     protected Set vertices;
35     
36     /**
37      *
38      */
39     public SetHypergraph()
40     {
410        super();
420        initialize();
430    }
44  
45     public void initialize()
46     {
470        edges = new HashSet();
480        vertices = new HashSet();
490        super.initialize();
500    }
51     
52     /**
53      * @see edu.uci.ics.jung.graph.Hypergraph#addVertex(edu.uci.ics.jung.graph.Hypervertex)
54      */
55     public Hypervertex addVertex(Hypervertex v)
56     {
570        checkConstraints(v, vertex_requirements);
58         
590        if (v instanceof AbstractElement)
60         {
610            AbstractElement ae = (AbstractElement) v;
620            ae.checkIDs(mVertexIDs);
630            ae.addGraph_internal(this);
64         }
650        vertices.add(v);
660        mGraphListenerHandler.handleAdd( v );
670        return v;
68     }
69  
70     /**
71      * Removes the vertex from this graph. If the vertex is an instance of
72      * <code>AbstractElement</code>, notifies it that it
73      * has been removed. Disconnects this vertex from any hyperedges to which
74      * it may be connected.
75      */
76     public void removeVertex(Hypervertex v)
77     {
780        if (v.getGraph() != this)
790            throw new IllegalArgumentException("This vertex is not in this graph");
80         
810        Set v_edges = new HashSet(v.getIncidentEdges());
820        for (Iterator iter = v_edges.iterator(); iter.hasNext(); )
830            v.disconnectEdge((Hyperedge)iter.next());
84         
850        if (v instanceof AbstractElement)
86         {
870            AbstractElement ae = (AbstractElement) v;
880            ae.removeGraph_internal();
890            mVertexIDs.remove(new Integer(ae.getID()));
90         }
91         
920        vertices.remove(v);
930        mGraphListenerHandler.handleRemove( v );
940    }
95     
96     /**
97      * @see edu.uci.ics.jung.graph.Hypergraph#addEdge(edu.uci.ics.jung.graph.Hyperedge)
98      */
99     public Hyperedge addEdge(Hyperedge e)
100     {
1010        checkConstraints(e, edge_requirements);
102         
1030        if (e instanceof AbstractElement)
104         {
1050            AbstractElement ae = (AbstractElement) e;
1060            ae.checkIDs(mEdgeIDs);
1070            ae.addGraph_internal(this);
108         }
1090        edges.add(e);
1100        mGraphListenerHandler.handleAdd( e );
1110        return e;
112     }
113  
114     /**
115      * Removes the edge from this graph. If the edge is an instance of
116      * <code>AbstractElement</code>, notifies it that it
117      * has been removed.
118      */
119     public void removeEdge(Hyperedge e)
120     {
1210        if (e.getGraph() != this)
1220            throw new IllegalArgumentException("This edge is not in this graph");
123  
1240        Set e_vertices = new HashSet(e.getIncidentVertices());
1250        for (Iterator iter = e_vertices.iterator(); iter.hasNext(); )
1260            e.disconnectVertex((Hypervertex)iter.next());
127         
1280        if (e instanceof AbstractElement)
129         {
1300            AbstractElement ae = (AbstractElement)e;
1310            ae.removeGraph_internal();
1320            mEdgeIDs.remove(new Integer(ae.getID()));
133         }
134  
1350        edges.remove(e);
1360        mGraphListenerHandler.handleRemove( e );
1370    }
138     
139     /**
140      * @see edu.uci.ics.jung.graph.ArchetypeGraph#getVertices()
141      */
142     public Set getVertices()
143     {
1440        return Collections.unmodifiableSet(vertices);
145     }
146  
147     /**
148      * @see edu.uci.ics.jung.graph.ArchetypeGraph#getEdges()
149      */
150     public Set getEdges()
151     {
1520        return Collections.unmodifiableSet(edges);
153     }
154  
155     /**
156      * Removes all vertices in the specified set from <code>g</code>. Syntactic
157      * sugar for a loop that calls <code>g.removeVertex</code> on all elements
158      * of the set.
159      * If any element of <code>vertices</code> is not part of this graph,
160      * then throws <code>IllegalArgumentException</code>. If this
161      * exception is thrown, any vertices that may have been removed already
162      * are not guaranteed to be restored to the graph.
163      */
164     public void removeVertices(Set vertices)
165     {
1660        GraphUtils.removeVertices(this, vertices);
1670    }
168  
169     /**
170      * Removes all vertices in the specified set from <code>g</code>. Syntactic
171      * sugar for a loop that calls <code>g.removeVertex</code> on all elements
172      * of the set.
173      * If any element of <code>edges</code> is not part of this graph,
174      * then throws <code>IllegalArgumentException</code>. If this
175      * exception is thrown, any edges that may have been removed already
176      * are not guaranteed to be restored to the graph.
177      */
178     public void removeEdges(Set edges)
179     {
1800        GraphUtils.removeEdges(this, edges);
1810    }
182 }

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.