You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2012/09/22 21:12:05 UTC
svn commit: r1388872 - in /lucene/dev/trunk/lucene/spatial/src:
java/org/apache/lucene/spatial/ java/org/apache/lucene/spatial/bbox/
java/org/apache/lucene/spatial/vector/ test/org/apache/lucene/spatial/vector/
Author: dsmiley
Date: Sat Sep 22 19:12:04 2012
New Revision: 1388872
URL: http://svn.apache.org/viewvc?rev=1388872&view=rev
Log:
LUCENE-4413 Standardize on throwing UnsupportedOperationException for a shape the strategy doesn't support. Document it.
Modified:
lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java
lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java
lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java
lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java
Modified: lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java?rev=1388872&r1=1388871&r2=1388872&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java Sat Sep 22 19:12:04 2012
@@ -96,6 +96,7 @@ public abstract class SpatialStrategy {
* since it doesn't use it.
*
* @return Not null nor will it have null elements.
+ * @throws UnsupportedOperationException if given a shape incompatible with the strategy
*/
public abstract Field[] createIndexableFields(Shape shape);
@@ -111,6 +112,10 @@ public abstract class SpatialStrategy {
* and {@link Shape} from the supplied {@code args}.
* The default implementation is
* <pre>return new ConstantScoreQuery(makeFilter(args));</pre>
+ *
+ * @throws UnsupportedOperationException If the strategy does not support the shape in {@code args}
+ * @throws org.apache.lucene.spatial.query.UnsupportedSpatialOperation If the strategy does not support the {@link
+ * org.apache.lucene.spatial.query.SpatialOperation} in {@code args}.
*/
public ConstantScoreQuery makeQuery(SpatialArgs args) {
return new ConstantScoreQuery(makeFilter(args));
@@ -124,6 +129,10 @@ public abstract class SpatialStrategy {
* {@link #makeQuery(org.apache.lucene.spatial.query.SpatialArgs)}
* then this method could be simply:
* <pre>return new QueryWrapperFilter(makeQuery(args).getQuery());</pre>
+ *
+ * @throws UnsupportedOperationException If the strategy does not support the shape in {@code args}
+ * @throws org.apache.lucene.spatial.query.UnsupportedSpatialOperation If the strategy does not support the {@link
+ * org.apache.lucene.spatial.query.SpatialOperation} in {@code args}.
*/
public abstract Filter makeFilter(SpatialArgs args);
Modified: lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java?rev=1388872&r1=1388871&r2=1388872&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java Sat Sep 22 19:12:04 2012
@@ -95,7 +95,7 @@ public class BBoxStrategy extends Spatia
public Field[] createIndexableFields(Shape shape) {
if (shape instanceof Rectangle)
return createIndexableFields((Rectangle)shape);
- throw new IllegalArgumentException("Can only index Rectangle, not " + shape);
+ throw new UnsupportedOperationException("Can only index Rectangle, not " + shape);
}
public Field[] createIndexableFields(Rectangle bbox) {
@@ -150,7 +150,7 @@ public class BBoxStrategy extends Spatia
private Query makeSpatialQuery(SpatialArgs args) {
Shape shape = args.getShape();
if (!(shape instanceof Rectangle))
- throw new IllegalArgumentException("Can only query by Rectangle, not " + shape);
+ throw new UnsupportedOperationException("Can only query by Rectangle, not " + shape);
Rectangle bbox = (Rectangle) shape;
Query spatial = null;
Modified: lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java?rev=1388872&r1=1388871&r2=1388872&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java Sat Sep 22 19:12:04 2012
@@ -18,7 +18,6 @@ package org.apache.lucene.spatial.vector
*/
import com.spatial4j.core.context.SpatialContext;
-import com.spatial4j.core.exception.InvalidShapeException;
import com.spatial4j.core.shape.Circle;
import com.spatial4j.core.shape.Point;
import com.spatial4j.core.shape.Rectangle;
@@ -90,7 +89,7 @@ public class TwoDoublesStrategy extends
public Field[] createIndexableFields(Shape shape) {
if (shape instanceof Point)
return createIndexableFields((Point) shape);
- throw new IllegalArgumentException("Can only index Point, not " + shape);
+ throw new UnsupportedOperationException("Can only index Point, not " + shape);
}
/** @see #createIndexableFields(com.spatial4j.core.shape.Shape) */
@@ -139,7 +138,7 @@ public class TwoDoublesStrategy extends
circle.getRadius() );
return new ConstantScoreQuery(vsf);
} else {
- throw new InvalidShapeException("Only Rectangles and Circles are currently supported, " +
+ throw new UnsupportedOperationException("Only Rectangles and Circles are currently supported, " +
"found [" + shape.getClass() + "]");//TODO
}
}
@@ -149,7 +148,7 @@ public class TwoDoublesStrategy extends
// For starters, just limit the bbox
Shape shape = args.getShape();
if (!(shape instanceof Rectangle || shape instanceof Circle)) {
- throw new InvalidShapeException("Only Rectangles and Circles are currently supported, " +
+ throw new UnsupportedOperationException("Only Rectangles and Circles are currently supported, " +
"found [" + shape.getClass() + "]");//TODO
}
Modified: lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java?rev=1388872&r1=1388871&r2=1388872&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java Sat Sep 22 19:12:04 2012
@@ -18,7 +18,6 @@ package org.apache.lucene.spatial.vector
*/
import com.spatial4j.core.context.SpatialContext;
-import com.spatial4j.core.exception.InvalidShapeException;
import com.spatial4j.core.shape.Circle;
import com.spatial4j.core.shape.Point;
import org.apache.lucene.search.Query;
@@ -50,7 +49,7 @@ public class TestTwoDoublesStrategy exte
assertNotNull(query);
}
- @Test(expected = InvalidShapeException.class)
+ @Test(expected = UnsupportedOperationException.class)
public void testInvalidQueryShape() {
Point point = ctx.makePoint(0, 0);
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, point);