KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgrapht > graph > GraphDelegator


1 /* ==========================================
2  * JGraphT : a free Java graph-theory library
3  * ==========================================
4  *
5  * Project Info: http://jgrapht.sourceforge.net/
6  * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
7  *
8  * (C) Copyright 2003-2006, by Barak Naveh and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this library; if not, write to the Free Software Foundation,
22  * Inc.,
23  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
24  */

25 /* -------------------
26  * GraphDelegator.java
27  * -------------------
28  * (C) Copyright 2003-2006, by Barak Naveh and Contributors.
29  *
30  * Original Author: Barak Naveh
31  * Contributor(s): Christian Hammer
32  *
33  * $Id: GraphDelegator.java 504 2006-07-03 02:37:26Z perfecthash $
34  *
35  * Changes
36  * -------
37  * 24-Jul-2003 : Initial revision (BN);
38  * 11-Mar-2004 : Made generic (CH);
39  * 07-May-2006 : Changed from List<Edge> to Set<Edge> (JVS);
40  * 28-May-2006 : Moved connectivity info from edge to graph (JVS);
41  *
42  */

43 package org.jgrapht.graph;
44
45 import java.io.*;
46
47 import java.util.*;
48
49 import org.jgrapht.*;
50
51
52 /**
53  * A graph backed by the the graph specified at the constructor, which delegates
54  * all its methods to the backing graph. Operations on this graph "pass through"
55  * to the to the backing graph. Any modification made to this graph or the
56  * backing graph is reflected by the other.
57  *
58  * <p>This graph does <i>not</i> pass the hashCode and equals operations through
59  * to the backing graph, but relies on <tt>Object</tt>'s <tt>equals</tt> and
60  * <tt>hashCode</tt> methods.</p>
61  *
62  * <p>This class is mostly used as a base for extending subclasses.</p>
63  *
64  * @author Barak Naveh
65  * @since Jul 20, 2003
66  */

67 public class GraphDelegator<V, E>
68     extends AbstractGraph<V, E>
69     implements Graph<V, E>, Serializable
70 {
71
72     //~ Static fields/initializers --------------------------------------------
73

74     private static final long serialVersionUID = 3257005445226181425L;
75
76     //~ Instance fields -------------------------------------------------------
77

78     /**
79      * The graph to which operations are delegated.
80      */

81     private Graph<V, E> delegate;
82
83     //~ Constructors ----------------------------------------------------------
84

85     /**
86      * Constructor for GraphDelegator.
87      *
88      * @param g the backing graph (the delegate).
89      *
90      * @throws IllegalArgumentException iff <code>g==null</code>
91      */

92     public GraphDelegator(Graph<V, E> g)
93     {
94         super();
95
96         if (g == null) {
97             throw new IllegalArgumentException JavaDoc("g must not be null.");
98         }
99
100         delegate = g;
101     }
102
103     //~ Methods ---------------------------------------------------------------
104

105     /**
106      * @see Graph#getAllEdges(Object, Object)
107      */

108     public Set<E> getAllEdges(V sourceVertex, V targetVertex)
109     {
110         return delegate.getAllEdges(sourceVertex, targetVertex);
111     }
112
113     /**
114      * @see Graph#getEdge(Object, Object)
115      */

116     public E getEdge(V sourceVertex, V targetVertex)
117     {
118         return delegate.getEdge(sourceVertex, targetVertex);
119     }
120
121     /**
122      * @see Graph#getEdgeFactory()
123      */

124     public EdgeFactory<V, E> getEdgeFactory()
125     {
126         return delegate.getEdgeFactory();
127     }
128
129     /**
130      * @see Graph#addEdge(Object, Object)
131      */

132     public E addEdge(V sourceVertex, V targetVertex)
133     {
134         return delegate.addEdge(sourceVertex, targetVertex);
135     }
136
137     /**
138      * @see Graph#addEdge(Object, Object, Object)
139      */

140     public boolean addEdge(V sourceVertex, V targetVertex, E e)
141     {
142         return delegate.addEdge(sourceVertex, targetVertex, e);
143     }
144
145     /**
146      * @see Graph#addVertex(Object)
147      */

148     public boolean addVertex(V v)
149     {
150         return delegate.addVertex(v);
151     }
152
153     /**
154      * @see Graph#containsEdge(Object)
155      */

156     public boolean containsEdge(E e)
157     {
158         return delegate.containsEdge(e);
159     }
160
161     /**
162      * @see Graph#containsVertex(Object)
163      */

164     public boolean containsVertex(V v)
165     {
166         return delegate.containsVertex(v);
167     }
168
169     /**
170      * @see UndirectedGraph#degreeOf(Object)
171      */

172     public int degreeOf(V vertex)
173     {
174         return ((UndirectedGraph<V, E>) delegate).degreeOf(vertex);
175     }
176
177     /**
178      * @see Graph#edgeSet()
179      */

180     public Set<E> edgeSet()
181     {
182         return delegate.edgeSet();
183     }
184
185     /**
186      * @see Graph#edgesOf(Object)
187      */

188     public Set<E> edgesOf(V vertex)
189     {
190         return delegate.edgesOf(vertex);
191     }
192
193     /**
194      * @see DirectedGraph#inDegreeOf(Object)
195      */

196     public int inDegreeOf(V vertex)
197     {
198         return ((DirectedGraph<V, ? extends E>) delegate).inDegreeOf(vertex);
199     }
200
201     /**
202      * @see DirectedGraph#incomingEdgesOf(Object)
203      */

204     public Set<E> incomingEdgesOf(V vertex)
205     {
206         return ((DirectedGraph<V, E>) delegate).incomingEdgesOf(vertex);
207     }
208
209     /**
210      * @see DirectedGraph#outDegreeOf(Object)
211      */

212     public int outDegreeOf(V vertex)
213     {
214         return ((DirectedGraph<V, ? extends E>) delegate).outDegreeOf(vertex);
215     }
216
217     /**
218      * @see DirectedGraph#outgoingEdgesOf(Object)
219      */

220     public Set<E> outgoingEdgesOf(V vertex)
221     {
222         return ((DirectedGraph<V, E>) delegate).outgoingEdgesOf(vertex);
223     }
224
225     /**
226      * @see Graph#removeEdge(Object)
227      */

228     public boolean removeEdge(E e)
229     {
230         return delegate.removeEdge(e);
231     }
232
233     /**
234      * @see Graph#removeEdge(Object, Object)
235      */

236     public E removeEdge(V sourceVertex, V targetVertex)
237     {
238         return delegate.removeEdge(sourceVertex, targetVertex);
239     }
240
241     /**
242      * @see Graph#removeVertex(Object)
243      */

244     public boolean removeVertex(V v)
245     {
246         return delegate.removeVertex(v);
247     }
248
249     /**
250      * @see java.lang.Object#toString()
251      */

252     public String JavaDoc toString()
253     {
254         return delegate.toString();
255     }
256
257     /**
258      * @see Graph#vertexSet()
259      */

260     public Set<V> vertexSet()
261     {
262         return delegate.vertexSet();
263     }
264
265     /**
266      * @see Graph#getEdgeSource(Object)
267      */

268     public V getEdgeSource(E e)
269     {
270         return delegate.getEdgeSource(e);
271     }
272
273     /**
274      * @see Graph#getEdgeTarget(Object)
275      */

276     public V getEdgeTarget(E e)
277     {
278         return delegate.getEdgeTarget(e);
279     }
280
281     /**
282      * @see Graph#getEdgeWeight(Object)
283      */

284     public double getEdgeWeight(E e)
285     {
286         return delegate.getEdgeWeight(e);
287     }
288
289     /**
290      * @see WeightedGraph#setEdgeWeight(Object, double)
291      */

292     public void setEdgeWeight(E e, double weight)
293     {
294         ((WeightedGraph<V, E>) delegate).setEdgeWeight(e, weight);
295     }
296 }
297
Popular Tags