Added "updateFromOther" and "compareWithOther" methods

This commit is contained in:
daniel oeh 2012-12-18 17:27:22 +01:00
parent d07afe16ae
commit aa7e58dc42
6 changed files with 184 additions and 3 deletions

View File

@ -171,6 +171,72 @@ public class Feed extends FeedFile {
}
}
public void updateFromOther(Feed other) {
super.updateFromOther(other);
if (other.title != null) {
title = other.title;
}
if (other.feedIdentifier != null) {
feedIdentifier = other.feedIdentifier;
}
if (other.link != null) {
link = other.link;
}
if (other.description != null) {
description = other.description;
}
if (other.language != null) {
language = other.language;
}
if (other.author != null) {
author = other.author;
}
if (other.paymentLink != null) {
paymentLink = other.paymentLink;
}
}
public boolean compareWithOther(Feed other) {
if (super.compareWithOther(other)) {
return true;
}
if (!title.equals(other.title)) {
return true;
}
if (other.feedIdentifier != null) {
if (feedIdentifier == null
|| !feedIdentifier.equals(other.feedIdentifier)) {
return true;
}
}
if (other.link != null) {
if (link == null || !link.equals(other.link)) {
return true;
}
}
if (other.description != null) {
if (description == null || !description.equals(other.description)) {
return true;
}
}
if (other.language != null) {
if (language == null || !language.equals(other.language)) {
return true;
}
}
if (other.author != null) {
if (author == null || !author.equals(other.author)) {
return true;
}
}
if (other.paymentLink != null) {
if (paymentLink == null || !paymentLink.equals(other.paymentLink)) {
return true;
}
}
return false;
}
@Override
public int getTypeAsInt() {
return FEEDFILETYPE_FEED;

View File

@ -21,6 +21,25 @@ public class FeedComponent {
this.id = id;
}
/**
* Update this FeedComponent's attributes with the attributes from another
* FeedComponent. This method should only update attributes which where read from
* the feed.
*/
public void updateFromOther(FeedComponent other) {
}
/**
* Compare's this FeedComponent's attribute values with another FeedComponent's
* attribute values. This method will only compare attributes which were
* read from the feed.
*
* @return true if attribute values are different, false otherwise
*/
public boolean compareWithOther(FeedComponent other) {
return false;
}
}

View File

@ -26,6 +26,33 @@ public abstract class FeedFile extends FeedComponent {
public abstract int getTypeAsInt();
/**
* Update this FeedFile's attributes with the attributes from another
* FeedFile. This method should only update attributes which where read from
* the feed.
*/
public void updateFromOther(FeedFile other) {
super.updateFromOther(other);
this.download_url = other.download_url;
}
/**
* Compare's this FeedFile's attribute values with another FeedFile's
* attribute values. This method will only compare attributes which were
* read from the feed.
*
* @return true if attribute values are different, false otherwise
*/
public boolean compareWithOther(FeedFile other) {
if (super.compareWithOther(other)) {
return true;
}
if (!download_url.equals(other.download_url)) {
return true;
}
return false;
}
public String getFile_url() {
return file_url;
}

View File

@ -43,6 +43,38 @@ public class FeedItem extends FeedComponent {
this.read = true;
}
public void updateFromOther(FeedItem other) {
super.updateFromOther(other);
if (other.title != null) {
title = other.title;
}
if (other.getDescription() != null) {
description = other.getDescription();
}
if (other.getContentEncoded() != null) {
contentEncoded = other.contentEncoded;
}
if (other.link != null) {
link = other.link;
}
if (other.pubDate != null && other.pubDate != pubDate) {
pubDate = other.pubDate;
}
if (other.media != null) {
if (media == null || media.compareWithOther(media)) {
media.updateFromOther(other.media);
}
}
if (other.paymentLink != null) {
paymentLink = other.paymentLink;
}
if (other.chapters != null) {
if (chapters == null) {
chapters = other.chapters;
}
}
}
/**
* Moves the 'description' and 'contentEncoded' field of feeditem to their
* SoftReference fields.
@ -215,7 +247,9 @@ public class FeedItem extends FeedComponent {
cachedContentEncoded = new SoftReference<String>(c);
}
public enum State {NEW, IN_PROGRESS, READ, PLAYING}
public enum State {
NEW, IN_PROGRESS, READ, PLAYING
}
public State getState() {
if (hasMedia()) {

View File

@ -65,6 +65,31 @@ public class FeedMedia extends FeedFile {
return MediaType.UNKNOWN;
}
public void updateFromOther(FeedMedia other) {
super.updateFromOther(other);
if (other.size > 0) {
size = other.size;
}
if (other.mime_type != null) {
mime_type = other.mime_type;
}
}
public boolean compareWithOther(FeedMedia other) {
if (super.compareWithOther(other)) {
return true;
}
if (other.mime_type != null) {
if (mime_type == null || !mime_type.equals(other.mime_type)) {
return true;
}
}
if (other.size > 0 && other.size != size) {
return true;
}
return false;
}
@Override
public int getTypeAsInt() {
return FEEDFILETYPE_FEEDMEDIA;

View File

@ -12,4 +12,14 @@ public class SimpleChapter extends Chapter {
return CHAPTERTYPE_SIMPLECHAPTER;
}
public void updateFromOther(SimpleChapter other) {
super.updateFromOther(other);
start = other.start;
if (other.title != null) {
title = other.title;
}
if (other.link != null) {
link = other.link;
}
}
}