KickJava   Java API By Example, From Geeks To Geeks.

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


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  * UnmodifiableGraph.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: UnmodifiableGraph.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  * An unmodifiable view of the backing graph specified in the constructor. This
54  * graph allows modules to provide users with "read-only" access to internal
55  * graphs. Query operations on this graph "read through" to the backing graph,
56  * and attempts to modify this graph result in an <code>
57  * UnsupportedOperationException</code>.
58  *
59  * <p>This graph does <i>not</i> pass the hashCode and equals operations through
60  * to the backing graph, but relies on <tt>Object</tt>'s <tt>equals</tt> and
61  * <tt>hashCode</tt> methods. This graph will be serializable if the backing
62  * graph is serializable.</p>
63  *
64  * @author Barak Naveh
65  * @since Jul 24, 2003
66  */

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

74     private static final long serialVersionUID = 3544957670722713913L;
75     private static final String JavaDoc UNMODIFIABLE = "this graph is unmodifiable";
76
77     //~ Constructors ----------------------------------------------------------
78

79     /**
80      * Creates a new unmodifiable graph based on the specified backing graph.
81      *
82      * @param g the backing graph on which an unmodifiable graph is to be
83      * created.
84      */

85     public UnmodifiableGraph(Graph<V, E> g)
86     {
87         super(g);
88     }
89
90     //~ Methods ---------------------------------------------------------------
91

92     /**
93      * @see Graph#addEdge(Object, Object)
94      */

95     public E addEdge(V sourceVertex, V targetVertex)
96     {
97         throw new UnsupportedOperationException JavaDoc(UNMODIFIABLE);
98     }
99
100     /**
101      * @see Graph#addEdge(Object, Object, Object)
102      */

103     public boolean addEdge(V sourceVertex, V targetVertex, E e)
104     {
105         throw new UnsupportedOperationException JavaDoc(UNMODIFIABLE);
106     }
107
108     /**
109      * @see Graph#addVertex(Object)
110      */

111     public boolean addVertex(V v)
112     {
113         throw new UnsupportedOperationException JavaDoc(UNMODIFIABLE);
114     }
115
116     /**
117      * @see Graph#removeAllEdges(Collection)
118      */

119     public boolean removeAllEdges(Collection<? extends E> edges)
120     {
121         throw new UnsupportedOperationException JavaDoc(UNMODIFIABLE);
122     }
123
124     /**
125      * @see Graph#removeAllEdges(Object, Object)
126      */

127     public Set<E> removeAllEdges(V sourceVertex, V targetVertex)
128     {
129         throw new UnsupportedOperationException JavaDoc(UNMODIFIABLE);
130     }
131
132     /**
133      * @see Graph#removeAllVertices(Collection)
134      */

135     public boolean removeAllVertices(Collection<? extends V> vertices)
136     {
137         throw new UnsupportedOperationException JavaDoc(UNMODIFIABLE);
138     }
139
140     /**
141      * @see Graph#removeEdge(Object)
142      */

143     public boolean removeEdge(E e)
144     {
145         throw new UnsupportedOperationException JavaDoc(UNMODIFIABLE);
146     }
147
148     /**
149      * @see Graph#removeEdge(Object, Object)
150      */

151     public E removeEdge(V sourceVertex, V targetVertex)
152     {
153         throw new UnsupportedOperationException JavaDoc(UNMODIFIABLE);
154     }
155
156     /**
157      * @see Graph#removeVertex(Object)
158      */

159     public boolean removeVertex(V v)
160     {
161         throw new UnsupportedOperationException JavaDoc(UNMODIFIABLE);
162     }
163 }
164
Popular Tags