Replace manual copying an array or collection with static methods calls (#24657)
This commit is contained in:
parent
17f8d2debd
commit
f185b69e04
|
@ -20,6 +20,7 @@
|
||||||
package org.elasticsearch.common.inject;
|
package org.elasticsearch.common.inject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -28,9 +29,7 @@ public class ModulesBuilder implements Iterable<Module> {
|
||||||
private final List<Module> modules = new ArrayList<>();
|
private final List<Module> modules = new ArrayList<>();
|
||||||
|
|
||||||
public ModulesBuilder add(Module... newModules) {
|
public ModulesBuilder add(Module... newModules) {
|
||||||
for (Module module : newModules) {
|
Collections.addAll(modules, newModules);
|
||||||
modules.add(module);
|
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,9 +124,7 @@ public class MultiPhrasePrefixQuery extends Query {
|
||||||
Term[][] terms = new Term[termArrays.size()][];
|
Term[][] terms = new Term[termArrays.size()][];
|
||||||
for (int i = 0; i < termArrays.size(); i++) {
|
for (int i = 0; i < termArrays.size(); i++) {
|
||||||
terms[i] = new Term[termArrays.get(i).length];
|
terms[i] = new Term[termArrays.get(i).length];
|
||||||
for (int j = 0; j < termArrays.get(i).length; j++) {
|
System.arraycopy(termArrays.get(i), 0, terms[i], 0, termArrays.get(i).length);
|
||||||
terms[i][j] = termArrays.get(i)[j];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return terms;
|
return terms;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,9 +54,8 @@ public final class IndexWarmer extends AbstractComponent {
|
||||||
ArrayList<Listener> list = new ArrayList<>();
|
ArrayList<Listener> list = new ArrayList<>();
|
||||||
final Executor executor = threadPool.executor(ThreadPool.Names.WARMER);
|
final Executor executor = threadPool.executor(ThreadPool.Names.WARMER);
|
||||||
list.add(new FieldDataWarmer(executor));
|
list.add(new FieldDataWarmer(executor));
|
||||||
for (Listener listener : listeners) {
|
|
||||||
list.add(listener);
|
Collections.addAll(list, listeners);
|
||||||
}
|
|
||||||
this.listeners = Collections.unmodifiableList(list);
|
this.listeners = Collections.unmodifiableList(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.indices.fielddata.cache;
|
package org.elasticsearch.indices.fielddata.cache;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.lucene.index.DirectoryReader;
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
|
@ -134,9 +135,7 @@ public class IndicesFieldDataCache extends AbstractComponent implements RemovalL
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
final Accountable accountable = cache.computeIfAbsent(key, k -> {
|
final Accountable accountable = cache.computeIfAbsent(key, k -> {
|
||||||
cacheHelper.addClosedListener(IndexFieldCache.this);
|
cacheHelper.addClosedListener(IndexFieldCache.this);
|
||||||
for (Listener listener : this.listeners) {
|
Collections.addAll(k.listeners, this.listeners);
|
||||||
k.listeners.add(listener);
|
|
||||||
}
|
|
||||||
final AtomicFieldData fieldData = indexFieldData.loadDirect(context);
|
final AtomicFieldData fieldData = indexFieldData.loadDirect(context);
|
||||||
for (Listener listener : k.listeners) {
|
for (Listener listener : k.listeners) {
|
||||||
try {
|
try {
|
||||||
|
@ -162,9 +161,7 @@ public class IndicesFieldDataCache extends AbstractComponent implements RemovalL
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
final Accountable accountable = cache.computeIfAbsent(key, k -> {
|
final Accountable accountable = cache.computeIfAbsent(key, k -> {
|
||||||
ElasticsearchDirectoryReader.addReaderCloseListener(indexReader, IndexFieldCache.this);
|
ElasticsearchDirectoryReader.addReaderCloseListener(indexReader, IndexFieldCache.this);
|
||||||
for (Listener listener : this.listeners) {
|
Collections.addAll(k.listeners, this.listeners);
|
||||||
k.listeners.add(listener);
|
|
||||||
}
|
|
||||||
final Accountable ifd = (Accountable) indexFieldData.localGlobalDirect(indexReader);
|
final Accountable ifd = (Accountable) indexFieldData.localGlobalDirect(indexReader);
|
||||||
for (Listener listener : k.listeners) {
|
for (Listener listener : k.listeners) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -229,9 +229,8 @@ public final class DirectCandidateGenerator extends CandidateGenerator {
|
||||||
// Merge new candidates into existing ones,
|
// Merge new candidates into existing ones,
|
||||||
// deduping:
|
// deduping:
|
||||||
final Set<Candidate> set = new HashSet<>(candidates);
|
final Set<Candidate> set = new HashSet<>(candidates);
|
||||||
for (int i = 0; i < this.candidates.length; i++) {
|
Collections.addAll(set, this.candidates);
|
||||||
set.add(this.candidates[i]);
|
|
||||||
}
|
|
||||||
this.candidates = set.toArray(new Candidate[set.size()]);
|
this.candidates = set.toArray(new Candidate[set.size()]);
|
||||||
// Sort strongest to weakest:
|
// Sort strongest to weakest:
|
||||||
Arrays.sort(this.candidates, Collections.reverseOrder());
|
Arrays.sort(this.candidates, Collections.reverseOrder());
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.painless.node;
|
package org.elasticsearch.painless.node;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import org.elasticsearch.painless.DefBootstrap;
|
import org.elasticsearch.painless.DefBootstrap;
|
||||||
import org.elasticsearch.painless.Definition;
|
import org.elasticsearch.painless.Definition;
|
||||||
import org.elasticsearch.painless.Globals;
|
import org.elasticsearch.painless.Globals;
|
||||||
|
@ -97,10 +98,7 @@ final class PSubDefCall extends AExpression {
|
||||||
|
|
||||||
if (argument instanceof ILambda) {
|
if (argument instanceof ILambda) {
|
||||||
ILambda lambda = (ILambda) argument;
|
ILambda lambda = (ILambda) argument;
|
||||||
|
Collections.addAll(parameterTypes, lambda.getCaptures());
|
||||||
for (Type capture : lambda.getCaptures()) {
|
|
||||||
parameterTypes.add(capture);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
argument.write(writer, globals);
|
argument.write(writer, globals);
|
||||||
|
|
Loading…
Reference in New Issue