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.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors;
/** /**
* Holder of custom audiences. * Holder of custom audiences.
@ -97,7 +96,7 @@ public class AudienceRegistry {
if (this.isEmpty()) { if (this.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} else { } 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 * @return the matching audience members
*/ */
public @NotNull Iterable<? extends Audience> of(@NotNull Predicate<Audience> filter) { 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) { if (holders == null) {
return Collections.emptyList(); return Collections.emptyList();
} else { } 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.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
/** /**
* Could be a player, a monster, or an object. * 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)); Vec end = start.add(position.direction().mul(range));
List<Entity> nearby = instance.getNearbyEntities(position, range).stream() List<Entity> nearby = instance.getNearbyEntities(position, range).stream()
.filter(e -> e != this && e.boundingBox.intersect(start, end) && predicate.test(e)) .filter(e -> e != this && e.boundingBox.intersect(start, end) && predicate.test(e)).toList();
.collect(Collectors.toList());
if (nearby.isEmpty()) { if (nearby.isEmpty()) {
return null; return null;
} }

View File

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

View File

@ -14,7 +14,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/** /**
* An object which manages all the {@link Task}'s. * An object which manages all the {@link Task}'s.
@ -204,6 +203,7 @@ public final class SchedulerManager implements IExtensionObserver {
/** /**
* Called when a Task from an extension is scheduled. * Called when a Task from an extension is scheduled.
*
* @param owningExtension the name of the extension which scheduled the task * @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
*/ */
@ -217,6 +217,7 @@ public final class SchedulerManager implements IExtensionObserver {
/** /**
* Called when a Task from an extension is scheduled for server shutdown. * Called when a Task from an extension is scheduled for server shutdown.
*
* @param owningExtension the name of the extension which scheduled the task * @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
*/ */
@ -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 * 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 * @param extension the name of the extension to unschedule tasks from
* @see Task#isTransient() * @see Task#isTransient()
*/ */
public void removeExtensionTasksOnUnload(String extension) { public void removeExtensionTasksOnUnload(String extension) {
List<Task> scheduledForThisExtension = extensionTasks.get(extension); List<Task> scheduledForThisExtension = extensionTasks.get(extension);
if(scheduledForThisExtension != null) { if (scheduledForThisExtension != null) {
List<Task> toCancel = scheduledForThisExtension.stream() List<Task> toCancel = scheduledForThisExtension.stream()
.filter(t -> !t.isTransient()) .filter(t -> !t.isTransient()).toList();
.collect(Collectors.toList());
toCancel.forEach(Task::cancel); toCancel.forEach(Task::cancel);
scheduledForThisExtension.removeAll(toCancel); scheduledForThisExtension.removeAll(toCancel);
} }
List<Task> shutdownScheduledForThisExtension = extensionShutdownTasks.get(extension); List<Task> shutdownScheduledForThisExtension = extensionShutdownTasks.get(extension);
if(shutdownScheduledForThisExtension != null) { if (shutdownScheduledForThisExtension != null) {
List<Task> toCancel = shutdownScheduledForThisExtension.stream() List<Task> toCancel = shutdownScheduledForThisExtension.stream()
.filter(t -> !t.isTransient()) .filter(t -> !t.isTransient()).toList();
.collect(Collectors.toList());
toCancel.forEach(Task::cancel); toCancel.forEach(Task::cancel);
shutdownScheduledForThisExtension.removeAll(toCancel); shutdownScheduledForThisExtension.removeAll(toCancel);
shutdownTasks.values().removeAll(toCancel); shutdownTasks.values().removeAll(toCancel);