Adds equals override for Language objects.
Makes languages sort group by can speaks.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package com.majinnaibu.monstercards.models;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Language implements Comparator<Language>, Comparable<Language> {
|
||||
|
||||
@@ -31,11 +34,41 @@ public class Language implements Comparator<Language>, Comparable<Language> {
|
||||
|
||||
@Override
|
||||
public int compareTo(Language o) {
|
||||
return this.getName().compareToIgnoreCase(o.getName());
|
||||
if (this.mSpeaks && !o.mSpeaks) {
|
||||
return -1;
|
||||
}
|
||||
if (!this.mSpeaks && o.mSpeaks) {
|
||||
return 1;
|
||||
}
|
||||
return this.mName.compareToIgnoreCase(o.mName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(Language o1, Language o2) {
|
||||
return o1.getName().compareToIgnoreCase(o2.getName());
|
||||
if (o1.mSpeaks && !o2.mSpeaks) {
|
||||
return -1;
|
||||
}
|
||||
if (!o1.mSpeaks && o2.mSpeaks) {
|
||||
return 1;
|
||||
}
|
||||
return o1.mName.compareToIgnoreCase(o2.mName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable @org.jetbrains.annotations.Nullable Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof Language)) {
|
||||
return false;
|
||||
}
|
||||
Language otherLanguage = (Language) obj;
|
||||
if (!Objects.equals(this.mName, otherLanguage.mName)) {
|
||||
return false;
|
||||
}
|
||||
if (this.mSpeaks != otherLanguage.mSpeaks) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user