Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve Tabs style checks #6346

Merged
merged 10 commits into from
Jun 8, 2021
71 changes: 55 additions & 16 deletions app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,16 @@ private static Tab from(final int tabId, @Nullable final JsonObject jsonObject)

@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
if (!(obj instanceof Tab)) {
return false;
}
final Tab other = (Tab) obj;
return getTabId() == other.getTabId();
}

return obj instanceof Tab && obj.getClass() == this.getClass()
&& ((Tab) obj).getTabId() == this.getTabId();
@Override
public int hashCode() {
return Objects.hashCode(getTabId());
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -358,8 +362,18 @@ protected void readDataFromJson(final JsonObject jsonObject) {

@Override
public boolean equals(final Object obj) {
return super.equals(obj) && kioskServiceId == ((KioskTab) obj).kioskServiceId
&& Objects.equals(kioskId, ((KioskTab) obj).kioskId);
if (!(obj instanceof KioskTab)) {
return false;
}
final KioskTab other = (KioskTab) obj;
return super.equals(obj)
&& kioskServiceId == other.kioskServiceId
&& kioskId.equals(other.kioskId);
}

@Override
public int hashCode() {
return Objects.hash(getTabId(), kioskServiceId, kioskId);
}

public int getKioskServiceId() {
Expand Down Expand Up @@ -432,9 +446,19 @@ protected void readDataFromJson(final JsonObject jsonObject) {

@Override
public boolean equals(final Object obj) {
return super.equals(obj) && channelServiceId == ((ChannelTab) obj).channelServiceId
&& Objects.equals(channelUrl, ((ChannelTab) obj).channelUrl)
&& Objects.equals(channelName, ((ChannelTab) obj).channelName);
if (!(obj instanceof ChannelTab)) {
return false;
}
final ChannelTab other = (ChannelTab) obj;
return super.equals(obj)
&& channelServiceId == other.channelServiceId
&& channelUrl.equals(other.channelName)
&& channelName.equals(other.channelName);
}

@Override
public int hashCode() {
return Objects.hash(getTabId(), channelServiceId, channelUrl, channelName);
}

public int getChannelServiceId() {
Expand Down Expand Up @@ -576,15 +600,30 @@ protected void readDataFromJson(final JsonObject jsonObject) {

@Override
public boolean equals(final Object obj) {
if (!(super.equals(obj)
&& Objects.equals(playlistType, ((PlaylistTab) obj).playlistType)
&& Objects.equals(playlistName, ((PlaylistTab) obj).playlistName))) {
return false; // base objects are different
if (!(obj instanceof PlaylistTab)) {
return false;
}

return (playlistId == ((PlaylistTab) obj).playlistId) // local
|| (playlistServiceId == ((PlaylistTab) obj).playlistServiceId // remote
&& Objects.equals(playlistUrl, ((PlaylistTab) obj).playlistUrl));
final PlaylistTab other = (PlaylistTab) obj;

return super.equals(obj)
&& playlistServiceId == other.playlistServiceId // Remote
&& playlistId == other.playlistId // Local
&& playlistUrl.equals(other.playlistUrl)
&& playlistName.equals(other.playlistName)
&& playlistType == other.playlistType;
}

@Override
public int hashCode() {
return Objects.hash(
getTabId(),
playlistServiceId,
playlistId,
playlistUrl,
playlistName,
playlistType
);
}

public int getPlaylistServiceId() {
Expand Down