Skip to content

Commit

Permalink
Further generics refinements
Browse files Browse the repository at this point in the history
Based on Ignacio's work in 050df95,
we fix the BoundingBox generics, and also add a little more specificity
to the previous generics (replace <?> with <? extends SpatialPoint>).
  • Loading branch information
craigtaverner committed Sep 6, 2022
1 parent 541e47f commit c8b9ee3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

public abstract XContentBuilder toXContentFragment(XContentBuilder builder, boolean buildLatLonFields) throws IOException;

protected abstract static class BoundsParser<T extends SpatialPoint> {
protected abstract static class BoundsParser<T extends BoundingBox<? extends SpatialPoint>> {
protected double top = Double.NaN;
protected double bottom = Double.NaN;
protected double left = Double.NaN;
Expand All @@ -98,7 +98,7 @@ protected BoundsParser(XContentParser parser) {
this.parser = parser;
}

public BoundingBox<T> parseBoundingBox() throws IOException, ElasticsearchParseException {
public T parseBoundingBox() throws IOException, ElasticsearchParseException {
XContentParser.Token token = parser.currentToken();
if (token != XContentParser.Token.START_OBJECT) {
throw new ElasticsearchParseException("failed to parse bounding box. Expected start object but found [{}]", token);
Expand Down Expand Up @@ -172,9 +172,9 @@ public BoundingBox<T> parseBoundingBox() throws IOException, ElasticsearchParseE
return createWithBounds();
}

protected abstract BoundingBox<T> createWithEnvelope();
protected abstract T createWithEnvelope();

protected abstract BoundingBox<T> createWithBounds();
protected abstract T createWithBounds();

protected abstract SpatialPoint parsePointWith(XContentParser parser, GeoUtils.EffectivePoint effectivePoint) throws IOException;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeGeoPoint(bottomRight);
}

protected static class GeoBoundsParser extends BoundsParser<GeoPoint> {
protected static class GeoBoundsParser extends BoundsParser<GeoBoundingBox> {
GeoBoundsParser(XContentParser parser) {
super(parser);
}
Expand Down Expand Up @@ -116,6 +116,6 @@ protected SpatialPoint parsePointWith(XContentParser parser, GeoUtils.EffectiveP
*/
public static GeoBoundingBox parseBoundingBox(XContentParser parser) throws IOException, ElasticsearchParseException {
GeoBoundsParser bounds = new GeoBoundsParser(parser);
return (GeoBoundingBox) bounds.parseBoundingBox();
return bounds.parseBoundingBox();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

package org.elasticsearch.index.fielddata;

import org.elasticsearch.common.geo.SpatialPoint;

/**
* Specialization of {@link IndexFieldData} for geo points and points.
*/
public interface IndexPointFieldData<T extends MultiPointValues<?>> extends IndexFieldData<LeafPointFieldData<T>> {}
public interface IndexPointFieldData<T extends MultiPointValues<? extends SpatialPoint>> extends IndexFieldData<LeafPointFieldData<T>> {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
package org.elasticsearch.index.fielddata;

import org.apache.lucene.index.SortedNumericDocValues;
import org.elasticsearch.common.geo.SpatialPoint;

/**
* {@link LeafFieldData} specialization for geo points and points.
*/
public abstract class LeafPointFieldData<T extends MultiPointValues<?>> implements LeafFieldData {
public abstract class LeafPointFieldData<T extends MultiPointValues<? extends SpatialPoint>> implements LeafFieldData {

/**
* Return geo-point or point values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.elasticsearch.index.fielddata.plain;

import org.apache.lucene.search.SortField;
import org.elasticsearch.common.geo.SpatialPoint;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
Expand All @@ -20,7 +21,7 @@
import org.elasticsearch.search.sort.BucketedSort;
import org.elasticsearch.search.sort.SortOrder;

abstract class AbstractPointIndexFieldData<T extends MultiPointValues<?>> implements IndexPointFieldData<T> {
abstract class AbstractPointIndexFieldData<T extends MultiPointValues<? extends SpatialPoint>> implements IndexPointFieldData<T> {

protected final String fieldName;
protected final ValuesSourceType valuesSourceType;
Expand Down

0 comments on commit c8b9ee3

Please sign in to comment.