Refactor unbox optional collection to utility class
This commit is contained in:
parent
f42681c390
commit
1543b539ba
@ -4,10 +4,12 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@ -275,4 +277,8 @@ public class UtilCollections
|
||||
return total.toString();
|
||||
}
|
||||
|
||||
public static <T> List<T> unboxPresent(Collection<Optional<T>> optionalList)
|
||||
{
|
||||
return optionalList.stream().filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import mineplex.core.common.jsonchat.JsonMessage;
|
||||
import mineplex.core.common.util.BukkitFuture;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilCollections;
|
||||
import mineplex.core.common.util.UtilFuture;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.incognito.IncognitoManager;
|
||||
@ -554,7 +555,7 @@ public class ReportManager
|
||||
CompletableFuture<Optional<Report>> future = _reportRepository.getReportsHandling(accountId).thenApply(reportIds ->
|
||||
reportIds.stream().map(_reportRepository::getReport).collect(Collectors.toList())
|
||||
).thenCompose(UtilFuture::sequence)
|
||||
.thenApply(reportOptionals -> reportOptionals.stream().filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()))
|
||||
.thenApply(UtilCollections::unboxPresent)
|
||||
.thenCompose(reports -> UtilFuture.filter(reports, this::isActiveReport)).thenApply(reports ->
|
||||
{
|
||||
Report report = null;
|
||||
|
Loading…
Reference in New Issue
Block a user