package chat;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

/**
 * \class TextTopicsManager
 * Provides an implementation of the topics manager model.
 */
public class TextTopicsManager implements TopicsManager {
	private Hashtable<String, Chatroom> chatrooms = new Hashtable<String, Chatroom>();
	
	/**
	 * constructor
	 */
	public TextTopicsManager() {
		super();
	}
	
	public void createTopic(String topic) throws ChatroomExistsException {
		if (!chatrooms.containsKey(topic)) {
			chatrooms.put(topic, new TextChatroom(topic));
		} else {
			throw new ChatroomExistsException();
		}
	}

	public Chatroom joinTopic(String topic) {
		return chatrooms.get(topic);
	}

	public Vector<String> listTopics() {
		Vector<String> vect = new Vector<String>();
		System.out.println("The openned topics are : ");
		for (Enumeration<String> e = chatrooms.keys() ; e.hasMoreElements() ;) {
			vect.addElement(e.nextElement());
			System.out.println(vect.lastElement());
		}
		return vect;
	}
}
