From: Han Qi <shm...@gm...> - 2013-09-25 13:14:41
|
HI Tom, you are right about equals and hashcode. But that still does not explain why g.findedge() throw Nullpoiner execption and for edge in g.getIncidentEdges(v), g.edges.get(edge) returns null. And why change the type of Graph make it ok. Best Qi On Wed, Sep 25, 2013 at 2:57 PM, Tom Nelson <tho...@gm...>wrote: > My guess is that your Tweet class does not override equals and hashcode, > so the new ones you create are never 'equal' to the ones in your graph. You > would have the same error with any Java collection, not just the Jung > graphs. > > Tom Nelson > > > On Wed, Sep 25, 2013 at 8:41 AM, Han Qi <shm...@gm...> wrote: > >> Hi, Joshua, >> >> thanks for the quick reply. What I mean ist that: >> >> I find sometimes g.findEdge throw java.lang. >> NullPointerException. With >> I then look at the source code of findEdge, it seems thatI that for some >> edges it get from g.getIncidentEdges(v), edges.get(edge) returns null. >> And this happens when the graph type is UndirectedSparseMultigraph, if I >> change it to UndirectedSparseGraph everything goes fine but the programm >> becomes much slower. >> >> Here is the code I use: the graph is pretty big 512,262 notes. >> >> Graph<String, List<Tweet[]>> g = new >> UndirectedSparseMultigraph<String, List<Tweet[]>>(); >> >> // add vertexes >> Set<String> UIDs = twitterData2.getRawDataUIDMap().keySet(); >> for (String uid : UIDs) { >> g.addVertex(uid); >> } >> >> // add edges >> long count = 0; >> for (Tweet aTweet : twitterData2.getRawData()) { >> String thisAuthor = aTweet.getAuthorId(); >> >> Collection<Tweet> result = query(thisAuthor) >> for (Tweet tweet : result) { >> String thatAuthor = tweet.getAuthorId(); >> Tweet[] pair = new Tweet[] { aTweet, tweet }; >> Tweet[] pair1 = new Tweet[] { tweet, aTweet }; >> >> if (!thisAuthor.equals(thatAuthor)) { >> >> try { >> List<Tweet[]> anEdge; >> if ((anEdge = g.findEdge(thisAuthor, thatAuthor)) >> == null) { // if there is no links between the two, then add a new one >> anEdge = new ArrayList<Tweet[]>(); >> g.addEdge(anEdge , thisAuthor, >> thatAuthor); >> } >> >> if (!(anEdge.contains(pair) || >> anEdge.contains(pair1))) { >> anEdge.add(new Tweet[] { aTweet, tweet }); >> } >> } catch (Exception e) { >> >> // TODO: handle exception >> count++; >> // e.printStackTrace(); >> // if (!g.containsVertex(thisAuthor) || >> // !g.containsVertex(thatAuthor)) >> // return null; >> // for (List<Tweet[]> edge : >> // g.getIncidentEdges(thisAuthor)) >> // g.getEdges().contains(edge); >> // if (g.getOpposite(thisAuthor, >> // edge).equals(thatAuthor)) >> // System.out.println(edge.toString()); >> // throw e; >> >> } >> >> } >> } >> } >> >> >> >> On Tue, Sep 24, 2013 at 6:22 PM, Joshua O'Madadhain < >> jos...@gm...> wrote: >> >>> Your report is confusing. You start out talking about g.findEdge() and >>> then talk about the return collection you get from g.getIncidentEdges(). >>> Please post a self-contained snippet that has the problem you're >>> describing. >>> >>> >>> On Tue, Sep 24, 2013 at 4:05 AM, Han Qi <shm...@gm...> wrote: >>> >>>> Hallo guys, I am using JUNG in a project. I find sometimes g.findEdge >>>> throw java.lang.NullPointerException. >>>> I find that for some edges I get from g.getIncidentEdges(v), >>>> edges.get(edge) returns null. >>>> It is a bug? >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> October Webinars: Code for Performance >>>> Free Intel webinars can help you accelerate application performance. >>>> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the >>>> most from >>>> the latest Intel processors and coprocessors. See abstracts and >>>> register > >>>> >>>> http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk >>>> _______________________________________________ >>>> Jung-support mailing list >>>> Jun...@li... >>>> https://lists.sourceforge.net/lists/listinfo/jung-support >>>> >>>> >>> >>> >>> -- >>> jos...@gm.........sites.google.com/site/joshuaomadadhain/ >>> Joshua O'Madadhain: Information Scientist, Musician, >>> Philosopher-At-Tall >>> It's that moment of dawning comprehension that I live for. -- Bill >>> Watterson >>> My opinions are too rational and insightful to be those of any >>> organization. >>> >> >> >> >> ------------------------------------------------------------------------------ >> October Webinars: Code for Performance >> Free Intel webinars can help you accelerate application performance. >> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most >> from >> the latest Intel processors and coprocessors. See abstracts and register > >> >> http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk >> _______________________________________________ >> Jung-support mailing list >> Jun...@li... >> https://lists.sourceforge.net/lists/listinfo/jung-support >> >> > > > ------------------------------------------------------------------------------ > October Webinars: Code for Performance > Free Intel webinars can help you accelerate application performance. > Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most > from > the latest Intel processors and coprocessors. See abstracts and register > > http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk > _______________________________________________ > Jung-support mailing list > Jun...@li... > https://lists.sourceforge.net/lists/listinfo/jung-support > > |