Skip to content

Commit

Permalink
Reduce number of raw types warnings (#31523)
Browse files Browse the repository at this point in the history
A first attempt to reduce the number of raw type warnings, 
most of the time by using the unbounded wildcard.
  • Loading branch information
Christoph Büscher authored Jun 25, 2018
1 parent 8e47688 commit 86ab3a2
Show file tree
Hide file tree
Showing 67 changed files with 261 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public NoopSearchRequestBuilder addSort(String field, SortOrder order) {
*
* @see org.elasticsearch.search.sort.SortBuilders
*/
public NoopSearchRequestBuilder addSort(SortBuilder sort) {
public NoopSearchRequestBuilder addSort(SortBuilder<?> sort) {
sourceBuilder().sort(sort);
return this;
}
Expand Down Expand Up @@ -415,7 +415,7 @@ public NoopSearchRequestBuilder setRescorer(RescorerBuilder<?> rescorer) {
* @param window rescore window
* @return this for chaining
*/
public NoopSearchRequestBuilder setRescorer(RescorerBuilder rescorer, int window) {
public NoopSearchRequestBuilder setRescorer(RescorerBuilder<?> rescorer, int window) {
sourceBuilder().clearRescorers();
return addRescorer(rescorer.windowSize(window));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testAppendValuesToNonExistingList() throws Exception {
appendProcessor = createAppendProcessor(field, values);
}
appendProcessor.execute(ingestDocument);
List list = ingestDocument.getFieldValue(field, List.class);
List<?> list = ingestDocument.getFieldValue(field, List.class);
assertThat(list, not(sameInstance(values)));
assertThat(list, equalTo(values));
}
Expand All @@ -115,7 +115,7 @@ public void testConvertScalarToList() throws Exception {
appendProcessor = createAppendProcessor(field, values);
}
appendProcessor.execute(ingestDocument);
List fieldValue = ingestDocument.getFieldValue(field, List.class);
List<?> fieldValue = ingestDocument.getFieldValue(field, List.class);
assertThat(fieldValue.size(), equalTo(values.size() + 1));
assertThat(fieldValue.get(0), equalTo(initialValue));
for (int i = 1; i < values.size() + 1; i++) {
Expand Down Expand Up @@ -144,7 +144,7 @@ public void testAppendMetadataExceptVersion() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
Object initialValue = ingestDocument.getSourceAndMetadata().get(randomMetaData.getFieldName());
appendProcessor.execute(ingestDocument);
List list = ingestDocument.getFieldValue(randomMetaData.getFieldName(), List.class);
List<?> list = ingestDocument.getFieldValue(randomMetaData.getFieldName(), List.class);
if (initialValue == null) {
assertThat(list, equalTo(values));
} else {
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/org/elasticsearch/action/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public TransportRequestOptions transportOptions(Settings settings) {

@Override
public boolean equals(Object o) {
return o instanceof Action && name.equals(((Action) o).name());
return o instanceof Action && name.equals(((Action<?>) o).name());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
public class BulkItemRequest implements Streamable {

private int id;
private DocWriteRequest request;
private DocWriteRequest<?> request;
private volatile BulkItemResponse primaryResponse;

BulkItemRequest() {

}

// NOTE: public for testing only
public BulkItemRequest(int id, DocWriteRequest request) {
public BulkItemRequest(int id, DocWriteRequest<?> request) {
this.id = id;
this.request = request;
}
Expand All @@ -48,7 +48,7 @@ public int id() {
return id;
}

public DocWriteRequest request() {
public DocWriteRequest<?> request() {
return request;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,24 +248,24 @@ public synchronized boolean awaitClose(long timeout, TimeUnit unit) throws Inter
* (for example, if no id is provided, one will be generated, or usage of the create flag).
*/
public BulkProcessor add(IndexRequest request) {
return add((DocWriteRequest) request);
return add((DocWriteRequest<?>) request);
}

/**
* Adds an {@link DeleteRequest} to the list of actions to execute.
*/
public BulkProcessor add(DeleteRequest request) {
return add((DocWriteRequest) request);
return add((DocWriteRequest<?>) request);
}

/**
* Adds either a delete or an index request.
*/
public BulkProcessor add(DocWriteRequest request) {
public BulkProcessor add(DocWriteRequest<?> request) {
return add(request, null);
}

public BulkProcessor add(DocWriteRequest request, @Nullable Object payload) {
public BulkProcessor add(DocWriteRequest<?> request, @Nullable Object payload) {
internalAdd(request, payload);
return this;
}
Expand All @@ -280,7 +280,7 @@ protected void ensureOpen() {
}
}

private synchronized void internalAdd(DocWriteRequest request, @Nullable Object payload) {
private synchronized void internalAdd(DocWriteRequest<?> request, @Nullable Object payload) {
ensureOpen();
bulkRequest.add(request, payload);
executeIfNeeded();
Expand Down
22 changes: 11 additions & 11 deletions server/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class BulkRequest extends ActionRequest implements CompositeIndicesReques
* {@link WriteRequest}s to this but java doesn't support syntax to declare that everything in the array has both types so we declare
* the one with the least casts.
*/
final List<DocWriteRequest> requests = new ArrayList<>();
final List<DocWriteRequest<?>> requests = new ArrayList<>();
private final Set<String> indices = new HashSet<>();
List<Object> payloads = null;

Expand All @@ -99,14 +99,14 @@ public BulkRequest() {
/**
* Adds a list of requests to be executed. Either index or delete requests.
*/
public BulkRequest add(DocWriteRequest... requests) {
for (DocWriteRequest request : requests) {
public BulkRequest add(DocWriteRequest<?>... requests) {
for (DocWriteRequest<?> request : requests) {
add(request, null);
}
return this;
}

public BulkRequest add(DocWriteRequest request) {
public BulkRequest add(DocWriteRequest<?> request) {
return add(request, null);
}

Expand All @@ -116,7 +116,7 @@ public BulkRequest add(DocWriteRequest request) {
* @param payload Optional payload
* @return the current bulk request
*/
public BulkRequest add(DocWriteRequest request, @Nullable Object payload) {
public BulkRequest add(DocWriteRequest<?> request, @Nullable Object payload) {
if (request instanceof IndexRequest) {
add((IndexRequest) request, payload);
} else if (request instanceof DeleteRequest) {
Expand All @@ -133,8 +133,8 @@ public BulkRequest add(DocWriteRequest request, @Nullable Object payload) {
/**
* Adds a list of requests to be executed. Either index or delete requests.
*/
public BulkRequest add(Iterable<DocWriteRequest> requests) {
for (DocWriteRequest request : requests) {
public BulkRequest add(Iterable<DocWriteRequest<?>> requests) {
for (DocWriteRequest<?> request : requests) {
add(request);
}
return this;
Expand Down Expand Up @@ -223,7 +223,7 @@ private void addPayload(Object payload) {
/**
* The list of requests in this bulk request.
*/
public List<DocWriteRequest> requests() {
public List<DocWriteRequest<?>> requests() {
return this.requests;
}

Expand Down Expand Up @@ -527,7 +527,7 @@ private int findNextMarker(byte marker, int from, BytesReference data, int lengt
* @return Whether this bulk request contains index request with an ingest pipeline enabled.
*/
public boolean hasIndexRequestsWithPipelines() {
for (DocWriteRequest actionRequest : requests) {
for (DocWriteRequest<?> actionRequest : requests) {
if (actionRequest instanceof IndexRequest) {
IndexRequest indexRequest = (IndexRequest) actionRequest;
if (Strings.hasText(indexRequest.getPipeline())) {
Expand All @@ -545,7 +545,7 @@ public ActionRequestValidationException validate() {
if (requests.isEmpty()) {
validationException = addValidationError("no requests added", validationException);
}
for (DocWriteRequest request : requests) {
for (DocWriteRequest<?> request : requests) {
// We first check if refresh has been set
if (((WriteRequest<?>) request).getRefreshPolicy() != RefreshPolicy.NONE) {
validationException = addValidationError(
Expand Down Expand Up @@ -580,7 +580,7 @@ public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
waitForActiveShards.writeTo(out);
out.writeVInt(requests.size());
for (DocWriteRequest request : requests) {
for (DocWriteRequest<?> request : requests) {
DocWriteRequest.writeDocumentRequest(out, request);
}
refreshPolicy.writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ protected void doExecute(Task task, BulkRequest bulkRequest, ActionListener<Bulk
final Set<String> indices = bulkRequest.requests.stream()
// delete requests should not attempt to create the index (if the index does not
// exists), unless an external versioning is used
.filter(request -> request.opType() != DocWriteRequest.OpType.DELETE
|| request.versionType() == VersionType.EXTERNAL
.filter(request -> request.opType() != DocWriteRequest.OpType.DELETE
|| request.versionType() == VersionType.EXTERNAL
|| request.versionType() == VersionType.EXTERNAL_GTE)
.map(DocWriteRequest::index)
.collect(Collectors.toSet());
Expand Down Expand Up @@ -184,7 +184,7 @@ public void onFailure(Exception e) {
if (!(ExceptionsHelper.unwrapCause(e) instanceof ResourceAlreadyExistsException)) {
// fail all requests involving this index, if create didn't work
for (int i = 0; i < bulkRequest.requests.size(); i++) {
DocWriteRequest request = bulkRequest.requests.get(i);
DocWriteRequest<?> request = bulkRequest.requests.get(i);
if (request != null && setResponseFailureIfIndexMatches(responses, i, request, index, e)) {
bulkRequest.requests.set(i, null);
}
Expand Down Expand Up @@ -221,7 +221,7 @@ void createIndex(String index, TimeValue timeout, ActionListener<CreateIndexResp
client.admin().indices().create(createIndexRequest, listener);
}

private boolean setResponseFailureIfIndexMatches(AtomicArray<BulkItemResponse> responses, int idx, DocWriteRequest request, String index, Exception e) {
private boolean setResponseFailureIfIndexMatches(AtomicArray<BulkItemResponse> responses, int idx, DocWriteRequest<?> request, String index, Exception e) {
if (index.equals(request.index())) {
responses.set(idx, new BulkItemResponse(idx, request.opType(), new BulkItemResponse.Failure(request.index(), request.type(), request.id(), e)));
return true;
Expand Down Expand Up @@ -271,7 +271,7 @@ protected void doRun() throws Exception {
final ConcreteIndices concreteIndices = new ConcreteIndices(clusterState, indexNameExpressionResolver);
MetaData metaData = clusterState.metaData();
for (int i = 0; i < bulkRequest.requests.size(); i++) {
DocWriteRequest docWriteRequest = bulkRequest.requests.get(i);
DocWriteRequest<?> docWriteRequest = bulkRequest.requests.get(i);
//the request can only be null because we set it to null in the previous step, so it gets ignored
if (docWriteRequest == null) {
continue;
Expand Down Expand Up @@ -315,7 +315,7 @@ protected void doRun() throws Exception {
// first, go over all the requests and create a ShardId -> Operations mapping
Map<ShardId, List<BulkItemRequest>> requestsByShard = new HashMap<>();
for (int i = 0; i < bulkRequest.requests.size(); i++) {
DocWriteRequest request = bulkRequest.requests.get(i);
DocWriteRequest<?> request = bulkRequest.requests.get(i);
if (request == null) {
continue;
}
Expand Down Expand Up @@ -362,7 +362,7 @@ public void onFailure(Exception e) {
// create failures for all relevant requests
for (BulkItemRequest request : requests) {
final String indexName = concreteIndices.getConcreteIndex(request.index()).getName();
DocWriteRequest docWriteRequest = request.request();
DocWriteRequest<?> docWriteRequest = request.request();
responses.set(request.id(), new BulkItemResponse(request.id(), docWriteRequest.opType(),
new BulkItemResponse.Failure(indexName, docWriteRequest.type(), docWriteRequest.id(), e)));
}
Expand Down Expand Up @@ -418,7 +418,7 @@ public void onTimeout(TimeValue timeout) {
});
}

private boolean addFailureIfIndexIsUnavailable(DocWriteRequest request, int idx, final ConcreteIndices concreteIndices,
private boolean addFailureIfIndexIsUnavailable(DocWriteRequest<?> request, int idx, final ConcreteIndices concreteIndices,
final MetaData metaData) {
IndexNotFoundException cannotCreate = indicesThatCannotBeCreated.get(request.index());
if (cannotCreate != null) {
Expand All @@ -442,7 +442,7 @@ private boolean addFailureIfIndexIsUnavailable(DocWriteRequest request, int idx,
return false;
}

private void addFailure(DocWriteRequest request, int idx, Exception unavailableException) {
private void addFailure(DocWriteRequest<?> request, int idx, Exception unavailableException) {
BulkItemResponse.Failure failure = new BulkItemResponse.Failure(request.index(), request.type(), request.id(),
unavailableException);
BulkItemResponse bulkItemResponse = new BulkItemResponse(idx, request.opType(), failure);
Expand Down Expand Up @@ -471,7 +471,7 @@ Index getConcreteIndex(String indexOrAlias) {
return indices.get(indexOrAlias);
}

Index resolveIfAbsent(DocWriteRequest request) {
Index resolveIfAbsent(DocWriteRequest<?> request) {
Index concreteIndex = indices.get(request.index());
if (concreteIndex == null) {
concreteIndex = indexNameExpressionResolver.concreteSingleIndex(state, request);
Expand Down Expand Up @@ -512,7 +512,7 @@ void processBulkIndexIngestRequest(Task task, BulkRequest original, ActionListen
});
}

static final class BulkRequestModifier implements Iterator<DocWriteRequest> {
static final class BulkRequestModifier implements Iterator<DocWriteRequest<?>> {

final BulkRequest bulkRequest;
final SparseFixedBitSet failedSlots;
Expand All @@ -528,7 +528,7 @@ static final class BulkRequestModifier implements Iterator<DocWriteRequest> {
}

@Override
public DocWriteRequest next() {
public DocWriteRequest<?> next() {
return bulkRequest.requests().get(++currentSlot);
}

Expand All @@ -547,10 +547,10 @@ BulkRequest getBulkRequest() {
modifiedBulkRequest.timeout(bulkRequest.timeout());

int slot = 0;
List<DocWriteRequest> requests = bulkRequest.requests();
List<DocWriteRequest<?>> requests = bulkRequest.requests();
originalSlots = new int[requests.size()]; // oversize, but that's ok
for (int i = 0; i < requests.size(); i++) {
DocWriteRequest request = requests.get(i);
DocWriteRequest<?> request = requests.get(i);
if (failedSlots.get(i) == false) {
modifiedBulkRequest.add(request);
originalSlots[slot++] = i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.action.support.replication;

import com.carrotsearch.hppc.cursors.IntObjectCursor;

import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public AbstractComponent(Settings settings) {
this.settings = settings;
}

public AbstractComponent(Settings settings, Class customClass) {
public AbstractComponent(Settings settings, Class<?> customClass) {
this.logger = LogManager.getLogger(customClass);
this.deprecationLogger = new DeprecationLogger(logger);
this.settings = settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected AbstractLifecycleComponent(Settings settings) {
super(settings);
}

protected AbstractLifecycleComponent(Settings settings, Class customClass) {
protected AbstractLifecycleComponent(Settings settings, Class<?> customClass) {
super(settings, customClass);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,22 @@

package org.elasticsearch.common.geo.builders;

import org.elasticsearch.common.geo.GeoShapeType;
import org.elasticsearch.common.geo.parsers.ShapeParser;
import org.elasticsearch.common.geo.parsers.GeoWKTParser;
import org.locationtech.spatial4j.shape.Shape;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.geo.GeoShapeType;
import org.elasticsearch.common.geo.XShapeCollection;
import org.elasticsearch.common.geo.parsers.GeoWKTParser;
import org.elasticsearch.common.geo.parsers.ShapeParser;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.locationtech.spatial4j.shape.Shape;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class GeometryCollectionBuilder extends ShapeBuilder {
public class GeometryCollectionBuilder extends ShapeBuilder<Shape, GeometryCollectionBuilder> {

public static final GeoShapeType TYPE = GeoShapeType.GEOMETRYCOLLECTION;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@
package org.elasticsearch.common.geo.builders;

import org.elasticsearch.common.geo.GeoShapeType;
import org.elasticsearch.common.geo.parsers.ShapeParser;
import org.elasticsearch.common.geo.parsers.GeoWKTParser;
import org.locationtech.spatial4j.shape.Shape;
import org.locationtech.jts.geom.Coordinate;

import org.elasticsearch.common.geo.XShapeCollection;
import org.elasticsearch.common.geo.parsers.GeoWKTParser;
import org.elasticsearch.common.geo.parsers.ShapeParser;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.spatial4j.shape.Shape;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

public class MultiPolygonBuilder extends ShapeBuilder {
public class MultiPolygonBuilder extends ShapeBuilder<Shape, MultiPolygonBuilder> {

public static final GeoShapeType TYPE = GeoShapeType.MULTIPOLYGON;

Expand Down
Loading

0 comments on commit 86ab3a2

Please sign in to comment.