NearbyFF extends FunctionBase4 { @Override public NodeValue exec(NodeValue v1, NodeValue v2, NodeValue v3, NodeValue v4) { try { GeometryWrapper geometry1 = GeometryWrapper.extract(v1, GeometryLiteralIndex.GeometryIndex.PRIMARY); GeometryWrapper geometry2 = GeometryWrapper.extract(v2, GeometryLiteralIndex.GeometryIndex.SECONDARY); if (!v3.isNumber()) { throw new ExprEvalException("Not a number: " + FmtUtils.stringForNode(v3.asNode())); } if (!(v4.isIRI() || v4.isString())) { throw new ExprEvalException("Not an IRI or String: " + FmtUtils.stringForNode(v4.asNode())); } double radius = v3.getDouble(); String unitsURI; if (v4.isIRI()) { unitsURI = v4.asNode().getURI(); } else { unitsURI = v4.asString(); } boolean result = relate(geometry1, geometry2, radius, unitsURI); return NodeValue.makeBoolean(result); } catch (DatatypeFormatException ex) { throw new ExprEvalException(ex.getMessage(), ex); } }  @Override NodeValue exec(NodeValue v1, NodeValue v2, NodeValue v3, NodeValue v4); static final boolean relate(GeometryWrapper geometry1, GeometryWrapper geometry2, double radius, String unitsURI);  }
@Test public void testExec() { NodeValue v1 = NodeValue.makeNode("<http: NodeValue v2 = NodeValue.makeNode("<http: NodeValue v3 = NodeValue.makeFloat(50); NodeValue v4 = NodeValue.makeNode(NodeFactory.createURI(Unit_URI.KILOMETER_URL)); NearbyFF instance = new NearbyFF(); NodeValue expResult = NodeValue.makeBoolean(true); NodeValue result = instance.exec(v1, v2, v3, v4); assertEquals(expResult, result); }
@Test public void testExec2() { NodeValue v1 = NodeValue.makeNode("<http: NodeValue v2 = NodeValue.makeNode("<http: NodeValue v3 = NodeValue.makeFloat(50); NodeValue v4 = NodeValue.makeString(Unit_URI.KILOMETER_URL); NearbyFF instance = new NearbyFF(); NodeValue expResult = NodeValue.makeBoolean(true); NodeValue result = instance.exec(v1, v2, v3, v4); assertEquals(expResult, result); }
@Test public void testExec_Paris_London() { NodeValue v1 = SpatialIndexTestData.PARIS_GEOMETRY_WRAPPER.asNodeValue(); NodeValue v2 = SpatialIndexTestData.LONDON_GEOMETRY_WRAPPER.asNodeValue(); NodeValue v3 = NodeValue.makeFloat(345); NodeValue v4 = NodeValue.makeString(Unit_URI.KILOMETER_URL); NearbyFF instance = new NearbyFF(); NodeValue expResult = NodeValue.makeBoolean(true); NodeValue result = instance.exec(v1, v2, v3, v4); assertEquals(expResult, result); }
@Test public void testExec_Paris_London_fail() { NodeValue v1 = SpatialIndexTestData.PARIS_GEOMETRY_WRAPPER.asNodeValue(); NodeValue v2 = SpatialIndexTestData.LONDON_GEOMETRY_WRAPPER.asNodeValue(); NodeValue v3 = NodeValue.makeFloat(200); NodeValue v4 = NodeValue.makeString(Unit_URI.KILOMETER_URL); NearbyFF instance = new NearbyFF(); NodeValue expResult = NodeValue.makeBoolean(false); NodeValue result = instance.exec(v1, v2, v3, v4); assertEquals(expResult, result); }
@Test public void testExec_fail() { NodeValue v1 = NodeValue.makeNode("<http: NodeValue v2 = NodeValue.makeNode("<http: NodeValue v3 = NodeValue.makeFloat(50); NodeValue v4 = NodeValue.makeNode(NodeFactory.createURI(Unit_URI.KILOMETER_URL)); NearbyFF instance = new NearbyFF(); NodeValue expResult = NodeValue.makeBoolean(false); NodeValue result = instance.exec(v1, v2, v3, v4); assertEquals(expResult, result); }
@Test(expected = ExprEvalException.class) public void testExec_pos0_fail() { NodeValue v1 = NodeValue.makeString("<http: NodeValue v2 = NodeValue.makeNode("<http: NodeValue v3 = NodeValue.makeFloat(50); NodeValue v4 = NodeValue.makeNode(NodeFactory.createURI(Unit_URI.KILOMETER_URL)); NearbyFF instance = new NearbyFF(); NodeValue expResult = NodeValue.makeBoolean(true); NodeValue result = instance.exec(v1, v2, v3, v4); }
@Test(expected = ExprEvalException.class) public void testExec_pos1_fail() { NodeValue v1 = NodeValue.makeNode("<http: NodeValue v2 = NodeValue.makeString("<http: NodeValue v3 = NodeValue.makeFloat(50); NodeValue v4 = NodeValue.makeNode(NodeFactory.createURI(Unit_URI.KILOMETER_URL)); NearbyFF instance = new NearbyFF(); NodeValue expResult = NodeValue.makeBoolean(true); NodeValue result = instance.exec(v1, v2, v3, v4); }
@Test(expected = ExprEvalException.class) public void testExec_pos2_fail() { NodeValue v1 = NodeValue.makeNode("<http: NodeValue v2 = NodeValue.makeNode("<http: NodeValue v3 = NodeValue.makeString("50"); NodeValue v4 = NodeValue.makeNode(NodeFactory.createURI(Unit_URI.KILOMETER_URL)); NearbyFF instance = new NearbyFF(); NodeValue expResult = NodeValue.makeBoolean(true); NodeValue result = instance.exec(v1, v2, v3, v4); }
@Test(expected = ExprEvalException.class) public void testExec_pos3_fail() { NodeValue v1 = NodeValue.makeNode("<http: NodeValue v2 = NodeValue.makeNode("<http: NodeValue v3 = NodeValue.makeFloat(50); NodeValue v4 = NodeValue.makeInteger(20); NearbyFF instance = new NearbyFF(); NodeValue expResult = NodeValue.makeBoolean(true); NodeValue result = instance.exec(v1, v2, v3, v4); }