SortBy sortBy = sortByList[i]; Ordering<Object> ordering = Ordering.from(comparator(sortBy)); if (SortOrder.DESCENDING.equals(sortBy.getSortOrder())) { ordering = ordering.reverse();
private SortOrder[] getSortOrders(LiteFeatureTypeStyle style) { SortBy[] sb = style.sortBy; SortOrder[] orders = new SortOrder[sb.length]; for (int i = 0; i < orders.length; i++) { orders[i] = sb[i].getSortOrder(); } return orders; }
public Object getProperty(Object object, QName name) throws Exception { SortBy sortBy = (SortBy) object; if (OGC.PropertyName.equals(name)) { return sortBy.getPropertyName(); } if ("SortOrder".equals(name.getLocalPart())) { return sortBy.getSortOrder(); } return null; } }
/** * Builds a SortKey Comparator from a SortBy array * * @param sortBy * @return */ static Comparator buildComparator(SortBy[] sortBy) { // sanity check if (sortBy == SortBy.UNSORTED || sortBy == null) { throw new IllegalArgumentException("Expected to get a sort, but found none"); } // build a list of comparators List<java.util.Comparator<?>> comparators = new ArrayList<java.util.Comparator<?>>(); for (SortBy sb : sortBy) { if (sb.getSortOrder() == SortOrder.ASCENDING) { comparators.add(FORWARD_COMPARATOR); } else { comparators.add(REVERSE_COMPARATOR); } } return new Comparator(comparators.toArray(new java.util.Comparator[comparators.size()])); } }
private String sortByToString(LiteFeatureTypeStyle style, Class[] classes) { StringBuilder sb = new StringBuilder("Layer ").append(style.layer.getTitle()).append("["); SortBy[] sortBy = style.sortBy; for (int i = 0; i < sortBy.length; i++) { SortBy curr = sortBy[i]; if (curr == SortBy.NATURAL_ORDER) { sb.append("NaturalOrder"); } else if (curr == SortBy.REVERSE_ORDER) { sb.append("ReverseNaturalOrder"); } else { sb.append(curr.getPropertyName().getPropertyName()); sb.append("(").append(classes[i].getSimpleName()).append(")"); if (curr.getSortOrder() == SortOrder.DESCENDING) { sb.append(" D"); } } if (i < sortBy.length) { sb.append(", "); } } sb.append("]"); return sb.toString(); }
} else { final PropertyName propertyName = sortBy.getPropertyName(); final SortOrder sortOrder = sortBy.getSortOrder(); return new Comparator<SimpleFeature>() { @SuppressWarnings("unchecked")
returnString.append(sb.getPropertyName().getPropertyName()); returnString.append(" "); returnString.append(sb.getSortOrder().name());
byClause.append(sortAtt.getSortOrder() == SortOrder.ASCENDING ? "ASC" : "DESC");
@SuppressWarnings("unchecked") protected int compare( SimpleFeature feature1, SimpleFeature feature2, SortBy order) { PropertyName name = order.getPropertyName(); Comparable value1 = (Comparable) name.evaluate(feature1); Comparable value2 = (Comparable) name.evaluate(feature2); if (value1 == value2) { return 0; } if (order.getSortOrder() == SortOrder.ASCENDING) { if (value1 == null) { return -1; } return value1.compareTo(value2); } else { if (value2 == null) { return -1; } return value2.compareTo(value1); } } });
protected SortBy[] unrollSortBy(SortBy[] sortArray) { if (sortArray == null) return null; ArrayList<SortBy> unrolledSorts = new ArrayList<>(); FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints()); for (SortBy aSort : sortArray) { SortBy newSort = ff.sort( unrollIndex(aSort.getPropertyName(), mapping).getPropertyName(), aSort.getSortOrder()); unrolledSorts.add(newSort); } return unrolledSorts.toArray(new SortBy[] {}); }
} else if (ex instanceof PropertyName) { PropertyName pn = (PropertyName) ex; transformed.add(FF.sort(pn.getPropertyName(), sort.getSortOrder())); } else if (!(ex instanceof Literal)) {
if (sort[i].getSortOrder() == SortOrder.DESCENDING) { order = " DESC"; } else {
} else { String name = sb.getPropertyName().getPropertyName(); boolean ascending = sb.getSortOrder() == SortOrder.ASCENDING; comparators.add(new PropertyComparator(name, ascending));
if (sort[i].getSortOrder() == SortOrder.DESCENDING) { sql.append(" DESC"); } else {
@Override public boolean supportsSorting(final SortBy[] sortAttributes) { if (super.supportsSorting(sortAttributes)) return true; for (int i = 0; i < sortAttributes.length; i++) { SortBy sortBy = sortAttributes[i]; if (SortBy.NATURAL_ORDER == sortBy || SortBy.REVERSE_ORDER == sortBy) { // we do only if we have a non null primary key return !(source.getPrimaryKey() instanceof NullPrimaryKey); } else { PropertyName propertyName = sortBy.getPropertyName(); SortOrder sortOrder = sortBy.getSortOrder(); if (!supportsPropertySorting(propertyName, sortOrder)) { return false; } } } return true; }
String propName = sortBy.getPropertyName().getPropertyName(); String property = mapper.getPropertyPath(propName); orderBy.append(property, sortBy.getSortOrder() == SortOrder.ASCENDING ? 1 : -1);
public Object getProperty(Object object, QName name) throws Exception { SortBy sortBy = (SortBy) object; if (OGC.PropertyName.equals(name)) { return sortBy.getPropertyName(); } if ("SortOrder".equals(name.getLocalPart())) { return sortBy.getSortOrder(); } return null; } }
sort.add( new SortByImpl( filterFac.property(att), sortBy.getSortOrder()));
public static void logSort( SortBy sortBy ) { if ( LOGGER.isDebugEnabled() ) { if ( sortBy != null ) { LOGGER.debug( "SortBy for query is set to [{}]", sortBy.getPropertyName().getPropertyName() + "/" + sortBy.getSortOrder() ); } else { LOGGER.debug( "SortBy for query is set to null" ); } } }
protected int compare( Feature feature1, Feature feature2, SortBy order){ PropertyName name = order.getPropertyName(); Comparable value1 = (Comparable) name.evaluate( feature1 ); Comparable value2 = (Comparable) name.evaluate( feature2 ); if( order.getSortOrder() == SortOrder.ASCENDING ){ return value1.compareTo( value2 ); } else return value2.compareTo( value1 ); } });