@@ -82,6 +82,7 @@ public GraphViewImpl createView(GraphView view, boolean nodes, boolean edges) {
8282 }
8383 } else {
8484 checkNonNullViewObject (view );
85+ checkGraphViewObject (view );
8586 checkViewExist ((GraphViewImpl ) view );
8687
8788 graphStore .autoWriteLock ();
@@ -96,9 +97,13 @@ public GraphViewImpl createView(GraphView view, boolean nodes, boolean edges) {
9697 }
9798
9899 public void destroyView (GraphView view ) {
100+ if (view .isMainView ()) {
101+ throw new IllegalArgumentException ("Can't delete the main view" );
102+ }
99103 graphStore .autoWriteLock ();
100104 try {
101105 checkNonNullViewObject (view );
106+ checkGraphViewObject (view );
102107
103108 TimeIndexStore nodeTimeStore = graphStore .timeStore .nodeIndexStore ;
104109 if (nodeTimeStore != null ) {
@@ -160,6 +165,7 @@ public int size() {
160165
161166 public Subgraph getGraph (GraphView view ) {
162167 checkNonNullViewObject (view );
168+ checkGraphViewObject (view );
163169
164170 if (graphStore .isUndirected ()) {
165171 if (view .isMainView ()) {
@@ -176,6 +182,7 @@ public Subgraph getGraph(GraphView view) {
176182
177183 public DirectedSubgraph getDirectedGraph (GraphView view ) {
178184 checkNonNullViewObject (view );
185+ checkGraphViewObject (view );
179186
180187 if (view .isMainView ()) {
181188 return graphStore ;
@@ -187,6 +194,7 @@ public DirectedSubgraph getDirectedGraph(GraphView view) {
187194
188195 public UndirectedSubgraph getUndirectedGraph (GraphView view ) {
189196 checkNonNullViewObject (view );
197+ checkGraphViewObject (view );
190198
191199 if (view .isMainView ()) {
192200 return graphStore .undirectedDecorator ;
@@ -358,14 +366,15 @@ public boolean deepEquals(GraphViewStore obj) {
358366 return true ;
359367 }
360368
361- protected void checkNonNullViewObject (final Object o ) {
369+ protected void checkNonNullViewObject (final GraphView o ) {
362370 if (o == null ) {
363371 throw new NullPointerException ();
364372 }
365- if (o != graphStore .mainGraphView ) {
366- if (!(o instanceof GraphViewImpl )) {
367- throw new ClassCastException ("View must be a GraphViewImpl object" );
368- }
373+ }
374+
375+ protected void checkGraphViewObject (final GraphView o ) {
376+ if (!o .isMainView () && !(o instanceof GraphViewImpl )) {
377+ throw new IllegalArgumentException ("The view is not from this implementation" );
369378 }
370379 }
371380
0 commit comments