solved s3 ex4
This commit is contained in:
parent
626f0d1bee
commit
8c647448ea
@ -63,12 +63,12 @@ public class Competitor implements Comparable<Competitor> {
|
|||||||
if (this.equals(other)) {
|
if (this.equals(other)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return new Long(this.getTime()).compareTo(new Long(other.getTime()));
|
return Long.valueOf(this.getTime()).compareTo(Long.valueOf(other.getTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Competitor other) {
|
public boolean equals(Competitor other) {
|
||||||
return this.getName().equals(other.getName())
|
return this.getName().equals(other.getName())
|
||||||
&& new Integer(this.getJg()).equals(new Integer(other.getJg()))
|
&& Integer.valueOf(this.getJg()).equals(Integer.valueOf(other.getJg()))
|
||||||
&& new Long(this.getTime()).equals(new Long(other.getTime()));
|
&& Long.valueOf(this.getTime()).equals(Long.valueOf(other.getTime()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package ch.zhaw.ads;
|
package ch.zhaw.ads;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.lang.ArrayIndexOutOfBoundsException;
|
import java.lang.ArrayIndexOutOfBoundsException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class RankingServer implements CommandExecutor {
|
public class RankingServer implements CommandExecutor {
|
||||||
List<Competitor> competitors;
|
List<Competitor> competitors;
|
||||||
@ -27,6 +28,21 @@ public class RankingServer implements CommandExecutor {
|
|||||||
competitor.setRank(i + 1);
|
competitor.setRank(i + 1);
|
||||||
result.append(competitor.toString() + "\n");
|
result.append(competitor.toString() + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Collections.sort(competitors, new Comparator<Competitor>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Competitor o1, Competitor o2) {
|
||||||
|
int nameCompare = o1.getName().compareTo(o2.getName());
|
||||||
|
if (nameCompare == 0) {
|
||||||
|
return Integer.valueOf(o1.getJg()).compareTo(o2.getJg());
|
||||||
|
}
|
||||||
|
return nameCompare;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
result.append("\n\nSorted Competitors (by name, then birth year):\n");
|
||||||
|
for (Competitor competitor : competitors) {
|
||||||
|
result.append(competitor.toString() + "\n");
|
||||||
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user