package org.server;

import java.io.PrintWriter;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 
 * Universally accessible contacts list (safe to edit from any thread of execution)
 *
 */
public class Contacts {
    
    private static Contacts instance = null;
    
    // map user names to their client sockets
    private ConcurrentHashMap<String, PrintWriter> userList = new ConcurrentHashMap<String, PrintWriter>();
    
    protected Contacts() {
        // Don't allow instantiation. Do nothing here.
    }
       
    // Use this to get an instance of this contacts object.
    public static Contacts getInstance() {
        if(instance == null) { 
            instance = new Contacts();
        }
        return instance;
    }
    
    // determine whether a certain contact name is currently logged on
    public Boolean hasContact(String name) {
        return userList.containsKey(name);
    }
    
    // return true if successfully added name, false otherwise
    public Boolean addContact(String name, PrintWriter pw) {
        if(hasContact(name)) {
            // cannot add duplicate
            return false;
        }
        userList.put(name, pw);
        return true;
    }
    
    // get the output stream
    public PrintWriter getContact(String name) throws Exception {
        if(! hasContact(name)) {
            // cannot get that contact
            throw new Exception();
        }
        return userList.get(name);
    }
    
    // remove a contact
    public void removeContact(String name) {
        userList.remove(name);
    }
}

@@ -42,16 +42,95 @@
 Writer;%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Map.Entry;%0A
 import j
@@ -1647,10 +1647,566 @@
 ;%0A    %7D%0A
+    %0A  //get the print writer list%0A    public List%3CPrintWriter%3E getWriterList() throws Exception%7B%0A    %09List%3CPrintWriter%3E users = new ArrayList%3CPrintWriter%3E();%0A    %09for (Entry%3CString, PrintWriter%3E entry : userList.entrySet()) %7B%0A%09%09%09users.add(entry.getValue());%0A%09%09%7D%0A    %09return users;%0A    %7D%0A    %0A    //get the user name list%0A    public List%3CString%3E getUserList() throws Exception%7B%0A    %09List%3CString%3E users = new ArrayList%3CString%3E();%0A    %09for (Entry%3CString, PrintWriter%3E entry : userList.entrySet()) %7B%0A%09%09%09users.add(entry.getKey());%0A%09%09%7D%0A    %09return users;%0A    %7D%0A
 %7D%0A

Update Contacts.java