considering possibility of null positions

This commit is contained in:
Claudio Barril 2014-09-07 20:16:09 -03:00
parent b45f874ce4
commit d8e255cac8

View File

@ -10,9 +10,17 @@ public class VerticalPositionComparator implements Comparator<TopicType> {
public int compare(TopicType o1, TopicType o2) {
final String myPosition = o1.getPosition();
final String otherPosition = o2.getPosition();
int myPositionY = Integer.parseInt(myPosition.split(",")[1]);
int otherPositionY = Integer.parseInt(otherPosition.split(",")[1]);
return myPositionY - otherPositionY;
int result;
if (otherPosition == null) {
result = -1;
} else if (myPosition == null) {
result = 1;
} else {
int myPositionY = Integer.parseInt(myPosition.split(",")[1]);
int otherPositionY = Integer.parseInt(otherPosition.split(",")[1]);
result = myPositionY - otherPositionY;
}
return result;
}
}