package ca.carleton.gcrc.atlas.module.impl;

import java.util.List;
import java.util.Vector;

import ca.carleton.gcrc.atlas.module.Topic;
import ca.carleton.gcrc.atlas.module.TopicContainer;

public class TopicContainerImpl extends IdentifiableImpl implements TopicContainer {
	private List<TopicImpl> topics = new Vector<TopicImpl>();

	public List<Topic> getTopics() {
		List<Topic> result = new Vector<Topic>();
		result.addAll(topics);
		return result;
	}
	
	public Topic addTopic() {
		TopicImpl topic = new TopicImpl();
		topic.setContainer(this);
		topics.add(topic);
		return topic;
	}

	public void removeTopic(Topic topic) throws Exception {
		if( true == topics.contains(topic) ) {
			if( topic instanceof TopicImpl ) {
				TopicImpl topicImpl = (TopicImpl)topic;
				topics.remove(topicImpl);
				topicImpl.setContainer(null);
			} else {
				throw new Exception("Unexpected class for topic found: "+topic.getClass().getName());
			}
			return;
		}

		throw new Exception("Unable to remove topic");
	}
	
}
