package chat;

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

public class TextGestTopics implements TopicsManager{

	protected Hashtable<String, Chatroom> Topics;	
	
	//________________________________________
	// Date : 07/11/11
	// Fonction: Retourne le topics avec le sujet correspondant
	//________________________________________
	public Hashtable<String, Chatroom> getTopics() {
		return Topics;
	}

	//________________________________________
	// Date : 07/11/11
	// Fonction: Création des topics
	//________________________________________
	public TextGestTopics() {
		Topics = new Hashtable<String, Chatroom>();
	}

	//________________________________________
	// Date : 07/11/11
	// Fonction: Création d'un topic
	//________________________________________
	@Override
	public String createTopic(String topic) {
		if(!Topics.containsKey(topic))
			Topics.put(topic, new TextChatRoom(topic));
		return null;
	}

	//________________________________________
	// Date : 07/11/11
	// Fonction: Retourner le chatroom correspondant
	//________________________________________
	@Override
	public Chatroom joinTopic(String topic) {
		return Topics.get(topic);
	}

	//________________________________________
	// Date : 07/11/11
	// Fonction: Lister l'ensemble des topics
	//________________________________________
	@Override
	public Vector<String> listTopics() {
		
		Vector<String> ret = new Vector<String>();
		Enumeration<String> e = Topics.keys();
		
		while(e.hasMoreElements()) {		
			ret.add(e.nextElement());
		}
		return ret;
	}

}
