Skip to content

Commit ad1252e

Browse files
committed
Remove some superfluous checks
1 parent 1bc167f commit ad1252e

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/main/java/org/gephi/graph/impl/GraphViewStore.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/test/java/org/gephi/graph/impl/GraphViewStoreTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ public void testDestroy() {
7171
Assert.assertTrue(view.isDestroyed());
7272
}
7373

74+
@Test(expectedExceptions = IllegalArgumentException.class)
75+
public void testDestroyMainView() {
76+
GraphStore graphStore = GraphGenerator.generateSmallGraphStore();
77+
GraphViewStore store = graphStore.viewStore;
78+
79+
store.destroyView(graphStore.mainGraphView);
80+
}
81+
7482
@Test(expectedExceptions = IllegalArgumentException.class)
7583
public void testDestroyTwice() {
7684
GraphStore graphStore = GraphGenerator.generateSmallGraphStore();
@@ -199,7 +207,7 @@ public void testGetUndirectedGraphNull() {
199207
store.getUndirectedGraph(null);
200208
}
201209

202-
@Test(expectedExceptions = ClassCastException.class)
210+
@Test(expectedExceptions = IllegalArgumentException.class)
203211
public void testGetViewAnonymousClass() {
204212
GraphStore graphStore = GraphGenerator.generateSmallGraphStore();
205213
GraphViewStore store = graphStore.viewStore;
@@ -212,7 +220,7 @@ public GraphModel getGraphModel() {
212220

213221
@Override
214222
public boolean isMainView() {
215-
throw new UnsupportedOperationException("Not supported yet.");
223+
return false;
216224
}
217225

218226
@Override

0 commit comments

Comments
 (0)