Fixed ProtectedRegion.compareTo.

It properly implements the Comparable interface now.
In particular, it now fulfills the criterion "sgn(x.compareTo(y)) == -sgn(y.compareTo(x))".
This commit is contained in:
TomyLobo 2012-01-09 14:47:59 +01:00
parent 46a2510e85
commit 9d848e222b

View File

@ -414,21 +414,22 @@ public boolean containsAny(List<BlockVector2D> pts) {
} }
/** /**
* Compares to another region. * Compares to another region.<br>
*<br>
* Orders primarily by the priority, descending<br>
* Orders secondarily by the id, ascending
* *
* @param other * @param other
* @return * @return
*/ */
public int compareTo(ProtectedRegion other) { public int compareTo(ProtectedRegion other) {
if (id.equals(other.id)) { if (priority > other.priority) {
return 0;
} else if (priority == other.priority) {
return 1;
} else if (priority > other.priority) {
return -1; return -1;
} else { } else if (priority < other.priority) {
return 1; return 1;
} }
return id.compareTo(other.id);
} }
/** /**