so,
I declare private List<Team> _data = new ArrayList<Team>();// this list has all Team in the Leagueprivate Map<Matches,MatchesResult> _matches = new HashMap<Matches,MatchesResult>(); // it has all Matches among Teams also the Matches result

There is a lot of stuff missing from what you posted: it's hard to say what a.get() is doing without knowing what a LeagueGames is.

I am guessing that get() obtains what it returns from a map. In that case you might get a null because "new Matches(t3,t4)" is not equal to any of the keys within the map. See get() in the Map API docs.

03-05-2011, 05:44 AM

pbrockway2

To be more pointed about it, get() involves comparing keys using their equals() method: does your Matches class override equals()? Because it should.

But when I print out the map, "new Matches(t3,t4)" is already there in the map

03-05-2011, 06:04 AM

pbrockway2

I have no doubt that there is some match between India and Italy as a key in the map. But how is the _matches map supposed to know that "new Matches(t3,t4)" match between India and Italy is equal() to the match it has as a key?

So, I have to override the equal() in all class
Team
Matches
MatchesResult

03-05-2011, 06:31 AM

pbrockway2

Yes, if Matches is going to function as a key in a map which depends only on its two team attributes then it will need an equals() that expresses that fact. (I don't know about the other classes; it depends on how they're used.)