Fix /reporthandle command

This commit is contained in:
Keir Nellyer 2016-06-24 17:45:56 +01:00
parent d178e9112b
commit 871bb04451
1 changed files with 9 additions and 9 deletions

View File

@ -1,8 +1,9 @@
package mineplex.core.report.command;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
@ -32,17 +33,16 @@ public class ReportHandleCommand extends CommandBase<ReportPlugin>
{
ReportManager reportManager = Plugin.getReportManager();
ReportRepository reportRepository = reportManager.getReportRepository();
Map<Report, Double> reportPriorities = new ConcurrentHashMap<>();
Map<Report, Double> reportPriorities = Collections.synchronizedMap(new HashMap<>());
// the below fetches the ids of all unhandled reports and gets a Report object for each of these ids
// the priority of the report is then calculated and the results placed in a map
CompletableFuture.allOf(
reportRepository.getUnhandledReports().thenCompose(reportRepository::getReports).thenAccept(reports ->
reports.stream().map(report ->
reportManager.calculatePriority(report).thenAccept(priority ->
reportPriorities.put(report, priority)
)
).toArray(CompletableFuture[]::new))
reportRepository.getUnhandledReports().thenCompose(reportRepository::getReports).thenAccept(reports ->
CompletableFuture.allOf(reports.stream().map(report ->
reportManager.calculatePriority(report).thenAccept(priority ->
reportPriorities.put(report, priority)
)
).toArray(CompletableFuture[]::new)).join()
).thenApply(aVoid ->
{
Map.Entry<Report, Double> mostImportant = null;