Adds equals override to Trait objects.
Fixes trait comparisons.
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 Trait implements Comparator<Trait>, Comparable<Trait> {
|
||||
|
||||
@@ -14,12 +17,33 @@ public class Trait implements Comparator<Trait>, Comparable<Trait> {
|
||||
|
||||
@Override
|
||||
public int compareTo(Trait o) {
|
||||
return this.name.compareToIgnoreCase(o.name);
|
||||
return compare(this, o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(Trait o1, Trait o2) {
|
||||
return o1.name.compareToIgnoreCase(o2.name);
|
||||
int result = o1.name.compareToIgnoreCase(o2.name);
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
return o1.description.compareToIgnoreCase(o2.description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable @org.jetbrains.annotations.Nullable Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof Trait)) {
|
||||
return false;
|
||||
}
|
||||
Trait otherTrait = (Trait) obj;
|
||||
if (!Objects.equals(this.name, otherTrait.name)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.description, otherTrait.description)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user