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

LineHitsSource
1 /*
2  * Copyright (c) 2003, the JUNG Project and the Regents of the University of
3  * California All rights reserved.
4  *
5  * This software is open-source under the BSD license; see either "license.txt"
6  * or http://jung.sourceforge.net/license.txt for a description.
7  *
8  * Created on Mar 3, 2004
9  */
10 package edu.uci.ics.jung.graph.impl;
11  
12 import java.util.*;
13 import edu.uci.ics.jung.graph.*;
14  
15 /**
16  * This fully functional class is provided as a different sort of way to think about the creation
17  * and use of Vertices, and a reminder that the user is always welcome to create
18  * their own vertices. While most vertex classes keep a table from neighboring vertex to edge,
19  * this one keeps a linked list. This reduces the memory footprint, but makes
20  * <code>findEdge()</code> (as well as most other methods) require time proportional
21  * to the vertex's degree.
22  *
23  * @author Joshua O'Madadhain
24  */
250public class LeanSparseVertex extends AbstractSparseVertex {
26  
27     protected List incident_edges;
28  
29     protected void initialize() {
300        super.initialize();
310        this.incident_edges = new LinkedList();
320    }
33  
34     /**
35      * @see edu.uci.ics.jung.graph.impl.AbstractSparseVertex#getNeighbors_internal()
36      */
37     protected Collection getNeighbors_internal() {
380        Set neighbors = new HashSet();
390        for (Iterator inco_it = incident_edges.iterator(); inco_it.hasNext();)
400            neighbors.add(((Edge) inco_it.next()).getOpposite(this));
410        return neighbors;
42     }
43  
44     /**
45      * @see edu.uci.ics.jung.graph.impl.AbstractSparseVertex#getEdges_internal()
46      */
47     protected Collection getEdges_internal() {
480        return incident_edges;
49     }
50  
51     /**
52      * @see edu.uci.ics.jung.graph.impl.AbstractSparseVertex#addNeighbor_internal(edu.uci.ics.jung.graph.Edge,
53      * edu.uci.ics.jung.graph.Vertex)
54      */
55     protected void addNeighbor_internal(Edge e, Vertex v) {
560        incident_edges.add(e);
570    }
58  
59     /**
60      * @see edu.uci.ics.jung.graph.impl.AbstractSparseVertex#removeNeighbor_internal(edu.uci.ics.jung.graph.Edge,
61      * edu.uci.ics.jung.graph.Vertex)
62      */
63     protected void removeNeighbor_internal(Edge e, Vertex v) {
640        incident_edges.remove(e);
650    }
66  
67     /**
68      * @see edu.uci.ics.jung.graph.Vertex#findEdgeSet(Vertex)
69      */
70     public Set findEdgeSet(Vertex w) {
710        Set edges = new HashSet();
720        for (Iterator iter = incident_edges.iterator(); iter.hasNext();) {
730            Edge e = (Edge) iter.next();
740            if (e instanceof UndirectedEdge
750                    || ((DirectedEdge) e).getDest() == w) edges.add(e);
76         }
770        return edges;
78     }
79  
80     /**
81      * @see edu.uci.ics.jung.graph.Vertex#getPredecessors()
82      */
83     public Set getPredecessors() {
840        Set preds = new HashSet();
850        for (Iterator iter = incident_edges.iterator(); iter.hasNext();) {
860            Edge e = (Edge) iter.next();
870            if (e instanceof UndirectedEdge
88                     || ((DirectedEdge) e).getDest() == this)
890                    preds.add(e.getOpposite(this));
90         }
910        return preds;
92     }
93  
94     /**
95      * @see edu.uci.ics.jung.graph.Vertex#getSuccessors()
96      */
97     public Set getSuccessors() {
980        Set succs = new HashSet();
990        for (Iterator iter = incident_edges.iterator(); iter.hasNext();) {
1000            Edge e = (Edge) iter.next();
1010            if (e instanceof UndirectedEdge
102                     || ((DirectedEdge) e).getSource() == this)
1030                    succs.add(e.getOpposite(this));
104         }
1050        return succs;
106     }
107  
108     /**
109      * @see edu.uci.ics.jung.graph.Vertex#getInEdges()
110      */
111     public Set getInEdges() {
1120        Set in = new HashSet();
1130        for (Iterator iter = incident_edges.iterator(); iter.hasNext();) {
1140            Edge e = (Edge) iter.next();
1150            if (e instanceof UndirectedEdge
1160                    || ((DirectedEdge) e).getDest() == this) in.add(e);
117         }
1180        return in;
119     }
120  
121     /**
122      * @see edu.uci.ics.jung.graph.Vertex#getOutEdges()
123      */
124     public Set getOutEdges() {
1250        Set out = new HashSet();
1260        for (Iterator iter = incident_edges.iterator(); iter.hasNext();) {
1270            Edge e = (Edge) iter.next();
1280            if (e instanceof UndirectedEdge
1290                    || ((DirectedEdge) e).getSource() == this) out.add(e);
130         }
1310        return out;
132     }
133  
134     /**
135      * @see edu.uci.ics.jung.graph.Vertex#inDegree()
136      */
137     public int inDegree() {
1380        return getInEdges().size();
139     }
140  
141     /**
142      * @see edu.uci.ics.jung.graph.Vertex#outDegree()
143      */
144     public int outDegree() {
1450        return getOutEdges().size();
146     }
147  
148     /**
149      * @see edu.uci.ics.jung.graph.Vertex#numPredecessors()
150      */
151     public int numPredecessors() {
1520        return getPredecessors().size();
153     }
154  
155     /**
156      * @see edu.uci.ics.jung.graph.Vertex#numSuccessors()
157      */
158     public int numSuccessors() {
1590        return getSuccessors().size();
160     }
161  
162     /**
163      * @see edu.uci.ics.jung.graph.Vertex#isSuccessorOf(edu.uci.ics.jung.graph.Vertex)
164      */
165     public boolean isSuccessorOf(Vertex v) {
1660        for (Iterator iter = incident_edges.iterator(); iter.hasNext();) {
1670            Edge e = (Edge) iter.next();
1680            if (e.getOpposite(this) == v) {
1690                if (e instanceof DirectedEdge) {
1700                    return ((DirectedEdge) e).getDest() == this;
171                 } else
1720                    return true;
173             }
174         }
1750        return false;
176     }
177  
178     /**
179      * @see edu.uci.ics.jung.graph.Vertex#isPredecessorOf(edu.uci.ics.jung.graph.Vertex)
180      */
181     public boolean isPredecessorOf(Vertex v) {
1820        for (Iterator iter = incident_edges.iterator(); iter.hasNext();) {
1830            Edge e = (Edge) iter.next();
1840            if (e.getOpposite(this) == v) {
1850                if (e instanceof DirectedEdge) {
1860                    return ((DirectedEdge) e).getSource() == this;
187                 } else
1880                    return true;
189             }
190         }
1910        return false;
192     }
193  
194     /**
195      * @see edu.uci.ics.jung.graph.Vertex#isSource(edu.uci.ics.jung.graph.Edge)
196      */
197     public boolean isSource(Edge e) {
1980        if (e instanceof DirectedEdge)
1990            return ((DirectedEdge) e).getSource() == this;
200         else
201             // UndirectedEdge
2020            return e.isIncident(this);
203     }
204  
205     /**
206      * @see edu.uci.ics.jung.graph.Vertex#isDest(edu.uci.ics.jung.graph.Edge)
207      */
208     public boolean isDest(Edge e) {
2090        if (e instanceof DirectedEdge)
2100            return ((DirectedEdge) e).getDest() == this;
211         else
212             // UndirectedEdge
2130            return e.isIncident(this);
214     }
215 }

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.