Skip to content

Commit 6decee2

Browse files
authored
Replace Function<Type, Boolean> with Predicate (elastic#63851)
In a few cases we use a Function that returns a Boolean, for which we could simply use a Predicate instead
1 parent 65ceee8 commit 6decee2

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

server/src/main/java/org/elasticsearch/index/search/NestedHelper.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,18 @@
3535
import org.elasticsearch.index.mapper.ObjectMapper;
3636

3737
import java.util.function.Function;
38+
import java.util.function.Predicate;
3839

3940
/** Utility class to filter parent and children clauses when building nested
4041
* queries. */
4142
public final class NestedHelper {
4243

4344
private final Function<String, ObjectMapper> objectMapperLookup;
44-
private final Function<String, Boolean> isMappedFieldFunction;
45+
private final Predicate<String> isMappedFieldPredicate;
4546

46-
public NestedHelper(Function<String, ObjectMapper> objectMapperLookup, Function<String, Boolean> isMappedFieldFunction) {
47+
public NestedHelper(Function<String, ObjectMapper> objectMapperLookup, Predicate<String> isMappedFieldPredicate) {
4748
this.objectMapperLookup = objectMapperLookup;
48-
this.isMappedFieldFunction = isMappedFieldFunction;
49+
this.isMappedFieldPredicate = isMappedFieldPredicate;
4950
}
5051

5152
/** Returns true if the given query might match nested documents. */
@@ -106,7 +107,7 @@ boolean mightMatchNestedDocs(String field) {
106107
// we might add a nested filter when it is nor required.
107108
return true;
108109
}
109-
if (isMappedFieldFunction.apply(field) == false) {
110+
if (isMappedFieldPredicate.test(field) == false) {
110111
// field does not exist
111112
return false;
112113
}
@@ -175,7 +176,7 @@ boolean mightMatchNonNestedDocs(String field, String nestedPath) {
175176
// we might add a nested filter when it is nor required.
176177
return true;
177178
}
178-
if (isMappedFieldFunction.apply(field) == false) {
179+
if (isMappedFieldPredicate.test(field) == false) {
179180
return false;
180181
}
181182
for (String parent = parentObject(field); parent != null; parent = parentObject(parent)) {

server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
import org.elasticsearch.common.util.concurrent.AtomicArray;
3737
import org.elasticsearch.common.util.concurrent.EsExecutors;
3838
import org.elasticsearch.index.IndexNotFoundException;
39-
import org.elasticsearch.index.VersionType;
4039
import org.elasticsearch.index.IndexingPressure;
40+
import org.elasticsearch.index.VersionType;
4141
import org.elasticsearch.indices.SystemIndices;
4242
import org.elasticsearch.tasks.Task;
4343
import org.elasticsearch.test.ESTestCase;
@@ -50,7 +50,7 @@
5050
import java.util.Map;
5151
import java.util.Set;
5252
import java.util.concurrent.ExecutorService;
53-
import java.util.function.Function;
53+
import java.util.function.Predicate;
5454

5555
import static java.util.Collections.emptySet;
5656
import static java.util.Collections.singleton;
@@ -108,7 +108,7 @@ public void testSomeFail() {
108108

109109

110110
private void indicesThatCannotBeCreatedTestCase(Set<String> expected,
111-
BulkRequest bulkRequest, Function<String, Boolean> shouldAutoCreate) {
111+
BulkRequest bulkRequest, Predicate<String> shouldAutoCreate) {
112112
ClusterService clusterService = mock(ClusterService.class);
113113
ClusterState state = mock(ClusterState.class);
114114
when(state.getMetadata()).thenReturn(Metadata.EMPTY_METADATA);
@@ -139,7 +139,7 @@ boolean needToCheck() {
139139

140140
@Override
141141
boolean shouldAutoCreate(String index, ClusterState state) {
142-
return shouldAutoCreate.apply(index);
142+
return shouldAutoCreate.test(index);
143143
}
144144

145145
@Override

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/DataCountsReporter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import java.util.Date;
1616
import java.util.Locale;
17-
import java.util.function.Function;
17+
import java.util.function.Predicate;
1818

1919

2020
/**
@@ -49,7 +49,7 @@ public class DataCountsReporter {
4949
private long logEvery = 1;
5050
private long logCount = 0;
5151

52-
private Function<Long, Boolean> reportingBoundaryFunction;
52+
private Predicate<Long> reportingBoundaryFunction;
5353

5454
private DataStreamDiagnostics diagnostics;
5555

@@ -93,7 +93,7 @@ public void reportRecordWritten(long inputFieldCount, long recordTimeMs) {
9393

9494
// report at various boundaries
9595
long totalRecords = getInputRecordCount();
96-
if (reportingBoundaryFunction.apply(totalRecords)) {
96+
if (reportingBoundaryFunction.test(totalRecords)) {
9797
logStatus(totalRecords);
9898
}
9999

0 commit comments

Comments
 (0)