Skip to content

Commit

Permalink
Remove unnecessary wrapping of unmodifiable collections
Browse files Browse the repository at this point in the history
  • Loading branch information
idegtiarenko committed Oct 26, 2023
1 parent 18b1bf5 commit 0bd11f1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import org.elasticsearch.test.tasks.MockTaskManagerListener;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;

/**
* MockTaskManagerListener that records all task registration/unregistration events
Expand Down Expand Up @@ -55,13 +55,11 @@ public synchronized List<Tuple<Boolean, TaskInfo>> getEvents() {
}

public synchronized List<TaskInfo> getRegistrationEvents() {
List<TaskInfo> events = this.events.stream().filter(Tuple::v1).map(Tuple::v2).toList();
return Collections.unmodifiableList(events);
return this.events.stream().filter(Tuple::v1).map(Tuple::v2).toList();
}

public synchronized List<TaskInfo> getUnregistrationEvents() {
List<TaskInfo> events = this.events.stream().filter(event -> event.v1() == false).map(Tuple::v2).toList();
return Collections.unmodifiableList(events);
return this.events.stream().filter(Predicate.not(Tuple::v1)).map(Tuple::v2).toList();
}

public synchronized void reset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ private static ScriptContextInfo mutate(ScriptContextInfo instance, Set<String>
}

static Set<ScriptContextInfo> mutateOne(Collection<ScriptContextInfo> instances) {
if (instances.size() == 0) {
return Collections.unmodifiableSet(Set.of(randomInstance()));
if (instances.isEmpty()) {
return Set.of(randomInstance());
}
ArrayList<ScriptContextInfo> mutated = new ArrayList<>(instances);
int mutateIndex = randomIntBetween(0, instances.size() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ private static ParameterInfo mutate(ParameterInfo instance) {
}

static List<ParameterInfo> mutateOne(List<ParameterInfo> instances) {
if (instances.size() == 0) {
return Collections.unmodifiableList(List.of(randomInstance()));
if (instances.isEmpty()) {
return List.of(randomInstance());
}
ArrayList<ParameterInfo> mutated = new ArrayList<>(instances);
int mutateIndex = randomIntBetween(0, instances.size() - 1);
Expand Down

0 comments on commit 0bd11f1

Please sign in to comment.