GeoHashGrid { Number pluckMetricValue(Map<String, Object> bucket, String metricKey, String valueKey) { Number value; if (null == metricKey || metricKey.trim().length() == 0) { value = pluckDocCount(bucket); } else { if (!bucket.containsKey(metricKey)) { LOGGER.warning("Unable to pluck metric, bucket does not contain required key:" + metricKey); throw new IllegalArgumentException(); } @SuppressWarnings("unchecked") Map<String,Object> metric = (Map<String,Object>) bucket.get(metricKey); if (!metric.containsKey(valueKey)) { LOGGER.warning("Unable to pluck value, metric does not contain required key:" + valueKey); throw new IllegalArgumentException(); } value = (Number) metric.get(valueKey); } return value; } GeoHashGrid(); void initalize(ReferencedEnvelope srcEnvelope, SimpleFeatureCollection features); GridCoverage2D toGridCoverage2D(); void setParams(List<String> params); void setEmptyCellValue(Float value); double getCellWidth(); double getCellHeight(); Envelope getEnvelope(); ReferencedEnvelope getBoundingBox(); float[][] getGrid(); void setScale(RasterScale scale); static final String BUCKET_NAME_KEY; static final String BUCKETS_KEY; static final String DOC_COUNT_KEY; static final String VALUE_KEY; }
@Test public void testPluckMetricValue_docCount() { Number plucked = this.geohashGrid.pluckMetricValue(METRIC_BUCKET, null, null); assertEquals(DOC_COUNT, plucked); plucked = this.geohashGrid.pluckMetricValue(METRIC_BUCKET, "", null); assertEquals(DOC_COUNT, plucked); }
@Test(expected=IllegalArgumentException.class) public void testPluckMetricValue_canNotFindMetricKey() { this.geohashGrid.pluckMetricValue(METRIC_BUCKET, "noGonnaFindMe", VALUE_KEY); }
@Test(expected=IllegalArgumentException.class) public void testPluckMetricValue_canNotFindValueKey() { this.geohashGrid.pluckMetricValue(METRIC_BUCKET, METRIC_KEY, "noGonnaFindMe"); }
@Test public void testPluckMetricValue() { Number plucked = this.geohashGrid.pluckMetricValue(METRIC_BUCKET, METRIC_KEY, VALUE_KEY); assertEquals(VALUE, plucked); }