@Override public int compare(Sighting lhs, Sighting rhs) { if (lhs.getTimestamp() == null && rhs.getTimestamp() == null) { return 0; } if (lhs.getTimestamp() == null) { return 1; } if (rhs.getTimestamp() == null) { return -1; } int value = lhs.getTimestamp().compareTo(rhs.getTimestamp()); if (value >= 1) { return -1; } if (value <= -1) { return 1; } if (value == 0) { return 0; } return value; }
@Override public int compare(Sighting lhs, Sighting rhs) { if (lhs.getDistance() == -1 && rhs.getDistance() == -1) { return 0; } if (lhs.getDistance() == -1) { return 1; } if (rhs.getDistance() == -1) { return -1; } float fistSighting = lhs.getDistance(); float secondSighting = rhs.getDistance(); if (fistSighting > secondSighting) { return 1; } if (fistSighting < secondSighting) { return -1; } if (fistSighting == secondSighting) { return 0; } return 0; }