public static SortBy sortBy(final String propertyName, final boolean ascending) { return factory.sort(propertyName, ascending ? SortOrder.ASCENDING : SortOrder.DESCENDING); }
/** Parses a token of the form 'Field1 {A|D}' into an instnace of {@link SortBy}. */ protected Object parseToken(String token) throws Exception { String[] nameOrder = token.trim().split(" "); String propertyName = nameOrder[0]; SortOrder order = SortOrder.ASCENDING; if (nameOrder.length > 1) { if ("D".equalsIgnoreCase(nameOrder[1]) || "DESC".equalsIgnoreCase(nameOrder[1])) { order = SortOrder.DESCENDING; } } return filterFactory.sort(propertyName, order); } }
SortBy sort = ff.sort(attribute, order); result.add(sort);
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { PropertyName name = (PropertyName) node.getChildValue(PropertyName.class); SortOrder order = (SortOrder) node.getChildValue(SortOrder.class); if (order == null) { order = SortOrder.ASCENDING; } return filterfactory.sort(name.getPropertyName(), order); }
public void testSortBySingleAscending() throws Exception { checkSortByParsing("z", ff.sort("z", SortOrder.ASCENDING)); }
public void testSortBySingleDescending() throws Exception { checkSortByParsing("cat D ", ff.sort("cat", SortOrder.DESCENDING)); }
public void testQueryCapabilitiesSort() throws Exception { FilterFactory ff = dataStore.getFilterFactory(); QueryCapabilities caps = featureSource.getQueryCapabilities(); // check we advertise support for sorting on basic attributes assertTrue( caps.supportsSorting( new SortBy[] {ff.sort(aname("intProperty"), SortOrder.ASCENDING)})); assertTrue( caps.supportsSorting( new SortBy[] {ff.sort(aname("stringProperty"), SortOrder.DESCENDING)})); assertTrue( caps.supportsSorting( new SortBy[] {ff.sort(aname("doubleProperty"), SortOrder.ASCENDING)})); // but we cannot sort geometries assertFalse( caps.supportsSorting( new SortBy[] {ff.sort(aname("geometry"), SortOrder.ASCENDING)})); }
void assertDatesMatch(Filter filter, String... dates) throws Exception { FilterFactory ff = dataStore.getFilterFactory(); Query query = new Query(aname("dates"), filter); query.setSortBy(new SortBy[] {ff.sort(aname("dt"), SortOrder.ASCENDING)}); assertDatesMatch(query, dates); }
peopleAsc = new SortBy[] {ff.sort("PERSONS", SortOrder.ASCENDING)}; peopleDesc = new SortBy[] {ff.sort("PERSONS", SortOrder.DESCENDING)}; dateAsc = new SortBy[] {ff.sort("date", SortOrder.ASCENDING)}; fidAsc = new SortBy[] {SortBy.NATURAL_ORDER}; nullAsc = new SortBy[] {ff.sort("null", SortOrder.ASCENDING)};
public void testMulParamValid() throws Exception { FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); FeatureSource fsView = dataStore.getFeatureSource("riverParam"); // let's change the mul param Query q = new Query(Query.ALL); q.setHints( new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, Collections.singletonMap("mul", "10"))); q.setSortBy(new SortBy[] {ff.sort(aname("mulflow"), SortOrder.ASCENDING)}); try (FeatureIterator fi = fsView.getFeatures(q).features()) { assertTrue(fi.hasNext()); SimpleFeature f = (SimpleFeature) fi.next(); assertEquals(30.0, ((Number) f.getAttribute(aname("mulflow"))).doubleValue(), 0.1); assertTrue(fi.hasNext()); f = (SimpleFeature) fi.next(); assertEquals(45.0, ((Number) f.getAttribute(aname("mulflow"))).doubleValue(), 0.1); } }
public void testTemporalJoin() throws Exception { FilterFactory ff = dataStore.getFilterFactory(); After after = ff.after(ff.property(aname("dt")), ff.property("other." + aname("dt"))); Query q = new Query(tname("dates")); q.getJoins().add(new Join(tname("dates"), after).alias("other")); q.setSortBy(new SortBy[] {ff.sort(aname("dt"), SortOrder.ASCENDING)}); assertDatesMatch(q, "2009-06-28 15:12:41", "2009-09-29 17:54:23", "2009-09-29 17:54:23"); }
/** * Adds the property. * * @param propertyName the property name */ public void addProperty(String propertyName) { dataList.add((SortByImpl) ff.sort(propertyName, DEFAULT_SORT_ORDER)); this.fireTableDataChanged(); if (parentObj != null) { parentObj.sortOrderUpdated(); } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { PropertyName name = (PropertyName) node.getChildValue(PropertyName.class); SortOrder order = (SortOrder) node.getChildValue(SortOrder.class); if (order == null) { order = SortOrder.ASCENDING; } return filterfactory.sort(name.getPropertyName(), order); }
public void testGetFeaturesWithOffset() throws Exception { Query q = new Query(featureSource.getSchema().getTypeName()); q.setSortBy( new SortBy[] { dataStore.getFilterFactory().sort(aname("intProperty"), SortOrder.ASCENDING) }); q.setStartIndex(2); SimpleFeatureCollection features = featureSource.getFeatures(q); // check size assertEquals(1, features.size()); // check actual iteration try (SimpleFeatureIterator it = features.features()) { assertTrue(it.hasNext()); SimpleFeature f = it.next(); ReferencedEnvelope fe = ReferencedEnvelope.reference(f.getBounds()); assertEquals(2, ((Number) f.getAttribute(aname("intProperty"))).intValue()); assertFalse(it.hasNext()); // assertEquals(fe, features.getBounds()); assertTrue(areReferencedEnvelopesEqual(fe, features.getBounds())); } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { PropertyName name = (PropertyName) node.getChildValue(PropertyName.class); SortOrder order = (SortOrder) node.getChildValue(SortOrder.class); if (order == null) { order = SortOrder.ASCENDING; } return filterfactory.sort(name.getPropertyName(), order); } }
void doTestSimpleJoinWithSort(boolean exposePrimaryKeys) throws Exception { dataStore.setExposePrimaryKeyColumns(exposePrimaryKeys); FilterFactory ff = dataStore.getFilterFactory(); Filter j = ff.equal(ff.property(aname("stringProperty")), ff.property(aname("name")), true); Query q = new Query(tname("ft1")); q.getJoins().add(new Join(tname("ftjoin"), j)); q.setSortBy(new SortBy[] {ff.sort(aname("intProperty"), SortOrder.DESCENDING)}); SimpleFeatureCollection features = dataStore.getFeatureSource(tname("ft1")).getFeatures(q); try (SimpleFeatureIterator it = features.features()) { assertTrue(it.hasNext()); assertEquals("two", it.next().getAttribute(aname("stringProperty"))); assertTrue(it.hasNext()); assertEquals("one", it.next().getAttribute(aname("stringProperty"))); assertTrue(it.hasNext()); assertEquals("zero", it.next().getAttribute(aname("stringProperty"))); } }
void doTestSimpleJoinWithLimitOffset(boolean exposePrimaryKeys) throws Exception { dataStore.setExposePrimaryKeyColumns(exposePrimaryKeys); FilterFactory ff = dataStore.getFilterFactory(); Filter j = ff.equal(ff.property(aname("stringProperty")), ff.property(aname("name")), true); Query q = new Query(tname("ft1")); q.getJoins().add(new Join(tname("ftjoin"), j)); q.setFilter(ff.greater(ff.property(aname("intProperty")), ff.literal(0))); q.setStartIndex(1); q.setSortBy(new SortBy[] {ff.sort(aname("intProperty"), SortOrder.ASCENDING)}); SimpleFeatureCollection features = dataStore.getFeatureSource(tname("ft1")).getFeatures(q); assertEquals(1, features.size()); try (SimpleFeatureIterator it = features.features()) { assertTrue(it.hasNext()); SimpleFeature f = it.next(); assertEquals("two", f.getAttribute(aname("stringProperty"))); SimpleFeature g = (SimpleFeature) f.getAttribute(aname("ftjoin")); assertEquals("two", g.getAttribute(aname("name"))); } }
public void testGetFeaturesWithSort() throws Exception { FilterFactory ff = dataStore.getFilterFactory(); SortBy sort = ff.sort(aname("stringProperty"), SortOrder.ASCENDING); Query query = new Query(); query.setSortBy(new SortBy[] {sort}); sort = ff.sort(aname("stringProperty"), SortOrder.DESCENDING); query.setSortBy(new SortBy[] {sort}); features = featureSource.getFeatures(query);