summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/util/QueueAccess.java
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2013-09-11 15:09:11 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2013-09-11 15:09:11 +0200
commitcef7772a90b7221de20e0a3176a8fc7d40ec9044 (patch)
tree53307e00a26e105f0cfa73518783187467f3f565 /src/de/danoeh/antennapod/util/QueueAccess.java
parent6043f79128586bc2925b81a852f0758a53f7990c (diff)
parent30c681d1cf5e0d33b716f6c8885ab92f46efbaa3 (diff)
downloadAntennaPod-cef7772a90b7221de20e0a3176a8fc7d40ec9044.zip
Merge branch 'release-0975'0.9.7.5
Diffstat (limited to 'src/de/danoeh/antennapod/util/QueueAccess.java')
-rw-r--r--src/de/danoeh/antennapod/util/QueueAccess.java93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/de/danoeh/antennapod/util/QueueAccess.java b/src/de/danoeh/antennapod/util/QueueAccess.java
new file mode 100644
index 000000000..7a1c7fef2
--- /dev/null
+++ b/src/de/danoeh/antennapod/util/QueueAccess.java
@@ -0,0 +1,93 @@
+package de.danoeh.antennapod.util;
+
+import de.danoeh.antennapod.feed.FeedItem;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Provides methods for accessing the queue. It is possible to load only a part of the information about the queue that
+ * is stored in the database (e.g. sometimes the user just has to test if a specific item is contained in the List.
+ * QueueAccess provides an interface for accessing the queue without having to care about the type of the queue
+ * representation.
+ */
+public abstract class QueueAccess {
+ /**
+ * Returns true if the item is in the queue, false otherwise.
+ */
+ public abstract boolean contains(long id);
+
+ /**
+ * Removes the item from the queue.
+ *
+ * @return true if the queue was modified by this operation.
+ */
+ public abstract boolean remove(long id);
+
+ private QueueAccess() {
+
+ }
+
+ public static QueueAccess IDListAccess(final List<Long> ids) {
+ return new QueueAccess() {
+ @Override
+ public boolean contains(long id) {
+ return (ids != null) && ids.contains(id);
+ }
+
+ @Override
+ public boolean remove(long id) {
+ return ids.remove(id);
+ }
+
+
+ };
+ }
+
+ public static QueueAccess ItemListAccess(final List<FeedItem> items) {
+ return new QueueAccess() {
+ @Override
+ public boolean contains(long id) {
+ if (items == null) {
+ return false;
+ }
+ for (FeedItem item : items) {
+ if (item.getId() == id) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean remove(long id) {
+ Iterator<FeedItem> it = items.iterator();
+ FeedItem item;
+ while (it.hasNext()) {
+ item = it.next();
+ if (item.getId() == id) {
+ it.remove();
+ return true;
+ }
+ }
+ return false;
+ }
+ };
+ }
+
+ public static QueueAccess NotInQueueAccess() {
+ return new QueueAccess() {
+ @Override
+ public boolean contains(long id) {
+ return false;
+ }
+
+ @Override
+ public boolean remove(long id) {
+ return false;
+ }
+ };
+
+ }
+
+}