Skip to content

Commit

Permalink
Deprecate Map, List, and Set in org.opensearch.common.collect (opense…
Browse files Browse the repository at this point in the history
…arch-project#6609)

Signed-off-by: Dilip Roshitha <diliproshitha@gmail.com>
  • Loading branch information
diliproshitha committed Mar 11, 2023
1 parent 775b672 commit e700e75
Show file tree
Hide file tree
Showing 142 changed files with 541 additions and 511 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [Refactor] XContent base classes from xcontent to core library ([#5902](https://github.com/opensearch-project/OpenSearch/pull/5902))

### Deprecated
- Map, List, and Set in org.opensearch.common.collect ([#6609](https://github.com/opensearch-project/OpenSearch/pull/6609))

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
@State(Scope.Benchmark)
public class StringTermsSerializationBenchmark {
private static final NamedWriteableRegistry REGISTRY = new NamedWriteableRegistry(
org.opensearch.common.collect.List.of(
List.of(
new NamedWriteableRegistry.Entry(InternalAggregation.class, StringTerms.NAME, StringTerms::new)
)
);
Expand All @@ -75,14 +75,14 @@ public class StringTermsSerializationBenchmark {

@Setup
public void initResults() {
results = DelayableWriteable.referencing(InternalAggregations.from(org.opensearch.common.collect.List.of(newTerms(true))));
results = DelayableWriteable.referencing(InternalAggregations.from(List.of(newTerms(true))));
}

private StringTerms newTerms(boolean withNested) {
List<StringTerms.Bucket> resultBuckets = new ArrayList<>(buckets);
for (int i = 0; i < buckets; i++) {
InternalAggregations inner = withNested
? InternalAggregations.from(org.opensearch.common.collect.List.of(newTerms(false)))
? InternalAggregations.from(List.of(newTerms(false)))
: InternalAggregations.EMPTY;
resultBuckets.add(new StringTerms.Bucket(new BytesRef("test" + i), i, inner, false, 0, DocValueFormat.RAW));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2032,8 +2032,8 @@ public void testSimulateIndexTemplate() throws Exception {
Settings settings = Settings.builder().put("index.number_of_shards", 1).build();
CompressedXContent mappings = new CompressedXContent("{\"properties\":{\"host_name\":{\"type\":\"keyword\"}}}");
AliasMetadata alias = AliasMetadata.builder("alias").writeIndex(true).build();
Template template = new Template(settings, mappings, org.opensearch.common.collect.Map.of("alias", alias));
List<String> pattern = org.opensearch.common.collect.List.of("pattern");
Template template = new Template(settings, mappings, Map.of("alias", alias));
List<String> pattern = List.of("pattern");
ComposableIndexTemplate indexTemplate = new ComposableIndexTemplate(
pattern,
template,
Expand All @@ -2058,7 +2058,7 @@ public void testSimulateIndexTemplate() throws Exception {
AliasMetadata simulationAlias = AliasMetadata.builder("simulation-alias").writeIndex(true).build();
ComposableIndexTemplate simulationTemplate = new ComposableIndexTemplate(
pattern,
new Template(null, null, org.opensearch.common.collect.Map.of("simulation-alias", simulationAlias)),
new Template(null, null, Map.of("simulation-alias", simulationAlias)),
Collections.emptyList(),
2L,
1L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
/**
* Java 9 List
*
* todo: deprecate and remove w/ min jdk upgrade to 11?
*
* @opensearch.internal
*/
@Deprecated
public class List {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
/**
* Java 9 Map
*
* todo: deprecate and remove w/ min jdk upgrade to 11?
*
* @opensearch.internal
*/
@Deprecated
public class Map {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
/**
* Java 9 Set
*
* todo: deprecate and remove w/ min jdk upgrade to 11?
*
* @opensearch.internal
*/
@Deprecated
public class Set {

/**
Expand Down
144 changes: 72 additions & 72 deletions libs/grok/src/test/java/org/opensearch/grok/GrokTests.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void testAppendingUniqueValueToScalar() throws Exception {
appendProcessor.execute(ingestDocument);
List<?> list = ingestDocument.getFieldValue(field, List.class);
assertThat(list.size(), equalTo(2));
assertThat(list, equalTo(org.opensearch.common.collect.List.of(originalValue, newValue)));
assertThat(list, equalTo(List.of(originalValue, newValue)));
}

public void testAppendingToListWithDuplicatesDisallowed() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ public void testModifyFieldsOutsideArray() throws Exception {
"values",
new CompoundProcessor(
false,
org.opensearch.common.collect.List.of(
List.of(
new UppercaseProcessor("_tag_upper", null, "_ingest._value", false, "_ingest._value")
),
org.opensearch.common.collect.List.of(
List.of(
new AppendProcessor("_tag", null, template, (model) -> (Collections.singletonList("added")), true)
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import static org.mockito.Mockito.mock;

public class GrokProcessorGetActionTests extends OpenSearchTestCase {
private static final Map<String, String> TEST_PATTERNS = org.opensearch.common.collect.Map.of("PATTERN2", "foo2", "PATTERN1", "foo1");
private static final Map<String, String> TEST_PATTERNS = Map.of("PATTERN2", "foo2", "PATTERN1", "foo1");

public void testRequest() throws Exception {
GrokProcessorGetAction.Request request = new GrokProcessorGetAction.Request(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static class TokenCountFieldType extends NumberFieldMapper.NumberFieldType {
@Override
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
if (hasDocValues() == false) {
return lookup -> org.opensearch.common.collect.List.of();
return lookup -> List.of();
}
return new DocValueFetcher(docValueFormat(format, null), searchLookup.doc().getForField(this));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.opensearch.common.Strings;
import org.opensearch.common.collect.List;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.plugins.Plugin;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import static org.hamcrest.Matchers.instanceOf;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class RankFeaturesFieldMapperTests extends MapperTestCase {

Expand All @@ -58,7 +59,7 @@ protected void assertExistsQuery(MapperService mapperService) {

@Override
protected Collection<? extends Plugin> getPlugins() {
return org.opensearch.common.collect.List.of(new MapperExtrasPlugin());
return List.of(new MapperExtrasPlugin());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -134,7 +135,7 @@ protected void writeFieldValue(XContentBuilder builder) throws IOException {

@Override
protected Collection<? extends Plugin> getPlugins() {
return org.opensearch.common.collect.List.of(new MapperExtrasPlugin());
return List.of(new MapperExtrasPlugin());
}

@Override
Expand All @@ -150,7 +151,7 @@ protected IndexAnalyzers createIndexAnalyzers(IndexSettings indexSettings) {
NamedAnalyzer simple = new NamedAnalyzer("simple", AnalyzerScope.INDEX, new SimpleAnalyzer());
NamedAnalyzer whitespace = new NamedAnalyzer("whitespace", AnalyzerScope.INDEX, new WhitespaceAnalyzer());
return new IndexAnalyzers(
org.opensearch.common.collect.Map.of(
Map.of(
"default",
dflt,
"standard",
Expand All @@ -162,8 +163,8 @@ protected IndexAnalyzers createIndexAnalyzers(IndexSettings indexSettings) {
"whitespace",
whitespace
),
org.opensearch.common.collect.Map.of(),
org.opensearch.common.collect.Map.of()
Map.of(),
Map.of()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

import java.io.IOException;
import java.util.Collections;
import java.util.List;

import static java.util.Arrays.asList;
import static org.apache.lucene.search.MultiTermQuery.CONSTANT_SCORE_REWRITE;
Expand Down Expand Up @@ -154,27 +155,27 @@ public void testFetchSourceValue() throws IOException {
SearchAsYouTypeFieldType fieldType = createFieldType();
fieldType.setIndexAnalyzer(Lucene.STANDARD_ANALYZER);

assertEquals(org.opensearch.common.collect.List.of("value"), fetchSourceValue(fieldType, "value"));
assertEquals(org.opensearch.common.collect.List.of("42"), fetchSourceValue(fieldType, 42L));
assertEquals(org.opensearch.common.collect.List.of("true"), fetchSourceValue(fieldType, true));
assertEquals(List.of("value"), fetchSourceValue(fieldType, "value"));
assertEquals(List.of("42"), fetchSourceValue(fieldType, 42L));
assertEquals(List.of("true"), fetchSourceValue(fieldType, true));

SearchAsYouTypeFieldMapper.PrefixFieldType prefixFieldType = new SearchAsYouTypeFieldMapper.PrefixFieldType(
fieldType.name(),
fieldType.getTextSearchInfo(),
2,
10
);
assertEquals(org.opensearch.common.collect.List.of("value"), fetchSourceValue(prefixFieldType, "value"));
assertEquals(org.opensearch.common.collect.List.of("42"), fetchSourceValue(prefixFieldType, 42L));
assertEquals(org.opensearch.common.collect.List.of("true"), fetchSourceValue(prefixFieldType, true));
assertEquals(List.of("value"), fetchSourceValue(prefixFieldType, "value"));
assertEquals(List.of("42"), fetchSourceValue(prefixFieldType, 42L));
assertEquals(List.of("true"), fetchSourceValue(prefixFieldType, true));

SearchAsYouTypeFieldMapper.ShingleFieldType shingleFieldType = new SearchAsYouTypeFieldMapper.ShingleFieldType(
fieldType.name(),
5,
fieldType.getTextSearchInfo()
);
assertEquals(org.opensearch.common.collect.List.of("value"), fetchSourceValue(shingleFieldType, "value"));
assertEquals(org.opensearch.common.collect.List.of("42"), fetchSourceValue(shingleFieldType, 42L));
assertEquals(org.opensearch.common.collect.List.of("true"), fetchSourceValue(shingleFieldType, true));
assertEquals(List.of("value"), fetchSourceValue(shingleFieldType, "value"));
assertEquals(List.of("42"), fetchSourceValue(shingleFieldType, 42L));
assertEquals(List.of("true"), fetchSourceValue(shingleFieldType, true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
import org.apache.lucene.index.IndexableFieldType;
import org.apache.lucene.util.BytesRef;
import org.opensearch.common.Strings;
import org.opensearch.common.collect.List;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.plugin.analysis.icu.AnalysisICUPlugin;
import org.opensearch.plugins.Plugin;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import static org.hamcrest.Matchers.containsString;
Expand All @@ -69,7 +69,7 @@ protected ICUCollationKeywordFieldMapper.Builder newBuilder() {

@Override
protected Set<String> unsupportedProperties() {
return org.opensearch.common.collect.Set.of("analyzer", "similarity");
return Set.of("analyzer", "similarity");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class Murmur3FieldMapperTests extends MapperTestCase {

Expand All @@ -55,7 +56,7 @@ protected void writeFieldValue(XContentBuilder builder) throws IOException {

@Override
protected Collection<? extends Plugin> getPlugins() {
return org.opensearch.common.collect.List.of(new MapperMurmur3Plugin());
return List.of(new MapperMurmur3Plugin());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ private static class Stats {
private final AtomicLong putBlockListOperations = new AtomicLong();

private Map<String, Long> toMap() {
return org.opensearch.common.collect.Map.of(
return Map.of(
"GetBlob",
getOperations.get(),
"ListBlobs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public AzureRepository(
}

private static Map<String, String> buildLocation(RepositoryMetadata metadata) {
return org.opensearch.common.collect.Map.of(
return Map.of(
"base_path",
Repository.BASE_PATH_SETTING.get(metadata.settings()),
"container",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpResponseInterceptor;
import org.opensearch.common.collect.List;

import java.util.List;
import java.util.Locale;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class GoogleCloudStorageRepository extends MeteredBlobStoreRepository {
}

private static Map<String, String> buildLocation(RepositoryMetadata metadata) {
return org.opensearch.common.collect.Map.of(
return Map.of(
"base_path",
BASE_PATH.get(metadata.settings()),
"bucket",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class S3Repository extends MeteredBlobStoreRepository {
}

private static Map<String, String> buildLocation(RepositoryMetadata metadata) {
return org.opensearch.common.collect.Map.of(
return Map.of(
"base_path",
BASE_PATH_SETTING.get(metadata.settings()),
"bucket",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public void test54ForceBundledJdkEmptyJavaHome() throws Exception {
public void test70CustomPathConfAndJvmOptions() throws Exception {

withCustomConfig(tempConf -> {
final List<String> jvmOptions = org.opensearch.common.collect.List.of("-Xms512m", "-Xmx512m", "-Dlog4j2.disable.jmx=true");
final List<String> jvmOptions = List.of("-Xms512m", "-Xmx512m", "-Dlog4j2.disable.jmx=true");
Files.write(tempConf.resolve("jvm.options"), jvmOptions, CREATE, APPEND);

sh.getEnv().put("OPENSEARCH_JAVA_OPTS", "-XX:-UseCompressedOops");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class FileUtils {
public static List<Path> lsGlob(Path directory, String glob) {
List<Path> paths = new ArrayList<>();
if (Files.exists(directory) == false) {
return org.opensearch.common.collect.List.of();
return List.of();
}
try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory, glob)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private enum PackageManagerCommand {
REMOVE
}

private static Map<PackageManagerCommand, String> RPM_OPTIONS = org.opensearch.common.collect.Map.of(
private static Map<PackageManagerCommand, String> RPM_OPTIONS = Map.of(
PackageManagerCommand.QUERY,
"-qe",
PackageManagerCommand.INSTALL,
Expand All @@ -335,7 +335,7 @@ private enum PackageManagerCommand {
"-e"
);

private static Map<PackageManagerCommand, String> DEB_OPTIONS = org.opensearch.common.collect.Map.of(
private static Map<PackageManagerCommand, String> DEB_OPTIONS = Map.of(
PackageManagerCommand.QUERY,
"-s",
PackageManagerCommand.INSTALL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter,
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
return org.opensearch.common.collect.List.of(new AddDocRestHandler());
return List.of(new AddDocRestHandler());
}

@Override
Expand All @@ -178,15 +178,15 @@ public String getName() {

@Override
public List<Route> routes() {
return org.opensearch.common.collect.List.of(new Route(RestRequest.Method.POST, "/_sys_index_test/add_doc/{id}"));
return List.of(new Route(RestRequest.Method.POST, "/_sys_index_test/add_doc/{id}"));
}

@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
IndexRequest indexRequest = new IndexRequest(SYSTEM_INDEX_NAME);
indexRequest.id(request.param("id"));
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
indexRequest.source(org.opensearch.common.collect.Map.of("some_field", "some_value"));
indexRequest.source(Map.of("some_field", "some_value"));
return channel -> client.index(indexRequest,
new RestStatusToXContentListener<>(channel, r -> r.getLocation(indexRequest.routing())));
}
Expand Down
Loading

0 comments on commit e700e75

Please sign in to comment.