public int compareTo(Element other) { if (nextLoc == null) { if (other.nextLoc != null) return 1; // null means no more data available, so its after any non-null position return 0; } if (other.nextLoc == null) return -1; // we can get to this point only if this.nextLoc != null return nextLoc.compareTo(other.nextLoc); }