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

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.Collection;
15 import java.util.Collections;
16 import java.util.HashSet;
17 import java.util.Iterator;
18 import java.util.Set;
19  
20 import edu.uci.ics.jung.graph.ArchetypeEdge;
21 import edu.uci.ics.jung.graph.ArchetypeGraph;
22 import edu.uci.ics.jung.graph.Hyperedge;
23 import edu.uci.ics.jung.graph.Hypergraph;
24 import edu.uci.ics.jung.graph.Hypervertex;
25  
26 /**
27  * This class provides a skeletal implementation of the <code>Hyperedge</code>
28  * interface to minimize the effort required to implement this interface.
29  * <P>
30  * This class extends <code>UserData</code>, which provides storage and
31  * retrieval mechanisms for user-defined data for each edge instance.
32  * This allows users to attach data to edges without having to extend
33  * this class.
34  *
35  * @author Joshua O'Madadhain
36  *
37  * @see SetHypergraph
38  * @see AbstractHypervertex
39  */
40 public abstract class AbstractHyperedge extends AbstractArchetypeEdge implements
41         Hyperedge
42 {
43     /**
44      * The next edge ID.
45      */
460    private static int nextGlobalEdgeID = 0;
47     
48     public AbstractHyperedge()
49     {
500        super();
510        this.id = nextGlobalEdgeID++;
520        initialize();
530    }
54     
55     protected void initialize()
56     {
570        super.initialize();
580    }
59     
60     /**
61      * Connects <code>hv1</code> to this edge and vice versa. If <code>hv1</code> is already
62      * incident to this edge, returns <code>false</code>; otherwise, returns <code>true</code>.
63      * Throws <code>IllegalArgumentException</code> if this edge is an
64      * orphan, or if <code>hv1</code> is either an orphan or part of a different graph than this edge.
65      *
66      * @see edu.uci.ics.jung.graph.Hyperedge#connectVertex(edu.uci.ics.jung.graph.Hypervertex)
67      */
68     public boolean connectVertex(Hypervertex hv1)
69     {
700        ArchetypeGraph g = this.getGraph();
710        if (g == null)
720            throw new IllegalArgumentException("Orphaned hyperedges may not be " +
73                     "connected to (or disconnected from) vertices");
74         
750        if (g != hv1.getGraph())
760            throw new IllegalArgumentException("Hypervertex " + hv1 + " is either orphaned" +
77                     "or an element of a graph other than " + g);
78         
790        if (hv1.isIncident(this))
800            return false;
81         
820        if (hv1 instanceof AbstractHypervertex)
83         {
840            AbstractHypervertex av = (AbstractHypervertex)hv1;
850            av.getEdges_internal().add(this);
86         }
870        getVertices_internal().add(hv1);
88         
890        return true;
90     }
91  
92     /**
93      * Disconnects <code>hv1</code> from this edge and vice versa. If <code>hv1</code> is not
94      * incident to this edge, returns <code>false</code>; otherwise, returns <code>true</code>.
95      *
96      * @see edu.uci.ics.jung.graph.Hyperedge#disconnectVertex(edu.uci.ics.jung.graph.Hypervertex)
97      */
98     public boolean disconnectVertex(Hypervertex hv1)
99     {
1000        ArchetypeGraph g = this.getGraph();
1010        if (g == null)
1020            throw new IllegalArgumentException("Orphaned hyperedges may not be " +
103                     "connected to (or disconnected from) vertices");
104         
1050        if (g != hv1.getGraph())
1060            throw new IllegalArgumentException("Hypervertex " + hv1 + " is either orphaned" +
107                     "or an element of a graph other than " + g);
108         
1090        if (!hv1.isIncident(this))
1100            return false;
111  
1120        if (hv1 instanceof AbstractHypervertex)
113         {
1140            AbstractHypervertex av = (AbstractHypervertex)hv1;
1150            av.getEdges_internal().remove(this);
116         }
1170        getVertices_internal().remove(hv1);
118         
1190        return true;
120     }
121  
122     /**
123      * Creates a copy of this edge in the specified graph <code>newGraph</code>,
124      * and copies this edge's user data to the new edge. Connects this
125      *
126      * @see edu.uci.ics.jung.graph.ArchetypeEdge#copy(edu.uci.ics.jung.graph.ArchetypeGraph)
127      */
128     public ArchetypeEdge copy(ArchetypeGraph newGraph)
129     {
1300        Hyperedge e = (Hyperedge)super.copy(newGraph);
1310        ((Hypergraph)newGraph).addEdge(e);
132         
1330        for (Iterator iter = getVertices_internal().iterator(); iter.hasNext(); )
134         {
1350            Hypervertex v = (Hypervertex)iter.next();
1360            e.connectVertex((Hypervertex)v.getEqualVertex(newGraph));
137         }
1380        return e;
139     }
140     
141     /**
142      * @see edu.uci.ics.jung.graph.ArchetypeEdge#getIncidentVertices()
143      */
144     public Set getIncidentVertices()
145     {
1460        return Collections.unmodifiableSet(new HashSet(getVertices_internal()));
147     }
148     
149  
150     /**
151      * Returns a human-readable representation of this edge.
152      *
153      * @see java.lang.Object#toString()
154      */
155     public String toString()
156     {
1570        String label = "HE" + id + "(";
1580        for (Iterator iter = getVertices_internal().iterator(); iter.hasNext(); )
159         {
1600            Hypervertex v = (Hypervertex)iter.next();
1610            label += v.toString();
1620            if (iter.hasNext())
1630                label += ",";
164         }
1650        return label + ")";
166     }
167  
168     protected abstract Collection getVertices_internal();
169 }

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.