public CalcResult getResult() { final List<CalcResult> results = new ArrayList<CalcResult>(); for (FeatureCalc delegate : delegates) { results.add(delegate.getResult()); } return new AbstractCalcResult() { @Override public Object getValue() { return results; } }; }
/** * We apply a copy of the aggregation visitor to each feature collection. * * @return the result of applying the aggregation visitor to eac feature collection */ Map<List<Object>, CalcResult> visit() { Map<List<Object>, CalcResult> results = new HashMap<>(); for (Map.Entry<List<Object>, FeatureCalc> entry : groupByIndexes.entrySet()) { // we add the aggregation visitor to the results results.put(entry.getKey(), entry.getValue().getResult()); } return results; } }
public static Object calc(SimpleFeatureCollection collection, FeatureCalc calculator) { accept(collection, calculator); return calculator.getResult(); } }
CalcResult tempRes = visitor.getResult(); if (tempRes == null) { throw new IllegalStateException("Unable to compute extrema value:" + extrema);
private Object findDefaultValue(Query query, String attribute) { FeatureCalc aggFunc; switch (NetCDFUtilities.getParameterBehaviour(attribute)) { case MAX: aggFunc = new MaxVisitor(attribute); break; case MIN: aggFunc = new MinVisitor(attribute); break; default: return null; } try { request.source.reader.getCatalog().computeAggregateFunction(query, aggFunc); return aggFunc.getResult().getValue(); } catch (IOException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); return null; } }
private Object calculate(SimpleFeatureCollection featureCollection) { FeatureCalc quantityVisitor = getListVisitor(); if (progress == null) progress = new NullProgressListener(); try { featureCollection.accepts(quantityVisitor, progress); } catch (IOException e) { LOGGER.log( Level.SEVERE, "QuantileFunction calculate(SimpleFeatureCollection) failed", e); return null; } if (progress.isCanceled()) return null; CalcResult calcResult = quantityVisitor.getResult(); if (calcResult == null || calcResult == CalcResult.NULL_RESULT) { return null; } List[] bin = (List[]) calcResult.getValue(); // generate the min and max values, and round off if applicable/necessary Comparable globalMin = (Comparable) bin[0].toArray()[0]; Object lastBin[] = bin[bin.length - 1].toArray(); if (lastBin.length == 0) { return null; } Comparable globalMax = (Comparable) lastBin[lastBin.length - 1]; if ((globalMin instanceof Number) && (globalMax instanceof Number)) { return calculateNumerical(bin, globalMin, globalMax); } else { return calculateNonNumerical(bin, globalMin, globalMax); } }
final FeatureCalc calc = visitors.get(i); features.accepts(calc, new NullProgressListener()); results.put(functionList.get(i), (Number) calc.getResult().getValue());
@Test public void onlyNotNulls() throws Exception { int idx = 1; for (T value : values) { featureCollection.add( featureBuilder.buildFeature("f" + idx, new Object[] {value, idx})); ++idx; } FeatureCalc calc = createVisitor(0, featureType); featureCollection.accepts(calc, null); Object value = calc.getResult().getValue(); assertEquals(expectedValue, value); assertSame(expectedValue.getClass(), value.getClass()); }
@Test public void emptyCollection() throws Exception { FeatureCalc calc = createVisitor(0, featureType); featureCollection.accepts(calc, null); assertNull(calc.getResult().getValue()); }
@Test public void mixed() throws Exception { int idx = 1; for (T value : values) { featureCollection.add( featureBuilder.buildFeature("f" + idx, new Object[] {value, idx})); ++idx; featureCollection.add(featureBuilder.buildFeature("f" + idx, new Object[] {null, idx})); ++idx; } FeatureCalc calc = createVisitor(0, featureType); featureCollection.accepts(calc, null); Object value = calc.getResult().getValue(); assertEquals(expectedValue, value); assertSame(expectedValue.getClass(), value.getClass()); } }
public CalcResult getResult() { final List<CalcResult> results = new ArrayList<CalcResult>(); for (FeatureCalc delegate : delegates) { results.add(delegate.getResult()); } return new AbstractCalcResult() { @Override public Object getValue() { return results; } }; }
public static Object calc(SimpleFeatureCollection collection, FeatureCalc calculator) { accept(collection, calculator); return calculator.getResult(); } }
public static Object calc(FeatureCollection collection, FeatureCalc calculator) { accept(collection, calculator); return calculator.getResult(); } }
@Test public void onlyNulls() throws Exception { featureCollection.add(featureBuilder.buildFeature("f1", new Object[] {null, 1})); featureCollection.add(featureBuilder.buildFeature("f2", new Object[] {null, 2})); featureCollection.add(featureBuilder.buildFeature("f3", new Object[] {null, 3})); FeatureCalc calc = createVisitor(0, featureType); featureCollection.accepts(calc, null); assertNull(calc.getResult().getValue()); }
/** * Extract the time domain extrema. * * @param metadataName a {@link String} either TIME_DOMAIN_MAXIMUM or TIME_DOMAIN_MINIMUM. * * @return either TIME_DOMAIN_MAXIMUM or TIME_DOMAIN_MINIMUM as a {@link String}. */ private String extractTimeExtrema(String metadataName) { if(timeAttribute==null){ if(LOGGER.isLoggable(Level.INFO)) LOGGER.info("Requesting extrema on attribute "+metadataName+" when no such an attribute is supported!"); return null; } try { final FeatureCalc visitor = createExtremaQuery(metadataName,rasterManager.timeAttribute); // check result final Date result=(Date) visitor.getResult().getValue(); final SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); df.setTimeZone(UTC_TZ); return df.format(result)+"Z";//ZULU } catch (IOException e) { if(LOGGER.isLoggable(Level.WARNING)) LOGGER.log(Level.WARNING,"Unable to compute extrema for TIME_DOMAIN",e); return null; } }
/** * Extract the elevation domain extrema. * * @param metadataName a {@link String} either ELEVATION_DOMAIN_MAXIMUM or ELEVATION_DOMAIN_MINIMUM. * * @return either ELEVATION_DOMAIN_MAXIMUM or ELEVATION_DOMAIN_MINIMUM as a {@link String}. */ private String extractElevationExtrema(String metadataName) { if(elevationAttribute==null){ if(LOGGER.isLoggable(Level.INFO)) LOGGER.info("Requesting extrema on attribute "+metadataName+" when no such an attribute is supported!"); return null; } try { final FeatureCalc visitor = createExtremaQuery(metadataName,rasterManager.elevationAttribute); // check result final Object result = visitor.getResult().getValue(); if(result instanceof Number) { return result.toString(); } else { return null; } } catch (IOException e) { if(LOGGER.isLoggable(Level.WARNING)) LOGGER.log(Level.WARNING,"Unable to compute extrema for ELEVATION_DOMAIN",e); return null; } }
/** * Return the result of iterating through the dimension collection of the given dimension using * given calculator as the attribute value calculator. * * @param typeInfo * @param dimension * @param calculator */ protected CalcResult getCalculatedResult( FeatureTypeInfo typeInfo, DimensionInfo dimension, FeatureCalc calculator) { CalcResult retval = null; try { FeatureCollection<?, ?> dimensionCollection = getDimensionCollection(typeInfo, dimension); if (dimensionCollection == null) { throw new ServiceException( "No dimension collection given, cannot select default value for dimension based on attribute" + dimension.getAttribute()); } dimensionCollection.accepts(calculator, null); retval = calculator.getResult(); } catch (IOException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } return retval; }
private Object findDefaultValue(Query query, String attribute) { FeatureCalc aggFunc; switch (NetCDFUtilities.getParameterBehaviour(attribute)) { case MAX: aggFunc = new MaxVisitor(attribute); break; case MIN: aggFunc = new MinVisitor(attribute); break; default: return null; } try { request.source.reader.getCatalog().computeAggregateFunction(query, aggFunc); return aggFunc.getResult().getValue(); } catch (IOException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); return null; } }
final FeatureCalc calc = visitors.get(i); features.accepts(calc, new NullProgressListener()); results.put(functionList.get(i), (Number) calc.getResult().getValue());
private void testVisitor(FeatureCalc visitor, Object expectedResult) { GeogigFeatureVisitorHandler.clearCache(); boolean handled = pointsSource.handleVisitor(Query.ALL, visitor); assertTrue(handled); CalcResult res = visitor.getResult(); assertEquals(expectedResult, res.getValue()); // run again handled = pointsSource.handleVisitor(Query.ALL, visitor); assertTrue(handled); res = visitor.getResult(); assertEquals(expectedResult, res.getValue()); }