mirror of https://github.com/apache/lucene.git
LUCENE-2562: Use Map#copyOf(), List#copyOf() and Set#copyOf() instead of Collections#unmodifiableMap(), unmodifiableList() and unmodifiableSet()
This commit is contained in:
parent
cd0706bd43
commit
511efc89fe
|
@ -667,7 +667,7 @@ public final class CustomAnalyzerPanelProvider implements CustomAnalyzerPanelOpe
|
|||
if (index < 0 || index > cfParamsList.size()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return Collections.unmodifiableMap(cfParamsList.get(index));
|
||||
return Map.copyOf(cfParamsList.get(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -693,7 +693,7 @@ public final class CustomAnalyzerPanelProvider implements CustomAnalyzerPanelOpe
|
|||
if (index < 0 || index > tfParamsList.size()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return Collections.unmodifiableMap(tfParamsList.get(index));
|
||||
return Map.copyOf(tfParamsList.get(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package org.apache.lucene.luke.models.analysis;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
@ -57,7 +56,7 @@ public interface Analysis {
|
|||
* Returns attributes of this token.
|
||||
*/
|
||||
public List<TokenAttribute> getAttributes() {
|
||||
return Collections.unmodifiableList(attributes);
|
||||
return List.copyOf(attributes);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,7 +83,7 @@ public interface Analysis {
|
|||
* Returns value of this attribute.
|
||||
*/
|
||||
public Map<String, String> getAttValues() {
|
||||
return Collections.unmodifiableMap(attValues);
|
||||
return Map.copyOf(attValues);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
|
@ -92,7 +91,7 @@ public final class AnalysisImpl implements Analysis {
|
|||
} catch (NoSuchMethodException e) {
|
||||
}
|
||||
}
|
||||
presetAnalyzerTypes = Collections.unmodifiableList(types);
|
||||
presetAnalyzerTypes = List.copyOf(types);
|
||||
}
|
||||
return presetAnalyzerTypes;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package org.apache.lucene.luke.models.analysis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -100,14 +99,14 @@ public final class CustomAnalyzerConfig {
|
|||
* Returns CharFilters configurations.
|
||||
*/
|
||||
List<ComponentConfig> getCharFilterConfigs() {
|
||||
return Collections.unmodifiableList(charFilterConfigs);
|
||||
return List.copyOf(charFilterConfigs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TokenFilters configurations.
|
||||
*/
|
||||
List<ComponentConfig> getTokenFilterConfigs() {
|
||||
return Collections.unmodifiableList(tokenFilterConfigs);
|
||||
return List.copyOf(tokenFilterConfigs);
|
||||
}
|
||||
|
||||
static class ComponentConfig {
|
||||
|
|
|
@ -200,7 +200,7 @@ public final class CommitsImpl extends LukeModel implements Commits {
|
|||
if (dir == null) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return Collections.unmodifiableMap(commitMap);
|
||||
return Map.copyOf(commitMap);
|
||||
}
|
||||
|
||||
private SegmentInfos findSegmentInfos(long commitGen) throws LukeException, IOException {
|
||||
|
@ -214,11 +214,11 @@ public final class CommitsImpl extends LukeModel implements Commits {
|
|||
|
||||
static String toDisplaySize(long size) {
|
||||
if (size < 1024) {
|
||||
return String.valueOf(size) + " B";
|
||||
return size + " B";
|
||||
} else if (size < 1048576) {
|
||||
return String.valueOf(size / 1024) + " KB";
|
||||
return (size / 1024) + " KB";
|
||||
} else {
|
||||
return String.valueOf(size / 1048576) + " MB";
|
||||
return (size / 1048576) + " MB";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package org.apache.lucene.luke.models.overview;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
@ -63,6 +62,6 @@ final class TopTerms {
|
|||
topTermsCache.put(field, topTerms);
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(topTermsCache.get(field));
|
||||
return List.copyOf(topTermsCache.get(field));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.lucene.luke.models.search;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.lucene.queries.mlt.MoreLikeThis;
|
||||
|
@ -71,7 +70,7 @@ public final class MLTConfig {
|
|||
}
|
||||
|
||||
private MLTConfig(Builder builder) {
|
||||
this.fields = Collections.unmodifiableList(builder.fields);
|
||||
this.fields = List.copyOf(builder.fields);
|
||||
this.maxDocFreq = builder.maxDocFreq;
|
||||
this.minDocFreq = builder.minDocFreq;
|
||||
this.minTermFreq = builder.minTermFreq;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package org.apache.lucene.luke.models.search;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
@ -173,7 +172,7 @@ public final class QueryParserConfig {
|
|||
this.autoGenerateMultiTermSynonymsPhraseQuery = builder.autoGenerateMultiTermSynonymsPhraseQuery;
|
||||
this.autoGeneratePhraseQueries = builder.autoGeneratePhraseQueries;
|
||||
this.splitOnWhitespace = builder.splitOnWhitespace;
|
||||
this.typeMap = Collections.unmodifiableMap(builder.typeMap);
|
||||
this.typeMap = Map.copyOf(builder.typeMap);
|
||||
}
|
||||
|
||||
public boolean isUseClassicParser() {
|
||||
|
|
|
@ -277,7 +277,7 @@ public final class SearchImpl extends LukeModel implements Search {
|
|||
this.exactHitsCount = exactHitsCount;
|
||||
this.query = Objects.requireNonNull(query);
|
||||
this.sort = sort;
|
||||
this.fieldsToLoad = fieldsToLoad == null ? null : Collections.unmodifiableSet(fieldsToLoad);
|
||||
this.fieldsToLoad = fieldsToLoad == null ? null : Set.copyOf(fieldsToLoad);
|
||||
searcher.setSimilarity(createSimilarity(Objects.requireNonNull(simConfig)));
|
||||
|
||||
try {
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.lucene.luke.models.search;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -92,7 +91,7 @@ public final class SearchResults {
|
|||
* Returns the documents of the current page.
|
||||
*/
|
||||
public List<Doc> getHits() {
|
||||
return Collections.unmodifiableList(hits);
|
||||
return List.copyOf(hits);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -152,7 +151,7 @@ public final class SearchResults {
|
|||
* Returns the field data of this document.
|
||||
*/
|
||||
public Map<String, String[]> getFieldValues() {
|
||||
return Collections.unmodifiableMap(fieldValues);
|
||||
return Map.copyOf(fieldValues);
|
||||
}
|
||||
|
||||
private Doc() {
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.lucene.luke.util.reflection;
|
|||
import java.io.IOException;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
@ -55,7 +54,7 @@ final class SubtypeCollector<T> implements Runnable {
|
|||
}
|
||||
|
||||
Set<Class<? extends T>> getTypes() {
|
||||
return Collections.unmodifiableSet(types);
|
||||
return Set.copyOf(types);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue