package forum;
import java.util.*;
/**
* Represents all topics in the discussion forum.
*
* In a real system there would be a database containing the topics.
*
* @author Simon Brown
*/
public class Topics {
/** a collection of all topics in the system */
private static ArrayList topics = new ArrayList();
/**
* Populates the collection of all topics when the class is loaded.
*/
static {
Topic topic;
Response response;
User user1, user2;
user1 = Users.getUser("Simon");
user2 = Users.getUser("Sam");
topic = new Topic(0, user1, "How do I write a Java Servlet?", "How do I write a Java Servlet and which class do I need to extend?");
topic.add(new Response(user2, "You need to write a Java class that extends javax.servlet.http.HttpServlet, and implement the doGet or doPost methods."));
topic.add(new Response(user1, "What's the purpose of doGet and doPost?"));
topics.add(topic);
topic = new Topic(1, user1, "Front Controller pattern?", "How do I use it?");
topics.add(topic);
topic = new Topic(2, user1, "HTTP session timeout", "When does the session timeout?");
topics.add(topic);
}
/**
* Gets a collection of all topics in the system.
*
* @return a Collection of Topic instances
*/
public static Collection getTopics() {
return topics;
}
/**
* Looks up the Topic with the specified id.
*
* @param id the topic id
* @return the appropriate Topic instance
*/
public static Topic getTopic(int id) {
return (Topic)topics.get(id);
}
}