Add a method for hashing and comparison
This commit is contained in:
parent
29bd296ceb
commit
e9d1148cd0
1 changed files with 26 additions and 6 deletions
|
@ -47,19 +47,39 @@ public class MyCompetitor implements Comparable<MyCompetitor> {
|
|||
|
||||
@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
|
||||
if (o instanceof MyCompetitor c) {
|
||||
return hashCode() == c.hashCode() &&
|
||||
getName().equals(c.getName()) &&
|
||||
getTime().equals(c.getTime()) &&
|
||||
rank == c.rank;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue