View Javadoc
1   package com.gisgraphy.fulltext;
2   
3   import java.util.Comparator;
4   
5   
6   public class SolrResponseDtoDistanceComparator implements Comparator<SolrResponseDto> {
7   
8       public int compare(SolrResponseDto o1, SolrResponseDto o2) {
9   	if (o1==null){
10  	    if (o2==null){
11  		return 0;
12  	    } else {
13  		return -1;
14  	    }
15  	}
16  	if (o2==null){
17  	    //o1 is not null so o2<o1
18  	    return 1;
19  	}
20  	Double distance1 = o1.getDistance();
21  	Double distance2 = o2.getDistance();
22  	if (distance1==null){
23  	    if (distance2==null){
24  		return 0;
25  	    } else {
26  		return -1;
27  	    }
28  	}
29  	if (distance2==null){
30  	    return 1;
31  	}
32  	if (distance1 > distance2)
33  	    return 1;
34  	else if (distance1 < distance2)
35  	    return -1;
36  	else
37  	    return 0;
38      }
39  
40  }