Line | Hits | Source |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2003, the JUNG Project and the Regents of the University | |
3 | * of California | |
4 | * All rights reserved. | |
5 | * | |
6 | * This software is open-source under the BSD license; see either | |
7 | * "license.txt" or | |
8 | * http://jung.sourceforge.net/license.txt for a description. | |
9 | */ | |
10 | /* | |
11 | * Created on Dec 11, 2003 | |
12 | */ | |
13 | package edu.uci.ics.jung.graph.impl; | |
14 | ||
15 | import java.util.HashSet; | |
16 | import java.util.Iterator; | |
17 | import java.util.Set; | |
18 | ||
19 | import edu.uci.ics.jung.graph.*; | |
20 | ||
21 | /** | |
22 | * A Hypervertex has zero or more hyperEdges attached to it, and | |
23 | * is a member of a Hypergraph. | |
24 | * | |
25 | * @author danyelf | |
26 | */ | |
27 | public class HypervertexBPG extends AbstractHyperUnitBPG implements Hypervertex { | |
28 | ||
29 | 21 | public HypervertexBPG() { |
30 | 21 | } |
31 | ||
32 | HypervertexBPG( BipartiteVertex bpv, HypergraphBPG hypergraphBPG ) { | |
33 | 3 | super( bpv, hypergraphBPG ); |
34 | 3 | } |
35 | ||
36 | public Set getIncidentElements() | |
37 | { | |
38 | 0 | return getIncidentEdges(); |
39 | } | |
40 | ||
41 | /** | |
42 | * @see edu.uci.ics.jung.graph.ArchetypeVertex#getNeighbors() | |
43 | */ | |
44 | public Set getNeighbors() { | |
45 | // ask the underlying vertex for the two-step-away neighbors | |
46 | // and then get the corresponding HyperVertex | |
47 | 13 | Set oldNeighbors = vertex.getNeighbors(); |
48 | ||
49 | 13 | Set realNeighbors = new HashSet(); |
50 | 13 | for (Iterator iter = oldNeighbors.iterator(); iter.hasNext();) { |
51 | 14 | Vertex v = (Vertex) iter.next(); |
52 | 14 | realNeighbors.addAll( v.getNeighbors() ); |
53 | } | |
54 | ||
55 | 13 | realNeighbors.remove( vertex ); |
56 | 13 | return graph.translateUnderlyingVertices( realNeighbors ); |
57 | } | |
58 | ||
59 | ||
60 | /** | |
61 | * @see edu.uci.ics.jung.graph.ArchetypeVertex#getIncidentEdges() | |
62 | */ | |
63 | public Set getIncidentEdges() { | |
64 | 6 | return graph.translateUnderlyingEdges( vertex.getNeighbors() ); |
65 | } | |
66 | ||
67 | /** | |
68 | * Returns the number of edges adjacent to this vertex | |
69 | * @see edu.uci.ics.jung.graph.ArchetypeVertex#degree() | |
70 | */ | |
71 | public int degree() { | |
72 | 6 | return vertex.degree(); |
73 | } | |
74 | ||
75 | ||
76 | /** | |
77 | * @see edu.uci.ics.jung.graph.ArchetypeVertex#getEqualVertex(edu.uci.ics.jung.graph.ArchetypeGraph) | |
78 | */ | |
79 | public ArchetypeVertex getEqualVertex(ArchetypeGraph g) { | |
80 | 3 | HypergraphBPG bpg = (HypergraphBPG) g; |
81 | // check if that graph's underlying vertex is the same as this one's. | |
82 | 3 | return bpg.getVertexCorrespondingTo( underlying_vertex() ); |
83 | } | |
84 | ||
85 | /** | |
86 | * @deprecated As of version 1.4, renamed to getEqualVertex(g). | |
87 | */ | |
88 | public ArchetypeVertex getEquivalentVertex(ArchetypeGraph g) | |
89 | { | |
90 | 0 | return getEqualVertex(g); |
91 | } | |
92 | ||
93 | /** | |
94 | * Not a very efficient implementation | |
95 | * @see edu.uci.ics.jung.graph.ArchetypeVertex#isNeighborOf(edu.uci.ics.jung.graph.ArchetypeVertex) | |
96 | */ | |
97 | public boolean isNeighborOf(ArchetypeVertex v) { | |
98 | 4 | return getNeighbors().contains(v); |
99 | } | |
100 | ||
101 | ||
102 | /** | |
103 | * @see edu.uci.ics.jung.graph.ArchetypeVertex#isIncident(edu.uci.ics.jung.graph.ArchetypeEdge) | |
104 | */ | |
105 | public boolean isIncident(ArchetypeEdge e) { | |
106 | 3 | HyperedgeBPG hepbg = (HyperedgeBPG) e; |
107 | 3 | return underlying_vertex().isNeighborOf(hepbg.underlying_vertex()); |
108 | } | |
109 | ||
110 | /** | |
111 | * @see edu.uci.ics.jung.graph.ArchetypeVertex#findEdge(ArchetypeVertex) | |
112 | */ | |
113 | public ArchetypeEdge findEdge(ArchetypeVertex v) | |
114 | { | |
115 | 0 | Set incident_edges = getIncidentEdges(); |
116 | ||
117 | 0 | for (Iterator iter = incident_edges.iterator(); iter.hasNext(); ) |
118 | { | |
119 | 0 | ArchetypeEdge e = (ArchetypeEdge)iter.next(); |
120 | 0 | if (e.isIncident(v)) |
121 | 0 | return e; |
122 | } | |
123 | 0 | return null; |
124 | } | |
125 | ||
126 | /** | |
127 | * @see edu.uci.ics.jung.graph.ArchetypeVertex#findEdgeSet(ArchetypeVertex) | |
128 | */ | |
129 | public Set findEdgeSet(ArchetypeVertex v) | |
130 | { | |
131 | 0 | Set incident_edges = getIncidentEdges(); |
132 | ||
133 | 0 | Set connecting_edges = new HashSet(); |
134 | 0 | for (Iterator iter = incident_edges.iterator(); iter.hasNext(); ) |
135 | { | |
136 | 0 | ArchetypeEdge e = (ArchetypeEdge)iter.next(); |
137 | 0 | if (e.isIncident(v)) |
138 | 0 | connecting_edges.add(e); |
139 | } | |
140 | 0 | return connecting_edges; |
141 | } | |
142 | ||
143 | /** | |
144 | * Not a very efficient implemenation: for each edge, counts the | |
145 | * neighbors. | |
146 | * @see edu.uci.ics.jung.graph.ArchetypeVertex#numNeighbors() | |
147 | */ | |
148 | public int numNeighbors() { | |
149 | 6 | return getNeighbors().size(); |
150 | } | |
151 | ||
152 | ||
153 | /** | |
154 | * @see edu.uci.ics.jung.graph.ArchetypeVertex#copy(edu.uci.ics.jung.graph.ArchetypeGraph) | |
155 | */ | |
156 | public ArchetypeVertex copy(ArchetypeGraph g) { | |
157 | 0 | HypergraphBPG hg = (HypergraphBPG) g; |
158 | 0 | HypervertexBPG hv = new HypervertexBPG(); |
159 | 0 | hg.addVertex( hv ); |
160 | 0 | hv.importUserData(this); |
161 | 0 | return hv; |
162 | } | |
163 | ||
164 | public boolean connectEdge(Hyperedge e) | |
165 | { | |
166 | 0 | return e.connectVertex(this); |
167 | } | |
168 | ||
169 | public boolean disconnectEdge(Hyperedge e) | |
170 | { | |
171 | 0 | return e.disconnectVertex(this); |
172 | } | |
173 | ||
174 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |