Skip to content

Commit

Permalink
Reduce more raw types warnings (#31780)
Browse files Browse the repository at this point in the history
Similar to #31523.
  • Loading branch information
Christoph Büscher authored Jul 5, 2018
1 parent ca5822e commit bd1c513
Show file tree
Hide file tree
Showing 66 changed files with 304 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ boolean isIgnoreMissing() {

@Override
public void execute(IngestDocument ingestDocument) throws Exception {
List values = ingestDocument.getFieldValue(field, List.class, ignoreMissing);
List<?> values = ingestDocument.getFieldValue(field, List.class, ignoreMissing);
if (values == null) {
if (ignoreMissing) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public RemoveProcessor create(Map<String, Processor.Factory> registry, String pr
final List<String> fields = new ArrayList<>();
final Object field = ConfigurationUtils.readObject(TYPE, processorTag, config, "field");
if (field instanceof List) {
fields.addAll((List) field);
@SuppressWarnings("unchecked")
List<String> stringList = (List<String>) field;
fields.addAll(stringList);
} else {
fields.add((String) field);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public enum SortOrder {
this.direction = direction;
}

@Override
public String toString() {
return this.direction;
}
Expand Down Expand Up @@ -94,13 +95,13 @@ String getTargetField() {
@Override
@SuppressWarnings("unchecked")
public void execute(IngestDocument document) {
List<? extends Comparable> list = document.getFieldValue(field, List.class);
List<? extends Comparable<Object>> list = document.getFieldValue(field, List.class);

if (list == null) {
throw new IllegalArgumentException("field [" + field + "] is null, cannot sort.");
}

List<? extends Comparable> copy = new ArrayList<>(list);
List<? extends Comparable<Object>> copy = new ArrayList<>(list);

if (order.equals(SortOrder.ASCENDING)) {
Collections.sort(copy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@

package org.elasticsearch.ingest.common;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.elasticsearch.ingest.CompoundProcessor;
import org.elasticsearch.ingest.IngestDocument;
import org.elasticsearch.ingest.Processor;
Expand All @@ -34,6 +27,14 @@
import org.elasticsearch.script.TemplateScript;
import org.elasticsearch.test.ESTestCase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import static org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument;
import static org.hamcrest.Matchers.equalTo;

Expand All @@ -54,7 +55,8 @@ public void testExecute() throws Exception {
);
processor.execute(ingestDocument);

List result = ingestDocument.getFieldValue("values", List.class);
@SuppressWarnings("unchecked")
List<String> result = ingestDocument.getFieldValue("values", List.class);
assertThat(result.get(0), equalTo("FOO"));
assertThat(result.get(1), equalTo("BAR"));
assertThat(result.get(2), equalTo("BAZ"));
Expand Down Expand Up @@ -204,12 +206,12 @@ public void testModifyFieldsOutsideArray() throws Exception {
), false);
processor.execute(ingestDocument);

List result = ingestDocument.getFieldValue("values", List.class);
List<?> result = ingestDocument.getFieldValue("values", List.class);
assertThat(result.get(0), equalTo("STRING"));
assertThat(result.get(1), equalTo(1));
assertThat(result.get(2), equalTo(null));

List errors = ingestDocument.getFieldValue("errors", List.class);
List<?> errors = ingestDocument.getFieldValue("errors", List.class);
assertThat(errors.size(), equalTo(2));
}

Expand All @@ -230,7 +232,7 @@ public void testScalarValueAllowsUnderscoreValueFieldToRemainAccessible() throws
ForEachProcessor forEachProcessor = new ForEachProcessor("_tag", "values", processor, false);
forEachProcessor.execute(ingestDocument);

List result = ingestDocument.getFieldValue("values", List.class);
List<?> result = ingestDocument.getFieldValue("values", List.class);
assertThat(result.get(0), equalTo("new_value"));
assertThat(result.get(1), equalTo("new_value"));
assertThat(result.get(2), equalTo("new_value"));
Expand Down Expand Up @@ -263,13 +265,13 @@ public void testNestedForEach() throws Exception {
"_tag", "values1", new ForEachProcessor("_tag", "_ingest._value.values2", testProcessor, false), false);
processor.execute(ingestDocument);

List result = ingestDocument.getFieldValue("values1.0.values2", List.class);
List<?> result = ingestDocument.getFieldValue("values1.0.values2", List.class);
assertThat(result.get(0), equalTo("ABC"));
assertThat(result.get(1), equalTo("DEF"));

result = ingestDocument.getFieldValue("values1.1.values2", List.class);
assertThat(result.get(0), equalTo("GHI"));
assertThat(result.get(1), equalTo("JKL"));
List<?> result2 = ingestDocument.getFieldValue("values1.1.values2", List.class);
assertThat(result2.get(0), equalTo("GHI"));
assertThat(result2.get(1), equalTo("JKL"));
}

public void testIgnoreMissing() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static class CustomScriptPlugin extends MockScriptPlugin {
protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
return Collections.singletonMap("my_script", script -> {
@SuppressWarnings("unchecked")
Map<String, Object> ctx = (Map) script.get("ctx");
Map<String, Object> ctx = (Map<String, Object>) script.get("ctx");
ctx.put("z", 0);
return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.github.mustachejava.codes.DefaultMustache;
import com.github.mustachejava.codes.IterableCode;
import com.github.mustachejava.codes.WriteCode;

import org.elasticsearch.common.Strings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentType;
Expand Down Expand Up @@ -202,11 +203,9 @@ protected Function<String, String> createFunction(Object resolved) {
return null;
}
try (XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent())) {
if (resolved == null) {
builder.nullValue();
} else if (resolved instanceof Iterable) {
if (resolved instanceof Iterable) {
builder.startArray();
for (Object o : (Iterable) resolved) {
for (Object o : (Iterable<?>) resolved) {
builder.value(o);
}
builder.endArray();
Expand Down Expand Up @@ -254,7 +253,7 @@ protected Function<String, String> createFunction(Object resolved) {
return null;
} else if (resolved instanceof Iterable) {
StringJoiner joiner = new StringJoiner(delimiter);
for (Object o : (Iterable) resolved) {
for (Object o : (Iterable<?>) resolved) {
joiner.add(oh.stringify(o));
}
return joiner.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
scripts.put("1==1", vars -> Boolean.TRUE);
scripts.put("use_fielddata_please", vars -> {
LeafDocLookup leafDocLookup = (LeafDocLookup) vars.get("_doc");
ScriptDocValues scriptDocValues = leafDocLookup.get("employees.name");
ScriptDocValues<?> scriptDocValues = leafDocLookup.get("employees.name");
return "virginia_potts".equals(scriptDocValues.get(0));
});
return scripts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private Collection<Query> rewriteCustomQuery(Query query) {
SpanQuery[] innerQueries = new SpanQuery[terms[i].length];
for (int j = 0; j < terms[i].length; j++) {
if (i == sizeMinus1) {
innerQueries[j] = new SpanMultiTermQueryWrapper(new PrefixQuery(terms[i][j]));
innerQueries[j] = new SpanMultiTermQueryWrapper<PrefixQuery>(new PrefixQuery(terms[i][j]));
} else {
innerQueries[j] = new SpanTermQuery(terms[i][j]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public interface DocWriteRequest<T> extends IndicesRequest {
* Get the options for this request
* @return the indices options
*/
@Override
IndicesOptions indicesOptions();

/**
Expand Down Expand Up @@ -157,9 +158,9 @@ public static OpType fromString(String sOpType) {
}

/** read a document write (index/delete/update) request */
static DocWriteRequest readDocumentRequest(StreamInput in) throws IOException {
static DocWriteRequest<?> readDocumentRequest(StreamInput in) throws IOException {
byte type = in.readByte();
DocWriteRequest docWriteRequest;
DocWriteRequest<?> docWriteRequest;
if (type == 0) {
IndexRequest indexRequest = new IndexRequest();
indexRequest.readFrom(in);
Expand All @@ -179,7 +180,7 @@ static DocWriteRequest readDocumentRequest(StreamInput in) throws IOException {
}

/** write a document write (index/delete/update) request*/
static void writeDocumentRequest(StreamOutput out, DocWriteRequest request) throws IOException {
static void writeDocumentRequest(StreamOutput out, DocWriteRequest<?> request) throws IOException {
if (request instanceof IndexRequest) {
out.writeByte((byte) 0);
((IndexRequest) request).writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ public ClusterUpdateSettingsRequest transientSettings(String source, XContentTyp
/**
* Sets the transient settings to be updated. They will not survive a full cluster restart
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public ClusterUpdateSettingsRequest transientSettings(Map source) {
public ClusterUpdateSettingsRequest transientSettings(Map<String, ?> source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
Expand Down Expand Up @@ -147,8 +146,7 @@ public ClusterUpdateSettingsRequest persistentSettings(String source, XContentTy
/**
* Sets the persistent settings to be updated. They will get applied cross restarts
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public ClusterUpdateSettingsRequest persistentSettings(Map source) {
public ClusterUpdateSettingsRequest persistentSettings(Map<String, ?> source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ClusterUpdateSettingsRequestBuilder setTransientSettings(String settings,
/**
* Sets the transient settings to be updated. They will not survive a full cluster restart
*/
public ClusterUpdateSettingsRequestBuilder setTransientSettings(Map settings) {
public ClusterUpdateSettingsRequestBuilder setTransientSettings(Map<String, ?> settings) {
request.transientSettings(settings);
return this;
}
Expand Down Expand Up @@ -94,7 +94,7 @@ public ClusterUpdateSettingsRequestBuilder setPersistentSettings(String settings
/**
* Sets the persistent settings to be updated. They will get applied cross restarts
*/
public ClusterUpdateSettingsRequestBuilder setPersistentSettings(Map settings) {
public ClusterUpdateSettingsRequestBuilder setPersistentSettings(Map<String, ?> settings) {
request.persistentSettings(settings);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
import java.util.Set;

import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS;
import static org.elasticsearch.common.settings.Settings.readSettingsFromStream;
import static org.elasticsearch.common.settings.Settings.writeSettingsToStream;
import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS;

/**
* A request to create an index. Best created with {@link org.elasticsearch.client.Requests#createIndexRequest(String)}.
Expand Down Expand Up @@ -189,8 +189,7 @@ public CreateIndexRequest settings(XContentBuilder builder) {
/**
* The settings to create the index with (either json/yaml/properties format)
*/
@SuppressWarnings("unchecked")
public CreateIndexRequest settings(Map source) {
public CreateIndexRequest settings(Map<String, ?> source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
Expand Down Expand Up @@ -256,8 +255,7 @@ public CreateIndexRequest mapping(String type, XContentBuilder source) {
* @param type The mapping type
* @param source The mapping source
*/
@SuppressWarnings("unchecked")
public CreateIndexRequest mapping(String type, Map source) {
public CreateIndexRequest mapping(String type, Map<String, ?> source) {
if (mappings.containsKey(type)) {
throw new IllegalStateException("mappings for type \"" + type + "\" were already defined");
}
Expand Down Expand Up @@ -286,8 +284,7 @@ public CreateIndexRequest mapping(String type, Object... source) {
/**
* Sets the aliases that will be associated with the index when it gets created
*/
@SuppressWarnings("unchecked")
public CreateIndexRequest aliases(Map source) {
public CreateIndexRequest aliases(Map<String, ?> source) {
try {
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.map(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public CreateIndexRequestBuilder addMapping(String type, Object... source) {
/**
* Sets the aliases that will be associated with the index when it gets created
*/
public CreateIndexRequestBuilder setAliases(Map source) {
public CreateIndexRequestBuilder setAliases(Map<String, ?> source) {
request.aliases(source);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ protected ReplicationResponse newResponseInstance() {
}

@Override
protected PrimaryResult shardOperationOnPrimary(ShardFlushRequest shardRequest, IndexShard primary) {
protected PrimaryResult<ShardFlushRequest, ReplicationResponse> shardOperationOnPrimary(ShardFlushRequest shardRequest,
IndexShard primary) {
primary.flush(shardRequest.getRequest());
logger.trace("{} flush request executed on primary", primary.shardId());
return new PrimaryResult(shardRequest, new ReplicationResponse());
return new PrimaryResult<ShardFlushRequest, ReplicationResponse>(shardRequest, new ReplicationResponse());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
package org.elasticsearch.action.admin.indices.mapping.get;

import com.carrotsearch.hppc.cursors.ObjectObjectCursor;

import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
Expand All @@ -39,9 +39,6 @@ public class GetMappingsResponse extends ActionResponse implements ToXContentFra

private static final ParseField MAPPINGS = new ParseField("mappings");

private static final ObjectParser<GetMappingsResponse, Void> PARSER =
new ObjectParser<GetMappingsResponse, Void>("get-mappings", false, GetMappingsResponse::new);

private ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = ImmutableOpenMap.of();

GetMappingsResponse(ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings) {
Expand Down Expand Up @@ -101,13 +98,15 @@ public static GetMappingsResponse fromXContent(XContentParser parser) throws IOE
for (Map.Entry<String, Object> entry : parts.entrySet()) {
final String indexName = entry.getKey();
assert entry.getValue() instanceof Map : "expected a map as type mapping, but got: " + entry.getValue().getClass();
final Map<String, Object> mapping = (Map<String, Object>) ((Map) entry.getValue()).get(MAPPINGS.getPreferredName());
@SuppressWarnings("unchecked")
final Map<String, Object> mapping = (Map<String, Object>) ((Map<String, ?>) entry.getValue()).get(MAPPINGS.getPreferredName());

ImmutableOpenMap.Builder<String, MappingMetaData> typeBuilder = new ImmutableOpenMap.Builder<>();
for (Map.Entry<String, Object> typeEntry : mapping.entrySet()) {
final String typeName = typeEntry.getKey();
assert typeEntry.getValue() instanceof Map : "expected a map as inner type mapping, but got: " +
typeEntry.getValue().getClass();
@SuppressWarnings("unchecked")
final Map<String, Object> fieldMappings = (Map<String, Object>) typeEntry.getValue();
MappingMetaData mmd = new MappingMetaData(typeName, fieldMappings);
typeBuilder.put(typeName, mmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ public PutMappingRequest source(XContentBuilder mappingBuilder) {
/**
* The mapping source definition.
*/
@SuppressWarnings("unchecked")
public PutMappingRequest source(Map mappingSource) {
public PutMappingRequest source(Map<String, ?> mappingSource) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(mappingSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ public Stats(long numDocs, long indexCreated, ByteSizeValue indexSize) {
* Holder for evaluated condition result
*/
public static class Result {
public final Condition condition;
public final Condition<?> condition;
public final boolean matched;

protected Result(Condition condition, boolean matched) {
protected Result(Condition<?> condition, boolean matched) {
this.condition = condition;
this.matched = matched;
}
Expand Down
Loading

0 comments on commit bd1c513

Please sign in to comment.