Line | Hits | Source |
---|---|---|
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 | { | |
36 | 31676 | super(); |
37 | 31676 | initialize(); |
38 | 31676 | } |
39 | ||
40 | /** | |
41 | * @see edu.uci.ics.jung.graph.Element#getIncidentElements() | |
42 | */ | |
43 | public Set getIncidentElements() | |
44 | { | |
45 | 0 | return getIncidentEdges(); |
46 | } | |
47 | ||
48 | /** | |
49 | * @see ArchetypeVertex#getNeighbors() | |
50 | */ | |
51 | public Set getNeighbors() { | |
52 | 299 | 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() { | |
60 | 6 | return getNeighbors_internal().size(); |
61 | } | |
62 | ||
63 | /** | |
64 | * @see ArchetypeVertex#getIncidentEdges() | |
65 | */ | |
66 | public Set getIncidentEdges() { | |
67 | 118193 | return Collections.unmodifiableSet(new HashSet(getEdges_internal())); |
68 | } | |
69 | ||
70 | /** | |
71 | * @see ArchetypeVertex#degree() | |
72 | */ | |
73 | public int degree() { | |
74 | 425822 | return getEdges_internal().size(); |
75 | } | |
76 | ||
77 | /** | |
78 | * @see ArchetypeVertex#isNeighborOf(ArchetypeVertex) | |
79 | */ | |
80 | public boolean isNeighborOf(ArchetypeVertex v) { | |
81 | 1435 | return getNeighbors_internal().contains(v); |
82 | } | |
83 | ||
84 | /** | |
85 | * @see ArchetypeVertex#isIncident(ArchetypeEdge) | |
86 | */ | |
87 | public boolean isIncident(ArchetypeEdge e) { | |
88 | 10 | 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 | { | |
97 | 729 | if (g == this.getGraph()) |
98 | 1 | throw new IllegalArgumentException("Source and destination graphs " |
99 | + "must be different"); | |
100 | ||
101 | try | |
102 | { | |
103 | 728 | AbstractArchetypeVertex v = (AbstractArchetypeVertex) clone(); |
104 | 728 | v.initialize(); |
105 | 728 | v.importUserData(this); |
106 | 728 | return v; |
107 | } | |
108 | 0 | catch (CloneNotSupportedException cne) |
109 | { | |
110 | 0 | 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 | { | |
127 | 176985 | if (this == o) |
128 | 35 | return true; |
129 | 176950 | if (!(o instanceof ArchetypeVertex)) |
130 | 0 | return false; |
131 | 176950 | ArchetypeVertex v = (ArchetypeVertex)o; |
132 | 176950 | 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 | { | |
145 | 181031 | if (ag instanceof AbstractArchetypeGraph) |
146 | { | |
147 | 92914 | AbstractArchetypeGraph aag = (AbstractArchetypeGraph)ag; |
148 | 92914 | return aag.getVertexByID(this.getID()); |
149 | } | |
150 | else | |
151 | 88117 | return null; |
152 | } | |
153 | ||
154 | /** | |
155 | * @deprecated As of version 1.4, renamed to getEqualVertex(ag). | |
156 | */ | |
157 | public ArchetypeVertex getEquivalentVertex(ArchetypeGraph ag) | |
158 | { | |
159 | 0 | 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 | { | |
168 | 0 | for (Iterator iter = getEdges_internal().iterator(); iter.hasNext(); ) |
169 | { | |
170 | 0 | ArchetypeEdge ae = (ArchetypeEdge)iter.next(); |
171 | 0 | if (ae.isIncident(v)) |
172 | 0 | return ae; |
173 | } | |
174 | 0 | 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 | { | |
182 | 0 | Set edges = new HashSet(); |
183 | 0 | for (Iterator iter = getEdges_internal().iterator(); iter.hasNext(); ) |
184 | { | |
185 | 0 | ArchetypeEdge ae = (ArchetypeEdge)iter.next(); |
186 | 0 | if (ae.isIncident(v)) |
187 | 0 | edges.add(ae); |
188 | } | |
189 | 0 | 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. |
copyright © 2003, jcoverage ltd. all rights reserved. |