Methods Summary |
---|
private void | addDefaultItems()Creates sample news items and adds them to the list.
NewsItemBean item = new NewsItemBean();
item.setCategory("JSF");
item.setMsg("O'Reilly's JSF book available now!");
item.setPostedBy("Hans Bergsten");
setNewsItem(item);
item = new NewsItemBean();
item.setCategory("JSP");
item.setMsg("3rd edition of O'Reilly JSP book released!");
item.setPostedBy("Hans Bergsten");
setNewsItem(item);
item = new NewsItemBean();
item.setCategory("Servlet");
item.setMsg("Servets and JSP: a powerful duo.");
item.setPostedBy("Hans Bergsten");
setNewsItem(item);
|
public NewsItemBean[] | getNewsItems()Returns an array of all items.
NewsItemBean[] a = null;
synchronized (newsItems) {
a = (NewsItemBean[])
newsItems.toArray(new NewsItemBean[newsItems.size()]);
}
return a;
|
public void | removeNewsItem(int id)Removes the news item with the specified id.
synchronized (newsItems) {
for (int i = 0; i < newsItems.size(); i++) {
NewsItemBean item = (NewsItemBean) newsItems.get(i);
if (id == item.getId()) {
newsItems.remove(i);
break;
}
}
}
|
public void | setNewsItem(NewsItemBean newsItem)Adds a news item to the list.
synchronized (idSequence) {
newsItem.setId(idSequence[0]++);
}
synchronized (newsItems) {
newsItems.add(newsItem);
}
|