List of usage examples for org.apache.lucene.spatial.query SpatialArgs validate
public void validate() throws IllegalArgumentException
From source file:org.apache.blur.analysis.type.spatial.SpatialArgsParser.java
License:Apache License
/** * Parses a string such as "Intersects(-10,20,-8,22) distErrPct=0.025". * //from ww w .j a va 2 s. c o m * @param v * The string to parse. Mandatory. * @param shapeReadWriter * The spatial shapeReadWriter. Mandatory. * @return Not null. * @throws IllegalArgumentException * If there is a problem parsing the string. * @throws InvalidShapeException * Thrown from {@link ShapeReadWriter#readShape(String)} */ public static SpatialArgs parse(String v, ShapeReadWriter<SpatialContext> shapeReadWriter) throws IllegalArgumentException, InvalidShapeException { int idx = v.indexOf('('); int edx = v.lastIndexOf(')'); if (idx < 0 || idx > edx) { throw new IllegalArgumentException("missing parens: " + v, null); } SpatialOperation op = SpatialOperation.get(v.substring(0, idx).trim()); String body = v.substring(idx + 1, edx).trim(); if (body.length() < 1) { throw new IllegalArgumentException("missing body : " + v, null); } Shape shape = shapeReadWriter.readShape(body); SpatialArgs args = new SpatialArgs(op, shape); if (v.length() > (edx + 1)) { body = v.substring(edx + 1).trim(); if (body.length() > 0) { Map<String, String> aa = parseMap(body); args.setDistErrPct(readDouble(aa.remove(DIST_ERR_PCT))); args.setDistErr(readDouble(aa.remove(DIST_ERR))); if (!aa.isEmpty()) { throw new IllegalArgumentException("unused parameters: " + aa, null); } } } args.validate(); return args; }