aboutsummaryrefslogtreecommitdiff
path: root/WordPress/src/main/java/org/wordpress/android/models/ReaderTagList.java
diff options
context:
space:
mode:
Diffstat (limited to 'WordPress/src/main/java/org/wordpress/android/models/ReaderTagList.java')
-rw-r--r--WordPress/src/main/java/org/wordpress/android/models/ReaderTagList.java69
1 files changed, 69 insertions, 0 deletions
diff --git a/WordPress/src/main/java/org/wordpress/android/models/ReaderTagList.java b/WordPress/src/main/java/org/wordpress/android/models/ReaderTagList.java
new file mode 100644
index 000000000..87464b722
--- /dev/null
+++ b/WordPress/src/main/java/org/wordpress/android/models/ReaderTagList.java
@@ -0,0 +1,69 @@
+package org.wordpress.android.models;
+
+import java.util.ArrayList;
+
+public class ReaderTagList extends ArrayList<ReaderTag> {
+
+ public int indexOfTagName(String tagName) {
+ if (tagName == null || isEmpty()) {
+ return -1;
+ }
+
+ for (int i = 0; i < size(); i++) {
+ if (tagName.equals(this.get(i).getTagSlug())) {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+ private int indexOfTag(ReaderTag tag) {
+ if (tag == null || isEmpty()) {
+ return -1;
+ }
+
+ for (int i = 0; i < this.size(); i++) {
+ if (ReaderTag.isSameTag(tag, this.get(i))) {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+ public boolean isSameList(ReaderTagList otherList) {
+ if (otherList == null || otherList.size() != this.size()) {
+ return false;
+ }
+
+ for (ReaderTag otherTag: otherList) {
+ int i = this.indexOfTag(otherTag);
+ if (i == -1) {
+ return false;
+ } else if (!otherTag.getEndpoint().equals(this.get(i).getEndpoint())) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /*
+ * returns a list of tags that are in this list but not in the passed list
+ */
+ public ReaderTagList getDeletions(ReaderTagList otherList) {
+ ReaderTagList deletions = new ReaderTagList();
+ if (otherList == null) {
+ return deletions;
+ }
+
+ for (ReaderTag thisTag: this) {
+ if (otherList.indexOfTag(thisTag) == -1) {
+ deletions.add(thisTag);
+ }
+ }
+
+ return deletions;
+ }
+}