Implement missing equals and hashcode methods for feeditem (#7132)

Till 5713b18267 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.
This commit is contained in:
flofriday 2024-04-24 21:06:12 +02:00 committed by GitHub
parent 0aa8e85003
commit 4bc0b38280
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 68 additions and 1 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}