Skip to content

Commit

Permalink
Implement missing equals and hashcode methods for feeditem (#7132)
Browse files Browse the repository at this point in the history
Till 5713b18 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.
  • Loading branch information
flofriday committed Apr 24, 2024
1 parent 0aa8e85 commit 4bc0b38
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
19 changes: 19 additions & 0 deletions 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;
Expand Down Expand Up @@ -88,4 +89,22 @@ public static int getAfterPosition(List<Chapter> chapters, int playbackPosition)
}
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);
}
}
20 changes: 20 additions & 0 deletions model/src/main/java/de/danoeh/antennapod/model/feed/Feed.java
Expand Up @@ -5,6 +5,8 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;

/**
Expand Down Expand Up @@ -468,4 +470,22 @@ public void setLastUpdateFailed(boolean lastUpdateFailed) {
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);
}
}
19 changes: 19 additions & 0 deletions model/src/main/java/de/danoeh/antennapod/model/feed/FeedItem.java
Expand Up @@ -11,6 +11,7 @@
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -418,4 +419,22 @@ public void setPodcastIndexChapterUrl(String url) {
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);
}
}
Expand Up @@ -501,12 +501,21 @@ public void checkEmbeddedPicture() {

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

0 comments on commit 4bc0b38

Please sign in to comment.