@Override public Object getValue() { return NearestVisitor.this.getNearestMatch(); } };
/** * 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); } } }