java - Removing RDF graph dead-ends using Jung -


i trying implement method removes dead-ends rdf graph

iterator<string> iter = rdfgraph.getvertices().iterator();       while(iter.hasnext()){         string x = iter.next();         if(rdfgraph.outdegree(x)==0){              iter.remove();         }      } 

whenever run java.lang.unsupportedoperationexception. how can fix code.

the iterator's remove() method optional. javadoc mentions when it's not supported, throw unsupportedoperationexception:

throws:

unsupportedoperationexception - if remove operation not supported iterator

based on discussion in adding node collection using jung2, i'd assume getvertices() returns unmodifiable collection, in case iterator wouldn't support remove(). note javadoc getvertices() says method returns view of vertices. doesn't adding or removing collection adds or removes vertices graph, or adding or removing vertices collection possible.

getvertices collection<v> getvertices()

returns view of vertices in graph. in general, obeys collection contract, , therefore makes no guarantees ordering of vertices within set.

instead of iter.remove(), makes more sense use rdfgraph.removevertex(x).

but, based on comment

i used rdfgraph.removevertex(x) got java.util.concurrentmodificationexception. idea on how bypass without using iterator?

it sounds either need go through vertices , create new collection of ones want remove, , remove them after you're done iterating through vertices. alternatively, create new collection of all vertices , remove them go through. e.g.,

new arraylist<>(rdfgraph.getvertices()).stream()   .filter(v -> rdfgraph.outdegree(x) == 0)   .foreach(rdfgraph::removevertex); 

the use of arraylist isn't important there; need new collection that's not connected original graph.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo