package org.openforis.collect.earth.planet;

import java.util.Comparator;;

public class FeatureSorter implements Comparator<Feature>{

	@Override
	public int compare(Feature o1, Feature o2) {
		if( o1.getProperties().getCloudPercent() !=null && o2.getProperties().getCloudPercent() != null  )
			if( o1.getProperties().getCloudPercent() == o2.getProperties().getCloudPercent()) {
					return o2.getProperties().getVisibleConfidencePercent() - o1.getProperties().getVisibleConfidencePercent();
				}else {
					return o1.getProperties().getCloudPercent() - o2.getProperties().getCloudPercent();
				}
		else if( o1.getProperties().getCloudPercent() != null ) {
			return -1;
		}else if( o2.getProperties().getCloudPercent() != null) {
			return 1;
		}else {
			return (int) ( (o1.getProperties().getCloudCover() - o2.getProperties().getCloudCover() ) * 100 );
		}
	}

}

@@ -294,18 +294,20 @@
  null  )
+ %7B
 %0D%0A
-
 %09%09%09if( o
@@ -395,115 +395,379 @@
 %09%09%09%09
-return o2.getProperties().getVisibleConfidencePercent() - o1.getProperties().getVisibleConfidencePercent();
+if( o2.getProperties().getVisibleConfidencePercent() !=null &&  o1.getProperties().getVisibleConfidencePercent() != null ) %7B%0D%0A%09%09%09%09%09%09return o2.getProperties().getVisibleConfidencePercent() - o1.getProperties().getVisibleConfidencePercent();%0D%0A%09%09%09%09%09%7Delse if( o2.getProperties().getVisibleConfidencePercent() !=null ) %7B%0D%0A%09%09%09%09%09%09return 1;%0D%0A%09%09%09%09%09%7Delse%7B%0D%0A%09%09%09%09%09%09return -1;%0D%0A%09%09%09%09%09%7D
 %0D%0A%09%09
@@ -876,16 +876,17 @@
 %09%09%09%7D%0D%0A%09%09
+%7D
 else if(
@@ -1033,24 +1033,123 @@
 %0A%09%09%7Delse %7B%0D%0A
+%09%09%09if( o1.getProperties().getCloudCover()!=null && o2.getProperties().getCloudCover()!=null ) %7B %0D%0A%09
 %09%09%09return (i
@@ -1239,16 +1239,81 @@
 100 );%0D%0A
+%09%09%09%7Delse %0D%0A%09%09%09%09return 1; // No way to know so return the latest%0D%0A
 %09%09%7D%0D%0A%09%7D%0D

Fix null exception when images have no visible percent properties