package sg.ncl;

import sg.ncl.testbed_interface.Team2;

import java.util.HashMap;

/**
 * Created by Te Ye
 */
public class TeamManager2 {

    private static TeamManager2 TEAM_MANAGER_SINGLETON = null;
    private HashMap<String, Team2> teamMap; /* teamId - Team */
    private HashMap<String, Team2> publicTeamMap;

    private TeamManager2() {
        teamMap = new HashMap<String, Team2>();
        publicTeamMap = new HashMap<String, Team2>();
    }

    public static TeamManager2 getInstance() {
        if (TEAM_MANAGER_SINGLETON == null) {
            TEAM_MANAGER_SINGLETON = new TeamManager2();
        }
        return TEAM_MANAGER_SINGLETON;
    }

    public HashMap<String, Team2> getTeamMap() {
        return teamMap;
    }

    public void setTeamMap(HashMap<String, Team2> teamMap) {
        this.teamMap = teamMap;
    }

    public void addTeamToTeamMap(Team2 team2) {
        teamMap.put(team2.getId(), team2);
    }

    public HashMap<String, Team2> getPublicTeamMap() {
        return publicTeamMap;
    }

    public void setPublicTeamMap(HashMap<String, Team2> publicTeamMap) {
        this.publicTeamMap = publicTeamMap;
    }

    public void addTeamToPublicTeamMap(Team2 team2) {
        publicTeamMap.put(team2.getId(), team2);
    }
}

@@ -48,16 +48,55 @@
 e.Team2;
+%0Aimport sg.ncl.testbed_interface.User2;
 %0A%0Aimport
@@ -106,23 +106,17 @@
 va.util.
-HashMap
+*
 ;%0A%0A/**%0A 
@@ -343,16 +343,110 @@
 TeamMap;
+%0A    private HashMap%3CString, List%3CTeam2%3E%3E userJoinRequestMap; /* userId, arraylists of team */
 %0A%0A    pr
@@ -494,37 +494,24 @@
 new HashMap%3C
-String, Team2
 %3E();%0A       
@@ -539,29 +539,62 @@
 HashMap%3C
-String, Team2
+%3E();%0A        userJoinRequestMap = new HashMap%3C
 %3E();%0A   
@@ -1406,10 +1406,1914 @@
 ;%0A    %7D%0A
+%0A    public HashMap%3CString, List%3CTeam2%3E%3E getUserJoinRequestMap() %7B%0A        return userJoinRequestMap;%0A    %7D%0A%0A    void setUserJoinRequestMap(HashMap%3CString, List%3CTeam2%3E%3E userJoinRequestMap) %7B%0A        this.userJoinRequestMap = userJoinRequestMap;%0A    %7D%0A%0A    public void addUserJoinRequestMap(String teamId, User2 requestUser) %7B%0A        if (userJoinRequestMap.containsKey(requestUser.getId())) %7B%0A            // ensure user is not already in the team or have submitted the application%0A            for (Map.Entry%3CString, List%3CTeam2%3E%3E entry : userJoinRequestMap.entrySet()) %7B%0A                String currUserId = entry.getKey();%0A                if (currUserId.equals(requestUser.getId())) %7B%0A                    List%3CTeam2%3E currJoinTeamList = entry.getValue();%0A                    for (ListIterator%3CTeam2%3E iter = currJoinTeamList.listIterator(); iter.hasNext();) %7B%0A                        Team2 currTeam = iter.next();%0A                        if (currTeam.getId().equals(teamId)) %7B%0A                            return;%0A                        %7D%0A                    %7D%0A                    Team2 one = teamMap.get(teamId);%0A                    // have existing join request but not for this team%0A                    currJoinTeamList.add(one);%0A                    // one.addUserToJoinRequestMap(userId, requestIssuer);%0A                    userJoinRequestMap.put(requestUser.getId(), currJoinTeamList);%0A                %7D%0A            %7D%0A        %7D else %7B%0A            // first time user make join request%0A            // add to user join team list%0A            // get team obj from teamName%0A            // put to map%0A            List%3CTeam2%3E myJoinRequestList = new ArrayList%3C%3E();%0A            Team2 one = teamMap.get(teamId);%0A            myJoinRequestList.add(one);%0A            userJoinRequestMap.put(requestUser.getId(), myJoinRequestList);%0A            // one.addUserToJoinRequestMap(userId, requestIssuer);%0A        %7D%0A    %7D%0A%0A
 %7D%0A

add a simple function to show users' join request