package net.minecraft.util; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; import java.util.Optional; import java.util.function.Supplier; import java.util.stream.Collectors; import org.jetbrains.annotations.Nullable; public interface ProblemReporter { ProblemReporter forChild(String name); void report(String message); public static class Collector implements ProblemReporter { private final Multimap problems; private final Supplier path; @Nullable private String pathCache; public Collector() { this(HashMultimap.create(), () -> ""); } private Collector(Multimap problems, Supplier path) { this.problems = problems; this.path = path; } private String getPath() { if (this.pathCache == null) { this.pathCache = (String)this.path.get(); } return this.pathCache; } @Override public ProblemReporter forChild(String name) { return new ProblemReporter.Collector(this.problems, () -> this.getPath() + name); } @Override public void report(String message) { this.problems.put(this.getPath(), message); } public Multimap get() { return ImmutableMultimap.copyOf(this.problems); } public Optional getReport() { Multimap multimap = this.get(); if (!multimap.isEmpty()) { String string = (String)multimap.asMap() .entrySet() .stream() .map(entry -> " at " + (String)entry.getKey() + ": " + String.join("; ", (Iterable)entry.getValue())) .collect(Collectors.joining("\n")); return Optional.of(string); } else { return Optional.empty(); } } } }