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

LineHitsSource
1 /*
2  * Created on Apr 26, 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.exceptions.FatalException;
21 import edu.uci.ics.jung.graph.ArchetypeEdge;
22 import edu.uci.ics.jung.graph.ArchetypeGraph;
23 import edu.uci.ics.jung.graph.ArchetypeVertex;
24  
25 /**
26  *
27  * @author Joshua O'Madadhain
28  */
29 public abstract class AbstractArchetypeVertex extends AbstractElement implements ArchetypeVertex
30 {
31     /**
32      *
33      */
34     public AbstractArchetypeVertex()
35     {
3631676        super();
3731676        initialize();
3831676    }
39  
40     /**
41      * @see edu.uci.ics.jung.graph.Element#getIncidentElements()
42      */
43     public Set getIncidentElements()
44     {
450        return getIncidentEdges();
46     }
47     
48     /**
49      * @see ArchetypeVertex#getNeighbors()
50      */
51     public Set getNeighbors() {
52299        return Collections.unmodifiableSet(new HashSet(getNeighbors_internal()));
53     }
54  
55     /**
56      *
57      * @see edu.uci.ics.jung.graph.ArchetypeVertex#numNeighbors()
58      */
59     public int numNeighbors() {
606        return getNeighbors_internal().size();
61     }
62     
63     /**
64      * @see ArchetypeVertex#getIncidentEdges()
65      */
66     public Set getIncidentEdges() {
67118193        return Collections.unmodifiableSet(new HashSet(getEdges_internal()));
68     }
69  
70     /**
71      * @see ArchetypeVertex#degree()
72      */
73     public int degree() {
74425822        return getEdges_internal().size();
75     }
76     
77     /**
78      * @see ArchetypeVertex#isNeighborOf(ArchetypeVertex)
79      */
80     public boolean isNeighborOf(ArchetypeVertex v) {
811435        return getNeighbors_internal().contains(v);
82     }
83  
84     /**
85      * @see ArchetypeVertex#isIncident(ArchetypeEdge)
86      */
87     public boolean isIncident(ArchetypeEdge e) {
8810        return getEdges_internal().contains(e);
89     }
90     
91  
92     /**
93      * @see edu.uci.ics.jung.graph.ArchetypeVertex#copy(edu.uci.ics.jung.graph.ArchetypeGraph)
94      */
95     public ArchetypeVertex copy(ArchetypeGraph g)
96     {
97729        if (g == this.getGraph())
981            throw new IllegalArgumentException("Source and destination graphs "
99                     + "must be different");
100  
101         try
102         {
103728            AbstractArchetypeVertex v = (AbstractArchetypeVertex) clone();
104728            v.initialize();
105728            v.importUserData(this);
106728            return v;
107         }
1080        catch (CloneNotSupportedException cne)
109         {
1100            throw new FatalException("Failure in cloning " + this, cne);
111         }
112     }
113  
114     /**
115      * Returns <code>true</code> if <code>o</code> is an instance of
116      * <code>ArchetypeVertex</code> that is equivalent to this vertex.
117      * Respects the vertex
118      * equivalences which are established by <code>copy()</code> and
119      * referenced by <code>getEquivalentVertex()</code>.
120      *
121      * @see java.lang.Object#equals(java.lang.Object)
122      * @see ArchetypeVertex#getEqualVertex(ArchetypeGraph)
123      * @see ArchetypeVertex#copy
124      */
125     public boolean equals(Object o)
126     {
127176985        if (this == o)
12835            return true;
129176950        if (!(o instanceof ArchetypeVertex))
1300            return false;
131176950        ArchetypeVertex v = (ArchetypeVertex)o;
132176950        return (this == v.getEqualVertex(this.getGraph()));
133     }
134  
135     /**
136      * Returns the vertex in the specified graph <code>ag</code>
137      * that is equivalent to this vertex. If there is no
138      * such vertex, or if <code>ag</code> is not an instance
139      * of <code>AbstractSparseGraph</code>, returns <code>null</code>.
140      *
141      * @see ArchetypeVertex#getEqualVertex(ArchetypeGraph)
142      */
143     public ArchetypeVertex getEqualVertex(ArchetypeGraph ag)
144     {
145181031        if (ag instanceof AbstractArchetypeGraph)
146         {
14792914            AbstractArchetypeGraph aag = (AbstractArchetypeGraph)ag;
14892914            return aag.getVertexByID(this.getID());
149         }
150         else
15188117            return null;
152     }
153  
154     /**
155      * @deprecated As of version 1.4, renamed to getEqualVertex(ag).
156      */
157     public ArchetypeVertex getEquivalentVertex(ArchetypeGraph ag)
158     {
1590        return getEqualVertex(ag);
160     }
161     
162     
163     /**
164      * @see edu.uci.ics.jung.graph.ArchetypeVertex#findEdge(edu.uci.ics.jung.graph.ArchetypeVertex)
165      */
166     public ArchetypeEdge findEdge(ArchetypeVertex v)
167     {
1680        for (Iterator iter = getEdges_internal().iterator(); iter.hasNext(); )
169         {
1700            ArchetypeEdge ae = (ArchetypeEdge)iter.next();
1710            if (ae.isIncident(v))
1720                return ae;
173         }
1740        return null;
175     }
176  
177     /**
178      * @see edu.uci.ics.jung.graph.ArchetypeVertex#findEdgeSet(edu.uci.ics.jung.graph.ArchetypeVertex)
179      */
180     public Set findEdgeSet(ArchetypeVertex v)
181     {
1820        Set edges = new HashSet();
1830        for (Iterator iter = getEdges_internal().iterator(); iter.hasNext(); )
184         {
1850            ArchetypeEdge ae = (ArchetypeEdge)iter.next();
1860            if (ae.isIncident(v))
1870                edges.add(ae);
188         }
1890        return Collections.unmodifiableSet(edges);
190     }
191  
192     /**
193      * Returns a set containing all neighbors of this vertex. This
194      * is an internal method which is not intended for users.
195      */
196     protected abstract Collection getNeighbors_internal();
197  
198     /**
199      * Returns a set containing all the incident edges of this vertex.
200      * This is an internal method which is not intended for users.
201      */
202     protected abstract Collection getEdges_internal();
203  
204 }

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.