[Android] Implement equals() method for medialibrary items

Geoffrey Métais git at videolan.org
Thu Dec 1 16:21:27 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Dec  1 16:19:40 2016 +0100| [3a5e93f276ffc37786d4ee59949cd21b427c924a] | committer: Geoffrey Métais

Implement equals() method for medialibrary items

> https://code.videolan.org/videolan/vlc-android/commit/3a5e93f276ffc37786d4ee59949cd21b427c924a
---

 medialibrary/src/org/videolan/medialibrary/media/DummyItem.java  | 6 ++++++
 .../src/org/videolan/medialibrary/media/MediaLibraryItem.java    | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/medialibrary/src/org/videolan/medialibrary/media/DummyItem.java b/medialibrary/src/org/videolan/medialibrary/media/DummyItem.java
index f05a403..c3faf43 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/DummyItem.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/DummyItem.java
@@ -2,6 +2,7 @@ package org.videolan.medialibrary.media;
 
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.text.TextUtils;
 
 import org.videolan.medialibrary.Medialibrary;
 
@@ -40,4 +41,9 @@ public class DummyItem extends MediaLibraryItem {
     public DummyItem(Parcel in) {
         super(in);
     }
+
+    @Override
+    public boolean equals(Object obj) {
+        return obj instanceof DummyItem && TextUtils.equals(mTitle, ((DummyItem) obj).getTitle());
+    }
 }
diff --git a/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java b/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
index 91f48fa..815682c 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
@@ -67,4 +67,13 @@ public abstract class MediaLibraryItem implements Parcelable {
         mId = in.readLong();
         mTitle = in.readString();
     }
+
+    @Override
+    public boolean equals(Object obj) {
+        return this == obj || (obj instanceof MediaLibraryItem && mId == ((MediaLibraryItem) obj).getId());
+    }
+
+    public boolean equals(MediaLibraryItem other) {
+        return this == other || (other != null && other.getItemType() == getItemType() && mId == other.getId());
+    }
 }



More information about the Android mailing list