model
Class Feed

java.lang.Object
  extended by model.Feed

public class Feed
extends java.lang.Object

The Feed class represents an RSS feed. A Feed itself has a title, description, url, and a date that it was last updated. Under some circumstances, a Feed is also a collection of Articles: the knowsChildren boolean determines whether this is the case. A feed created by a parser, or in general added to under any circumstances, contains some Articles; otherwise, a feed does not contain articles, and if you want a feed's articles, you should ask a database.

Author:
pgroudas

Field Summary
private  java.util.List<Article> articles
           
private  java.lang.String description
           
private  int id
           
private  boolean knowsChildren
           
private  java.util.Date lastUpdatedByFeed
           
private  java.util.Date lastUpdatedByUser
           
private  int parentid
           
private  java.util.Date publishedDate
           
private  java.lang.String title
           
private  int updateInterval
           
private  java.lang.String url
           
 
Constructor Summary
Feed(int id, int parentid, java.lang.String title, java.lang.String description, java.lang.String url, java.util.Date lastUpdatedByFeed, java.util.Date lastUpdatedByUser, java.util.Date publishedDate, int updateInterval)
          Constructor that is used when the DBHandler creates and returns a string, so this feed should have an id.
Feed(java.lang.String title, java.lang.String description, java.lang.String url, java.util.Date lastUpdatedByFeed, java.util.Date lastUpdatedByUser, java.util.Date publishedDate)
          Constructor that is used when the RomeFeedParser creates a feed, so this kind of feed should not have an id.
 
Method Summary
 boolean addArticle(Article a)
          The method addArticle adds the specified article to the feed, if it is not already in the feed.
 void addArticles(java.util.List<Article> a)
          Adds a list of articles to the feed, calling the addArticle method.
 java.util.List<Article> getChildren()
          Gets the articles from a feed, should rarely be used as the database should be the source of this type of information, except when the parser is creating the feed.
 java.lang.String getDescription()
          Gets the description of the feed.
 int getId()
          Gets the id of the feed, if it has one; throws an error otherwise.
 java.util.Date getLastUpdatedByFeed()
          Returns the date when the feed was last updated.
 java.util.Date getLastUpdatedByUser()
          Returns the date the feed was last updated by the user.
 int getParentId()
          Gets the id of the feed's parent folder, if it has one; throws an error otherwise.
 java.util.Date getPublishedDate()
          Returns the date the feed was published.
 java.lang.String getTitle()
          Gets the title of the Feed, which should not be null (but might conceivably be the empty string "").
 int getUpdateInterval()
          Gets the updateInterval of the feed, an integer representing how frequently the application should try to update the feed.
 java.lang.String getUrl()
          Gets the url of the Feed.
private  boolean hasArticle(Article a)
          The method hasArticle tests if the article is already in the feed, based on the article.isSame() method.
static boolean isSame(Feed f1, Feed f2)
          Tests equivalence of two feeds by comparing the two feeds' URLs.
 boolean knowsChildren()
          This method returns a boolean indication whether or not this feed is actually containing its children, which isn't trivial because feeds returned by the database don't have references to their children.
 boolean removeArticle(Article a)
          The method removeArticle attempts to remove the specified article from the Feed.
private  void setKnowsChildren(boolean b)
          sets the knowsChildren private data field.
 void setTitle(java.lang.String title)
          Sets the title of the feed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

knowsChildren

private boolean knowsChildren

title

private java.lang.String title

description

private java.lang.String description

url

private java.lang.String url

id

private int id

parentid

private int parentid

updateInterval

private int updateInterval

lastUpdatedByFeed

private java.util.Date lastUpdatedByFeed

lastUpdatedByUser

private java.util.Date lastUpdatedByUser

publishedDate

private java.util.Date publishedDate

articles

private java.util.List<Article> articles
Constructor Detail

Feed

public Feed(int id,
            int parentid,
            java.lang.String title,
            java.lang.String description,
            java.lang.String url,
            java.util.Date lastUpdatedByFeed,
            java.util.Date lastUpdatedByUser,
            java.util.Date publishedDate,
            int updateInterval)
Constructor that is used when the DBHandler creates and returns a string, so this feed should have an id. This is a complete representation of the feed from the database, so should not have null values in place of strings; nevertheless, if the relevant input is null, title, description, and URL will be stored as empty strings instead of null values. Likewise, null date input will become a new generic date object.

Parameters:
id - Guaranteed unique (comes from database).
parentid -
title -
description -
url -
lastUpdatedByFeed -
lastUpdatedByUser -
publishedDate -
updateInterval -

Feed

public Feed(java.lang.String title,
            java.lang.String description,
            java.lang.String url,
            java.util.Date lastUpdatedByFeed,
            java.util.Date lastUpdatedByUser,
            java.util.Date publishedDate)
Constructor that is used when the RomeFeedParser creates a feed, so this kind of feed should not have an id. Title, description, and URL become empty strings if null values are supplied; the date fields lastUpdatedByFeed, lastUpdatedByUser, and publishedDate become new date objects if null values are given.

Parameters:
title -
description -
url -
lastUpdatedByFeed -
lastUpdatedByUser -
publishedDate -
Method Detail

addArticle

public boolean addArticle(Article a)
The method addArticle adds the specified article to the feed, if it is not already in the feed. If it is already in the feed, it returns false.

Returns:
true if the article was successfully added.

addArticles

public void addArticles(java.util.List<Article> a)
Adds a list of articles to the feed, calling the addArticle method. Because each addArticle returns a boolean value, this has no return type; it's void! Note that duplicate articles will not be added (per the contract of addArticle).

Parameters:
a - The list of articles to be added to the feed.

hasArticle

private boolean hasArticle(Article a)
The method hasArticle tests if the article is already in the feed, based on the article.isSame() method.

Parameters:
a - Article to be compared.
Returns:
true if for some Article b in the feed b.isSame(a) returns true.

removeArticle

public boolean removeArticle(Article a)
The method removeArticle attempts to remove the specified article from the Feed. If one such feed is found it is removed and the method returns true. If more than one article matches the specified article, then nothing is guaranteed other than that one will be removed.

Returns:
true if the specified article is removed from the feed.

isSame

public static boolean isSame(Feed f1,
                             Feed f2)
Tests equivalence of two feeds by comparing the two feeds' URLs. A URL should be globally unique within a user's set of subscribed feeds.

Parameters:
f1 - First feed to be tested
f2 - Second feed to be tested
Returns:
True if the feeds are the same (have same URL); false otherwise.

getChildren

public java.util.List<Article> getChildren()
                                    throws java.lang.IllegalAccessException
Gets the articles from a feed, should rarely be used as the database should be the source of this type of information, except when the parser is creating the feed.

Returns:
List of all articles which the feed thinks are its children (the database may be more up to date and may disagree with this method)
Throws:
java.lang.IllegalAccessException - if the feed has not yet been instantiated with its children (for instance, it is newly created)

knowsChildren

public boolean knowsChildren()
This method returns a boolean indication whether or not this feed is actually containing its children, which isn't trivial because feeds returned by the database don't have references to their children.

Returns:

setKnowsChildren

private void setKnowsChildren(boolean b)
sets the knowsChildren private data field.

Parameters:
b -

getDescription

public java.lang.String getDescription()
Gets the description of the feed. This longwinded (optional) description tells the user what the feed is all about.

Returns:
String description

getId

public int getId()
Gets the id of the feed, if it has one; throws an error otherwise.

Returns:
int The feed's id.
Throws:
java.lang.IllegalAccessError - If this feed was constructed as "small" (without an id), throw this exception.

getParentId

public int getParentId()
Gets the id of the feed's parent folder, if it has one; throws an error otherwise.

Returns:
int parentId The id of the feed's parent folder.
Throws:
java.lang.IllegalAccessError - If this feed was constructed as "small" (without a parent id), throw this exception.

getLastUpdatedByFeed

public java.util.Date getLastUpdatedByFeed()
Returns the date when the feed was last updated.

Returns:
Date lastUpdated

getLastUpdatedByUser

public java.util.Date getLastUpdatedByUser()
Returns the date the feed was last updated by the user.

Returns:
Date lastUpdatedByUser

getPublishedDate

public java.util.Date getPublishedDate()
Returns the date the feed was published.

Returns:
Date pubDate

getTitle

public java.lang.String getTitle()
Gets the title of the Feed, which should not be null (but might conceivably be the empty string "").

Returns:
String title

setTitle

public void setTitle(java.lang.String title)
Sets the title of the feed. If input is null, sets the title of the feed to the empty string; otherwise sets feed title to the input.

Parameters:
title - String New title for feed.

getUrl

public java.lang.String getUrl()
Gets the url of the Feed. This should not be null, as feeds are considered unique on the basis of their urls.

Returns:
String url

getUpdateInterval

public int getUpdateInterval()
Gets the updateInterval of the feed, an integer representing how frequently the application should try to update the feed. Only works if the feed has been created with an update interval!

Returns:
int updateInterval
Throws:
java.lang.IllegalAccessError - If the feed has not been instantiated with an update interval, give this exception.