Methods Summary |
---|
private void | addDefaultItems()Creates sample news items and adds them to the list.
NewsItemBean item = new NewsItemBean();
item.setCategory("JSP");
item.setMsg("New O'Reilly JSP book released!");
item.setPostedBy("Hans Bergsten");
setNewsItem(item);
item = new NewsItemBean();
item.setCategory("Servlet");
item.setMsg("Servets and JSP is a great combination.");
item.setPostedBy("Hans Bergsten");
setNewsItem(item);
item = new NewsItemBean();
item.setCategory("EJB");
item.setMsg("JSP makes a great front-end for EJB.");
item.setPostedBy("Hans Bergsten");
setNewsItem(item);
|
public NewsItemBean[] | getNewsItems(java.lang.String[] categories)Returns an array of all items in the specified categories.
Vector matches = new Vector();
synchronized (newsItems) {
for (int i = 0; i < newsItems.size(); i++) {
NewsItemBean item = (NewsItemBean) newsItems.elementAt(i);
if (ArraySupport.contains(categories, item.getCategory())) {
matches.addElement(item);
}
}
}
NewsItemBean[] matchingItems = new NewsItemBean[matches.size()];
matches.copyInto(matchingItems);
return matchingItems;
|
public void | removeNewsItem(int id)Removes the new item with the specified id.
synchronized (newsItems) {
for (int i = 0; i < newsItems.size(); i++) {
NewsItemBean item = (NewsItemBean) newsItems.elementAt(i);
if (id == item.getId()) {
newsItems.removeElementAt(i);
break;
}
}
}
|
public void | setNewsItem(NewsItemBean newsItem)Adds a news item to the list.
synchronized (idSequence) {
newsItem.setId(idSequence[0]++);
}
newsItems.addElement(newsItem);
|