diff --git a/app/src/main/java/ch/nuth/zhaw/exbox/MyCompetitor.java b/app/src/main/java/ch/nuth/zhaw/exbox/MyCompetitor.java index fef2cf6..021838e 100644 --- a/app/src/main/java/ch/nuth/zhaw/exbox/MyCompetitor.java +++ b/app/src/main/java/ch/nuth/zhaw/exbox/MyCompetitor.java @@ -47,19 +47,39 @@ public class MyCompetitor implements Comparable { @Override public int compareTo(MyCompetitor o) { - // to be done - return -1; + int result = getName().compareTo(o.getName()); + + if (result == 0) { + result = getTime().compareTo(o.getTime()); + + if (result == 0) { + result = rank - o.rank; + } + } + + return result; } @Override public int hashCode() { - // to be done - return -1; + int hashCode = 1; + hashCode *= 13; + hashCode += name.hashCode(); + hashCode *= 17; + hashCode += time.hashCode(); + hashCode *= 31; + return hashCode + rank; } @Override public boolean equals (Object o) { - // to be done - return false; + if (o instanceof MyCompetitor c) { + return hashCode() == c.hashCode() && + getName().equals(c.getName()) && + getTime().equals(c.getTime()) && + rank == c.rank; + } else { + return false; + } } }