/** * Calculate nearest using {@link NearestVisitor}. * * @param Collection collection to calculate the maximum * @param Expression Single Expression argument * @param value Attribute value used for nearest search * @return An object containing the maximum value of the attributes * @throws IllegalFilterException * @throws IOException */ static Object near(SimpleFeatureCollection collection, Expression expression, Object value) throws IllegalFilterException, IOException { NearestVisitor visitor = new NearestVisitor(expression, value); collection.accepts(visitor, new NullProgressListener()); return visitor.getNearestMatch(); }
private void testNearest( SimpleFeatureCollection fc, String attributeName, Object target, Object... validResults) throws IOException { PropertyName expr = ff.property(attributeName); NearestVisitor visitor = new NearestVisitor(expr, target); fc.accepts(visitor, null); Object nearestMatch = visitor.getNearestMatch(); if (validResults.length == 0) { assertNull(nearestMatch); } else { boolean found = false; for (Object object : validResults) { found |= object != null ? (object.equals(nearestMatch)) : nearestMatch == null; } assertTrue( "Could match nearest " + nearestMatch + " among valid values " + Arrays.asList(validResults), found); } } }
NearestVisitor vis = new NearestVisitor(ff.property("bar"), Integer.valueOf(0)); verify(delegate); vis = new NearestVisitor(ff.property("baz"), "abc");
public @Test void handleNearestVisitorNotIndexed() { final int valueToMatch = 2050; Integer expectedResult = Integer.valueOf(2000); testVisitor(new NearestVisitor(ff.property("ip"), valueToMatch), expectedResult); }
/** * @see GeogigFeatureVisitorHandler */ public @Test void handleNearestVisitorMaterializedAttribute() { NodeRef typeRef = pointsSource.delegate.getTypeRef(); createIndex(typeRef, Collections.singletonList("ip")); final int valueToMatch = 2050; Integer expectedResult = Integer.valueOf(2000); testVisitor(new NearestVisitor(ff.property("ip"), valueToMatch), expectedResult); }
@Override public Object getDefaultValue( ResourceInfo resource, String dimensionName, DimensionInfo dimension, Class clz) { String attrName = dimension.getAttribute(); Class<?> attrType = String.class; if (resource instanceof FeatureTypeInfo) { List<AttributeTypeInfo> attrTypes; try { attrTypes = ((FeatureTypeInfo) resource).attributes(); for (AttributeTypeInfo attr : attrTypes) { if (attr.getName().equals(attrName)) { attrType = attr.getBinding(); break; } } } catch (IOException e) { } } final FeatureCalc nearest = new NearestVisitor(ff.property(dimension.getAttribute()), this.toMatch); CalcResult res = getCalculatedResult((FeatureTypeInfo) resource, dimension, nearest); if (res.equals(CalcResult.NULL_RESULT)) { return null; } else { return Converters.convert(res.getValue(), clz); } }
private FeatureCalc getFeatureCalcForStrategy( DimensionDefaultValueSelectionStrategy delegateStrategy, DimensionDescriptor dd) { String sa = dd.getStartAttribute(); String ea = dd.getEndAttribute(); if (delegateStrategy instanceof CoverageMaximumValueSelectionStrategyImpl) { if (ea != null) { return new MaxVisitor(ea); } else { return new MaxVisitor(sa); } } else if (delegateStrategy instanceof CoverageMinimumValueSelectionStrategyImpl) { return new MinVisitor(sa); } else if (delegateStrategy instanceof CoverageNearestValueSelectionStrategyImpl) { CoverageNearestValueSelectionStrategyImpl impl = (CoverageNearestValueSelectionStrategyImpl) delegateStrategy; Object targetValue = impl.getTargetValue(); return new NearestVisitor(ff.property(sa), targetValue); } else { throw new ServiceException( "Don't konw how to restrict the domain for strategy " + delegateStrategy); } }
|| ((Range) value).getMinValue().equals(((Range) value).getMaxValue()))) { Date date = (Date) (value instanceof Range ? ((Range) value).getMinValue() : value); NearestVisitor visitor = new NearestVisitor(attribute, date); Filter filter = Filter.INCLUDE; if (acceptableRange != null) {