final PropertyName PROPERTY = sortBy.getPropertyName();
return new Comparator<SimpleFeature>() {
@SuppressWarnings("unchecked")
public int compare(SimpleFeature f1, SimpleFeature f2) {
Object value1 = PROPERTY.evaluate(f1, Comparable.class);
Object value2 = PROPERTY.evaluate(f2, Comparable.class);
if (value1 == null || value2 == null) {
return 0; // cannot perform comparison
}
if (value1 instanceof Comparable && value1.getClass().isInstance(value2)) {
return ((Comparable<Object>) value1).compareTo(value2);