Apache Lucene open-source search software
LUCENE-2032: fixed serialization issue in CartesianShapeFilter and removed referenced to java 5 logging API
Simon Willnauer48d6f2122d93
diff --git a/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianPolyFilterBuilder.java b/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianPolyFilterBuilder.javaindex f8ac5427688..63ad1b419ba 100644--- a/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianPolyFilterBuilder.java+++ b/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianPolyFilterBuilder.java@@ -19,11 +19,8 @@ package org.apache.lucene.spatial.tier;import java.math.BigDecimal;import java.math.RoundingMode;-import java.util.logging.Level;-import java.util.logging.Logger;import org.apache.lucene.search.Filter;-import org.apache.lucene.spatial.geometry.shape.Rectangle;import org.apache.lucene.spatial.tier.projections.CartesianTierPlotter;import org.apache.lucene.spatial.tier.projections.IProjector;import org.apache.lucene.spatial.tier.projections.SinusoidalProjector;@@ -46,8 +43,6 @@ public class CartesianPolyFilterBuilder {public static final double MILES_FLOOR = 1.0;private IProjector projector = new SinusoidalProjector();- private Logger log = Logger.getLogger(getClass().getName());-private final String tierPrefix;public CartesianPolyFilterBuilder( String tierPrefix ) {@@ -59,7 +54,6 @@ public class CartesianPolyFilterBuilder {if (miles < MILES_FLOOR) {miles = MILES_FLOOR;}- Rectangle box = DistanceUtils.getInstance().getBoundary(latitude, longitude, miles);LLRect box1 = LLRect.createBox( new FloatLatLng( latitude, longitude ), miles, miles );LatLng ll = box1.getLowerLeft();LatLng ur = box1.getUpperRight();@@ -84,7 +78,6 @@ public class CartesianPolyFilterBuilder {CartesianTierPlotter ctp = new CartesianTierPlotter(2, projector,tierPrefix);int bestFit = ctp.bestFit(miles);- log.info("Best Fit is : " + bestFit);ctp = new CartesianTierPlotter(bestFit, projector,tierPrefix);Shape shape = new Shape(ctp.getTierFieldName());@@ -133,9 +126,6 @@ public class CartesianPolyFilterBuilder {int scale = (int)Math.log10(tierVert);endY = new BigDecimal(endY).setScale(scale, RoundingMode.HALF_EVEN).doubleValue();startY = new BigDecimal(startY).setScale(scale, RoundingMode.HALF_EVEN).doubleValue();- if(log.isLoggable(Level.FINE)) {- log.fine("scale "+scale+" startX "+ startX + " endX "+endX +" startY "+ startY + " endY "+ endY +" tierVert "+ tierVert);- }double xInc = 1.0d / tierVert;xInc = new BigDecimal(xInc).setScale(scale, RoundingMode.HALF_EVEN).doubleValue();diff --git a/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianShapeFilter.java b/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianShapeFilter.javaindex 76feb98390c..c3c1410e75b 100644--- a/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianShapeFilter.java+++ b/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianShapeFilter.java@@ -35,49 +35,33 @@ import org.apache.lucene.util.OpenBitSet;* release.</font>*/public class CartesianShapeFilter extends Filter {-- private static final Logger log = Logger.getLogger(CartesianShapeFilter.class.getName());-- /**- *- */- private static final long serialVersionUID = 1L;- private Shape shape;- private String fieldName;++ private final Shape shape;+ private final String fieldName;- CartesianShapeFilter(Shape shape, String fieldName){+ CartesianShapeFilter(final Shape shape, final String fieldName){this.shape = shape;this.fieldName = fieldName;}@Override- public DocIdSet getDocIdSet(IndexReader reader) throws IOException {- long start = System.currentTimeMillis();-- OpenBitSet bits = new OpenBitSet(reader.maxDoc());-- TermDocs termDocs = reader.termDocs();- List<Double> area = shape.getArea();+ public DocIdSet getDocIdSet(final IndexReader reader) throws IOException {+ final OpenBitSet bits = new OpenBitSet(reader.maxDoc());+ final TermDocs termDocs = reader.termDocs();+ final List<Double> area = shape.getArea();int sz = area.size();- log.fine("Area size "+ sz);-++ final Term term = new Term(fieldName);// iterate through each boxidfor (int i =0; i< sz; i++) {double boxId = area.get(i).doubleValue();- termDocs.seek(new Term(fieldName,- NumericUtils.doubleToPrefixCoded(boxId)));-+ termDocs.seek(term.createTerm(NumericUtils.doubleToPrefixCoded(boxId)));// iterate through all documents// which have this boxIdwhile (termDocs.next()) {bits.fastSet(termDocs.doc());}}-- long end = System.currentTimeMillis();- if(log.isLoggable(Level.FINE)) {- log.fine("BoundaryBox Time Taken: "+ (end - start) + " found: "+bits.cardinality()+" candidates");- }return bits;}}diff --git a/contrib/spatial/src/java/org/apache/lucene/spatial/tier/Shape.java b/contrib/spatial/src/java/org/apache/lucene/spatial/tier/Shape.javaindex 5b95b3f8421..2a5bdbbf087 100644--- a/contrib/spatial/src/java/org/apache/lucene/spatial/tier/Shape.java+++ b/contrib/spatial/src/java/org/apache/lucene/spatial/tier/Shape.java@@ -17,6 +17,7 @@package org.apache.lucene.spatial.tier;+import java.io.Serializable;import java.util.ArrayList;import java.util.List;@@ -25,7 +26,7 @@ import java.util.List;* flux and might change in incompatible ways in the next* release.</font>*/-public class Shape {+public class Shape implements Serializable{private List<Double> area = new ArrayList<Double>();private String tierId;diff --git a/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesianShapeFilter.java b/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesianShapeFilter.javanew file mode 100644index 00000000000..c83289a99eb--- /dev/null+++ b/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesianShapeFilter.java@@ -0,0 +1,44 @@+/**+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package org.apache.lucene.spatial.tier;++import java.io.ByteArrayOutputStream;+import java.io.IOException;+import java.io.NotSerializableException;+import java.io.ObjectOutputStream;++import junit.framework.TestCase;+/**+ *+ * Test for {@link CartesianShapeFilter}+ *+ */+public class TestCartesianShapeFilter extends TestCase {++ public void testSerializable() throws IOException {+ CartesianShapeFilter filter = new CartesianShapeFilter(new Shape("1"),+ "test");+ try {+ ByteArrayOutputStream bos = new ByteArrayOutputStream();+ ObjectOutputStream oos = new ObjectOutputStream(bos);+ oos.writeObject(filter);+ } catch (NotSerializableException e) {+ fail("Filter should be serializable but raised a NotSerializableException ["+e.getMessage()+"]");+ }+ }++}