|
17 | 17 |
|
18 | 18 | import it.unimi.dsi.fastutil.ints.IntRBTreeSet; |
19 | 19 | import it.unimi.dsi.fastutil.ints.IntSortedSet; |
| 20 | +import java.util.function.Predicate; |
20 | 21 | import org.gephi.graph.api.DirectedSubgraph; |
21 | 22 | import org.gephi.graph.api.Edge; |
22 | 23 | import org.gephi.graph.api.Graph; |
@@ -54,6 +55,17 @@ public GraphViewImpl createView() { |
54 | 55 | return createView(true, true); |
55 | 56 | } |
56 | 57 |
|
| 58 | + public GraphViewImpl createView(Predicate<Node> nodeFilter, Predicate<Edge> edgeFilter) { |
| 59 | + graphStore.autoWriteLock(); |
| 60 | + try { |
| 61 | + GraphViewImpl graphView = new GraphViewImpl(graphStore, nodeFilter, edgeFilter); |
| 62 | + addView(graphView); |
| 63 | + return graphView; |
| 64 | + } finally { |
| 65 | + graphStore.autoWriteUnlock(); |
| 66 | + } |
| 67 | + } |
| 68 | + |
57 | 69 | public GraphViewImpl createView(boolean nodes, boolean edges) { |
58 | 70 | graphStore.autoWriteLock(); |
59 | 71 | try { |
@@ -232,58 +244,38 @@ public void destroyGraphObserver(GraphObserverImpl graphObserver) { |
232 | 244 | graphViewImpl.destroyGraphObserver(graphObserver); |
233 | 245 | } |
234 | 246 |
|
235 | | - protected void addNode(NodeImpl node) { |
236 | | - if (views.length > 0) { |
237 | | - for (GraphViewImpl view : views) { |
238 | | - if (view != null) { |
239 | | - view.ensureNodeVectorSize(node); |
240 | | - } |
241 | | - } |
242 | | - } |
243 | | - } |
244 | | - |
245 | 247 | protected void removeNode(NodeImpl node) { |
246 | | - if (views.length > 0) { |
247 | | - for (GraphViewImpl view : views) { |
248 | | - if (view != null) { |
249 | | - view.removeNode(node); |
250 | | - } |
| 248 | + for (GraphViewImpl view : views) { |
| 249 | + if (view != null) { |
| 250 | + view.removeNode(node); |
251 | 251 | } |
252 | 252 | } |
253 | 253 | } |
254 | 254 |
|
255 | 255 | protected void addEdge(EdgeImpl edge) { |
256 | | - if (views.length > 0) { |
257 | | - for (GraphViewImpl view : views) { |
258 | | - if (view != null) { |
259 | | - view.ensureEdgeVectorSize(edge); |
260 | | - |
261 | | - if (view.nodeView && !view.edgeView) { |
262 | | - view.addEdgeInNodeView(edge); |
263 | | - } |
| 256 | + for (GraphViewImpl view : views) { |
| 257 | + if (view != null) { |
| 258 | + if (view.nodeView && !view.edgeView) { |
| 259 | + view.addEdgeInNodeView(edge); |
264 | 260 | } |
265 | 261 | } |
266 | 262 | } |
267 | 263 | } |
268 | 264 |
|
269 | 265 | protected void setEdgeType(EdgeImpl edge, int oldType, boolean wasMutual) { |
270 | | - if (views.length > 0) { |
271 | | - for (GraphViewImpl view : views) { |
272 | | - if (view != null) { |
273 | | - if ((view.nodeView && !view.edgeView) || (view.edgeView && view.containsEdge(edge))) { |
274 | | - view.setEdgeType(edge, oldType, wasMutual); |
275 | | - } |
| 266 | + for (GraphViewImpl view : views) { |
| 267 | + if (view != null) { |
| 268 | + if ((view.nodeView && !view.edgeView) || (view.edgeView && view.containsEdge(edge))) { |
| 269 | + view.setEdgeType(edge, oldType, wasMutual); |
276 | 270 | } |
277 | 271 | } |
278 | 272 | } |
279 | 273 | } |
280 | 274 |
|
281 | 275 | protected void removeEdge(EdgeImpl edge) { |
282 | | - if (views.length > 0) { |
283 | | - for (GraphViewImpl view : views) { |
284 | | - if (view != null) { |
285 | | - view.removeEdge(edge); |
286 | | - } |
| 276 | + for (GraphViewImpl view : views) { |
| 277 | + if (view != null) { |
| 278 | + view.removeEdge(edge); |
287 | 279 | } |
288 | 280 | } |
289 | 281 | } |
|
0 commit comments