Use toList in stream chains

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-10-22 02:23:14 +02:00
parent 7891cc5bbe
commit b1ef97b5af
5 changed files with 19 additions and 23 deletions

View File

@ -12,7 +12,6 @@ import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
/**
* Holder of custom audiences.
@ -97,7 +96,7 @@ public class AudienceRegistry {
if (this.isEmpty()) {
return Collections.emptyList();
} else {
return this.registry.values().stream().flatMap(Collection::stream).collect(Collectors.toUnmodifiableList());
return this.registry.values().stream().flatMap(Collection::stream).toList();
}
}
@ -128,6 +127,6 @@ public class AudienceRegistry {
* @return the matching audience members
*/
public @NotNull Iterable<? extends Audience> of(@NotNull Predicate<Audience> filter) {
return this.registry.values().stream().flatMap(Collection::stream).filter(filter).collect(Collectors.toUnmodifiableList());
return this.registry.values().stream().flatMap(Collection::stream).filter(filter).toList();
}
}

View File

@ -147,7 +147,7 @@ public class BossBarManager {
if (holders == null) {
return Collections.emptyList();
} else {
return holders.stream().map(holder -> holder.bar).collect(Collectors.toUnmodifiableList());
return holders.stream().map(holder -> holder.bar).toList();
}
}

View File

@ -57,7 +57,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
/**
* Could be a player, a monster, or an object.
@ -1571,8 +1570,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
Vec end = start.add(position.direction().mul(range));
List<Entity> nearby = instance.getNearbyEntities(position, range).stream()
.filter(e -> e != this && e.boundingBox.intersect(start, end) && predicate.test(e))
.collect(Collectors.toList());
.filter(e -> e != this && e.boundingBox.intersect(start, end) && predicate.test(e)).toList();
if (nearby.isEmpty()) {
return null;
}

View File

@ -11,7 +11,6 @@ import net.minestom.server.utils.identity.NamedAndIdentified;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.stream.Collectors;
/**
* Represents the data sent to the player when responding to a ping event.
@ -197,8 +196,7 @@ public class ResponseData {
@Deprecated(forRemoval = true) // to throw an error for people using it - this method is *horrible*
public List<PingPlayer> getPlayers() {
return this.entries.stream()
.map(entry -> PingPlayer.of(PlainComponentSerializer.plain().serialize(entry.getName()), entry.getUuid()))
.collect(Collectors.toUnmodifiableList());
.map(entry -> PingPlayer.of(PlainComponentSerializer.plain().serialize(entry.getName()), entry.getUuid())).toList();
}
/**
@ -328,6 +326,7 @@ public class ResponseData {
/**
* Represents a player line in the server list hover.
*
* @deprecated See {@link NamedAndIdentified}
*/
@Deprecated

View File

@ -14,7 +14,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/**
* An object which manages all the {@link Task}'s.
@ -151,10 +150,10 @@ public final class SchedulerManager implements IExtensionObserver {
public ObjectCollection<Task> getTasks() {
return tasks.values();
}
/**
* Returns the task associated with this task id
*
*
* @param id the id of the task
* @return task the task itself
*/
@ -171,10 +170,10 @@ public final class SchedulerManager implements IExtensionObserver {
public ObjectCollection<Task> getShutdownTasks() {
return shutdownTasks.values();
}
/**
* Returns the shutdown task associated with this task id
*
*
* @param id the id of the task
* @return task the shutdown task itself
*/
@ -204,8 +203,9 @@ public final class SchedulerManager implements IExtensionObserver {
/**
* Called when a Task from an extension is scheduled.
*
* @param owningExtension the name of the extension which scheduled the task
* @param task the task that has been scheduled
* @param task the task that has been scheduled
*/
void onScheduleFromExtension(String owningExtension, Task task) {
List<Task> scheduledForThisExtension = extensionTasks.computeIfAbsent(owningExtension, s -> new CopyOnWriteArrayList<>());
@ -217,8 +217,9 @@ public final class SchedulerManager implements IExtensionObserver {
/**
* Called when a Task from an extension is scheduled for server shutdown.
*
* @param owningExtension the name of the extension which scheduled the task
* @param task the task that has been scheduled
* @param task the task that has been scheduled
*/
void onScheduleShutdownFromExtension(String owningExtension, Task task) {
List<Task> scheduledForThisExtension = extensionShutdownTasks.computeIfAbsent(owningExtension, s -> new CopyOnWriteArrayList<>());
@ -230,25 +231,24 @@ public final class SchedulerManager implements IExtensionObserver {
/**
* Unschedules all non-transient tasks ({@link Task#isTransient()}) from this scheduler. Tasks are allowed to complete
*
* @param extension the name of the extension to unschedule tasks from
* @see Task#isTransient()
*/
public void removeExtensionTasksOnUnload(String extension) {
List<Task> scheduledForThisExtension = extensionTasks.get(extension);
if(scheduledForThisExtension != null) {
if (scheduledForThisExtension != null) {
List<Task> toCancel = scheduledForThisExtension.stream()
.filter(t -> !t.isTransient())
.collect(Collectors.toList());
.filter(t -> !t.isTransient()).toList();
toCancel.forEach(Task::cancel);
scheduledForThisExtension.removeAll(toCancel);
}
List<Task> shutdownScheduledForThisExtension = extensionShutdownTasks.get(extension);
if(shutdownScheduledForThisExtension != null) {
if (shutdownScheduledForThisExtension != null) {
List<Task> toCancel = shutdownScheduledForThisExtension.stream()
.filter(t -> !t.isTransient())
.collect(Collectors.toList());
.filter(t -> !t.isTransient()).toList();
toCancel.forEach(Task::cancel);
shutdownScheduledForThisExtension.removeAll(toCancel);
shutdownTasks.values().removeAll(toCancel);