1 package net.sf.flock;
2
3 import java.net.URL;
4 import java.util.ArrayList;
5 import java.util.Date;
6 import java.util.Iterator;
7 import java.util.List;
8
9
10 /***
11 * @version $Revision: 1.5 $
12 * @author $Author: phraktle $
13 */
14 public class Feed implements FeedI {
15
16 private String title = "New feed";
17 private URL site;
18 private List items = new ArrayList();
19
20 /***
21 * @see net.sf.flock.FeedI#getSite()
22 */
23 public URL getSite() {
24 return site;
25 }
26
27 public void setSite(URL site) {
28 this.site = site;
29 }
30
31 /***
32 * @see net.sf.flock.FeedI#getItems()
33 */
34 public List getItems() {
35 return this.items;
36 }
37
38 public ItemI newItem(Date creationTime, String title, String description, URL link) {
39 Item item = new Item(this);
40 item.setCreationTime(creationTime);
41 item.setTitle(title);
42 item.setDescription(description);
43 item.setLink(link);
44 this.items.add( item );
45 return item;
46 }
47
48 protected boolean hasItem(ItemI article) {
49 return this.items.contains(article);
50 }
51
52 /***
53 * @see net.sf.flock.FeedI#getTitle()
54 */
55 public String getTitle() {
56 return this.title;
57 }
58
59 public void setTitle(String title) {
60 if (title==null) {
61 throw new IllegalArgumentException("Title cannot be null");
62 }
63 this.title = title;
64 }
65
66 /***
67 * @see net.sf.flock.FeedI#merge(FeedI)
68 */
69 public List merge(FeedI feed) {
70 this.setTitle( feed.getTitle() );
71 this.setSite( feed.getSite() );
72
73 List newItems = new ArrayList();
74 for (Iterator i=feed.getItems().iterator(); i.hasNext(); ) {
75 Item a = (Item)i.next();
76 if (!this.hasItem(a)) {
77 newItems.add(
78 this.newItem(
79 a.getCreationTime(),
80 a.getTitle(),
81 a.getDescription(),
82 a.getLink()
83 )
84 );
85 }
86 }
87
88 return newItems;
89 }
90
91 }
This page was automatically generated by Maven