/** * Calculate maximum (using FeatureCalc) - only one parameter is used. * * @param collection collection to calculate the maximum * @param expression Single Expression argument * @return An object containing the maximum value of the attributes * @throws IllegalFilterException * @throws IOException */ static CalcResult calculateMax(SimpleFeatureCollection collection, Expression expression) throws IllegalFilterException, IOException { MaxVisitor maxVisitor = new MaxVisitor(expression); collection.accepts(maxVisitor, null); return maxVisitor.getResult(); }
featureCollection.accepts(maxVisit, progress); if (progress.isCanceled()) return null; globalMax = (Comparable) maxVisit.getResult().getValue();
public void testBadMerge() throws IllegalFilterException, IOException { // count + max = boom! CountVisitor countVisitor = new CountVisitor(); countVisitor.setValue(8); CalcResult countResult = countVisitor.getResult(); MaxVisitor maxVisitor = new MaxVisitor((Expression) null); maxVisitor.setValue(new Double(99)); CalcResult maxResult = maxVisitor.getResult(); try { CalcResult boomResult = maxResult.merge(countResult); fail(); // merge should throw an exception } catch (Exception e) { assertEquals("Parameter is not a compatible type", e.getMessage()); } }
int value1 = maxVisitor.getResult().toInt(); assertEquals(3, value1); double value2 = maxVisitor2.getResult().toDouble(); assertEquals((double) 4.5, value2, 0); CalcResult maxResult1 = (MaxResult) maxVisitor.getResult(); CalcResult maxResult2 = (MaxResult) maxVisitor2.getResult(); CalcResult maxResult3 = (MaxResult) maxResult1.merge(maxResult2); assertEquals((double) 4.5, maxResult3.toDouble(), 0); maxResult1 = maxVisitor.getResult(); maxResult7 = maxResult7.merge(maxResult1); assertEquals(544, maxResult7.toDouble(), 0); maxResult1 = maxVisitor.getResult(); maxResult7 = maxResult7.merge(maxResult1); assertEquals(6453, maxResult7.toDouble(), 0); assertEquals(CalcResult.NULL_RESULT, maxVisitor.getResult()); assertSame(maxResult2, maxVisitor.getResult().merge(maxResult2)); assertSame(maxResult2, maxResult2.merge(maxVisitor.getResult()));
public void testMax() throws Exception { FilterFactory ff = dataStore.getFilterFactory(); PropertyName p = ff.property(aname("doubleProperty")); MaxVisitor v = new MyMaxVisitor(p); dataStore.getFeatureSource(tname("ft1")).accepts(Query.ALL, v, null); assertFalse(visited); assertEquals(2.2, v.getResult().toDouble(), 0.01); }
MaxVisitor max = new MaxVisitor(attribute); handleVisitor(qBelow, max); Comparable maxBelow = (Comparable) max.getResult().getValue(); if (maxBelow != null && maxBelow.equals(targetValue)) {
public void testMaxWithFilter() throws Exception { FilterFactory ff = dataStore.getFilterFactory(); PropertyName p = ff.property(aname("doubleProperty")); MaxVisitor v = new MyMaxVisitor(p); Filter f = ff.less(ff.property(aname("doubleProperty")), ff.literal(2)); Query q = new Query(tname("ft1"), f); dataStore.getFeatureSource(tname("ft1")).accepts(q, v, null); assertFalse(visited); assertEquals(1.1, v.getResult().toDouble(), 0.01); }
/** * Calculate maximum (using FeatureCalc) - only one parameter is used. * * @param collection collection to calculate the maximum * @param expression Single Expression argument * * @return An object containing the maximum value of the attributes * * @throws IllegalFilterException * @throws IOException */ static CalcResult calculateMax(SimpleFeatureCollection collection, Expression expression) throws IllegalFilterException, IOException { MaxVisitor maxVisitor = new MaxVisitor(expression); collection.accepts(maxVisitor, null); return maxVisitor.getResult(); }
public void testMaxWithLimitOffset() throws Exception { if (!dataStore.getSQLDialect().isLimitOffsetSupported()) { return; } FilterFactory ff = dataStore.getFilterFactory(); PropertyName p = ff.property(aname("doubleProperty")); MaxVisitor v = new MyMaxVisitor(p); Query q = new Query(tname("ft1")); q.setStartIndex(0); q.setMaxFeatures(2); dataStore.getFeatureSource(tname("ft1")).accepts(q, v, null); assertFalse(visited); assertEquals(1.1, v.getResult().toDouble(), 0.01); }
/** * Calculate maximum (using FeatureCalc) - only one parameter is used. * * @param collection collection to calculate the maximum * @param expression Single Expression argument * * @return An object containing the maximum value of the attributes * * @throws IllegalFilterException * @throws IOException */ public static CalcResult calculateMax(FeatureCollection collection, Expression expression) throws IllegalFilterException, IOException { MaxVisitor maxVisitor = new MaxVisitor(expression); collection.accepts(maxVisitor, null); return maxVisitor.getResult(); }
MaxVisitor transformedVisitor = new MaxVisitor(transformedExpression); delegateVisitor(transformedVisitor, progress); original.setValue(transformedVisitor.getResult().getValue()); } else if (visitor instanceof UniqueVisitor) { UniqueVisitor original = (UniqueVisitor) visitor;
private Object calculate(FeatureCollection featureCollection) { int classNum = getClasses(); Comparable globalMin; Comparable globalMax; try { MinVisitor minVisit = new MinVisitor(getExpression()); if (progress == null) progress = new NullProgressListener(); featureCollection.accepts(minVisit, progress); if (progress.isCanceled()) return null; globalMin = (Comparable) minVisit.getResult().getValue(); MaxVisitor maxVisit = new MaxVisitor(getExpression()); featureCollection.accepts(maxVisit, progress); if (progress.isCanceled()) return null; globalMax = (Comparable) maxVisit.getResult().getValue(); if ((globalMin instanceof Number) && (globalMax instanceof Number)) { return calculateNumerical(classNum, globalMin, globalMax); } else { return calculateNonNumerical(classNum, featureCollection); } } catch (IllegalFilterException e) { // accepts exploded LOGGER.log(Level.SEVERE, "EqualIntervalFunction calculate(FeatureCollection) failed", e); return null; } catch (IOException e) { // getResult().getValue() exploded LOGGER.log(Level.SEVERE, "EqualIntervalFunction calculate(FeatureCollection) failed", e); return null; } }
private RangedClassifier calculate(SimpleFeatureCollection featureCollection) { int classNum = getClasses(); Comparable globalMin; Comparable globalMax; try { MinVisitor minVisit = new MinVisitor(getExpression()); if (progress == null) progress = new NullProgressListener(); featureCollection.accepts(minVisit, progress); if (progress.isCanceled()) return null; globalMin = (Comparable) minVisit.getResult().getValue(); MaxVisitor maxVisit = new MaxVisitor(getExpression()); featureCollection.accepts(maxVisit, progress); if (progress.isCanceled()) return null; globalMax = (Comparable) maxVisit.getResult().getValue(); if ((globalMin instanceof Number) && (globalMax instanceof Number)) { return calculateNumerical(classNum, globalMin, globalMax); } else { return calculateNonNumerical(classNum, featureCollection); } } catch (IllegalFilterException e) { // accepts exploded LOGGER.log(Level.SEVERE, "EqualIntervalFunction calculate(SimpleFeatureCollection) failed", e); return null; } catch (IOException e) { // getResult().getValue() exploded LOGGER.log(Level.SEVERE, "EqualIntervalFunction calculate(SimpleFeatureCollection) failed", e); return null; } }
protected void updateAttributeStats(DataAttribute attribute) throws IOException { FeatureTypeInfo featureType = GeoServerApplication.get().getCatalog().getFeatureType(featureTypeId); FeatureSource<?, ?> fs = featureType.getFeatureSource(null, null); // check we can compute min and max PropertyDescriptor pd = fs.getSchema().getDescriptor(attribute.getName()); Class<?> binding = pd.getType().getBinding(); if (pd == null || !Comparable.class.isAssignableFrom(binding) || Geometry.class.isAssignableFrom(binding)) { return; } // grab the feature collection and run the min/max visitors (this will move the // query to the dbms in case of such data source) Query q = new Query(); q.setPropertyNames(new String[] {attribute.getName()}); FeatureCollection<?, ?> fc = fs.getFeatures(q); MinVisitor minVisitor = new MinVisitor(attribute.getName()); MaxVisitor maxVisitor = new MaxVisitor(attribute.getName()); fc.accepts(minVisitor, null); fc.accepts(maxVisitor, null); Object min = minVisitor.getResult().getValue(); attribute.setMin(Converters.convert(min, String.class)); Object max = maxVisitor.getResult().getValue(); attribute.setMax(Converters.convert(max, String.class)); }
new MaxVisitor(endAttribute == null ? attribute : endAttribute); lowers.accepts(lowersVisitor, null); Comparable maxOfSmallers = (Comparable) lowersVisitor.getResult().getValue();