I need your help guys "HashMap"
Hi,
I'm working in course project to Manage League Games
I'm trying to write a code to generate Matches between Team.
so,
I declare
private List<Team> _data = new ArrayList<Team>(); // this list has all Team in the League
private Map<Matches,MatchesResult> _matches = new HashMap<Matches,MatchesResult>(); // it has all Matches among Teams also the Matches result
Class Matches has attributes Team team1, team2;
Class MatchesResult has attributes Matches match; int team1Result, team2Result;
So I write the following code to generate the Matches;
public void generateMatches(){
Team [] team = new Team[_data.size()];
int k=0;
Iterator t = _data.iterator();
// The following loop used to copy all Team into team array
while (t.hasNext()) {
team[k]= (Team) t.next();
k++;
}
// This code is to generate Matches among Teams
for(int i=0;i<team.length;i++){
for(int j =i+1;j<team.length;j++){
Matches m1 = new Matches(team[i],team[j]);
MatchesResult m2 = new MatchesResult(m1);
_matches.put(m1,m2);
}
}
}
I run the program with the following code;
Team t1 = new Soccer("Brazil");
Team t2 = new Soccer("France");
Team t3 = new Soccer("India");
Team t4 = new Soccer("Italy");
LeagueGames a = new LeagueGames();
System.out.println(a.size());
a.addTeam(t1);
a.addTeam(t2);
a.addTeam(t3);
a.addTeam(t4);
System.out.println(a.size());
a.generateMatches();
System.out.println(a.toString());
System.out.println(a.get(new Matches(t3,t4))); // Here suppose I get the Match between India and Italy BUT I got NULL
Here is the Output
0
4
Leagua Matches:
Brazil vs France : 0 - 0
France vs Italy : 0 - 0
France vs India : 0 - 0
Brazil vs Italy : 0 - 0
India vs Italy : 0 - 0
Brazil vs India : 0 - 0
null
I have no idea why I got NULL.
Could you help, please?
Thank's