diff options
author | flofriday <flohacksfriday@gmail.com> | 2024-04-24 21:06:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-24 21:06:12 +0200 |
commit | 4bc0b38280f5d1fa3bc1d0988dd6d2607e65314f (patch) | |
tree | 3de93ac66d65c6b95bb6210472b201fdc697bbee /model/src | |
parent | 0aa8e850034828c8d129fcf29d8b6fe635ec0b10 (diff) | |
download | AntennaPod-4bc0b38280f5d1fa3bc1d0988dd6d2607e65314f.zip |
Implement missing equals and hashcode methods for feeditem (#7132)
Till 5713b1826795598848c95f31df906b7af5ce7076 many classes like FeedItem
used to inherit from FeedComponent which provided those two methods.
However since that commit the component no longer exists and now the
classes need to implement it on their own. Without this, ArrayList.remove breaks.
Diffstat (limited to 'model/src')
4 files changed, 68 insertions, 1 deletions
diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/Chapter.java b/model/src/main/java/de/danoeh/antennapod/model/feed/Chapter.java index 3683a2a44..f6a5205d2 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/feed/Chapter.java +++ b/model/src/main/java/de/danoeh/antennapod/model/feed/Chapter.java @@ -1,6 +1,7 @@ package de.danoeh.antennapod.model.feed; import java.util.List; +import java.util.Objects; public class Chapter { private long id; @@ -88,4 +89,22 @@ public class Chapter { } return chapters.size() - 1; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + Chapter chapter = (Chapter) o; + return id == chapter.id; + } + + @Override + public int hashCode() { + return Objects.hash(id); + } } diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/Feed.java b/model/src/main/java/de/danoeh/antennapod/model/feed/Feed.java index 15d256c24..99e7ca9dc 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/feed/Feed.java +++ b/model/src/main/java/de/danoeh/antennapod/model/feed/Feed.java @@ -5,6 +5,8 @@ import androidx.annotation.Nullable; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; + import org.apache.commons.lang3.StringUtils; /** @@ -468,4 +470,22 @@ public class Feed { public boolean isLocalFeed() { return downloadUrl.startsWith(PREFIX_LOCAL_FOLDER); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + Feed feed = (Feed) o; + return id == feed.id; + } + + @Override + public int hashCode() { + return Objects.hash(id); + } } diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedItem.java b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedItem.java index df4cc8f9c..2a62e3e34 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedItem.java +++ b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedItem.java @@ -11,6 +11,7 @@ import java.io.Serializable; import java.util.Date; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; /** @@ -418,4 +419,22 @@ public class FeedItem implements Serializable { public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + FeedItem feedItem = (FeedItem) o; + return id == feedItem.id; + } + + @Override + public int hashCode() { + return Objects.hash(id); + } } diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedMedia.java b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedMedia.java index 698cdf34e..1f0786875 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedMedia.java +++ b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedMedia.java @@ -501,12 +501,21 @@ public class FeedMedia implements Playable { @Override public boolean equals(Object o) { + if (this == o) { + return true; + } if (o == null) { return false; } if (o instanceof RemoteMedia) { return o.equals(this); } - return super.equals(o); + + if (getClass() != o.getClass()) { + return false; + } + + FeedMedia feedMedia = (FeedMedia) o; + return id == feedMedia.id; } } |