comparator with null values.

Posted by pvgoddijn on Stack Overflow See other posts from Stack Overflow or by pvgoddijn
Published on 2010-03-08T13:35:31Z Indexed on 2010/03/08 13:51 UTC
Read the original article Hit count: 396

Filed under:
|
|

Hi,

We have some code wich sorts a list of addresses based on the distance between their coordinates. this is done through collections.sort with a custom comparator.

However from time to time an adress without coordinates is in the list causing a NullPointerException. My initial idea to fix this was to have the comparator return 0 as dististance for addresses where at least one of the coordinates is null. I fear this might lead to corruption of the order the 'valid' elements in the list.

so is returning a '0' values for null data in a comparator ok, or is there a cleaner way to resolve this.

© Stack Overflow or respective owner

Related posts about java

Related posts about comparator