considering possibility of null positions

This commit is contained in:
Claudio Barril 2014-09-07 20:16:09 -03:00
parent 37b2cc7466
commit 72ee23849f

View File

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