67 lines
1.7 KiB
Java
67 lines
1.7 KiB
Java
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<String, String> problems;
|
|
private final Supplier<String> path;
|
|
@Nullable
|
|
private String pathCache;
|
|
|
|
public Collector() {
|
|
this(HashMultimap.create(), () -> "");
|
|
}
|
|
|
|
private Collector(Multimap<String, String> problems, Supplier<String> 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<String, String> get() {
|
|
return ImmutableMultimap.copyOf(this.problems);
|
|
}
|
|
|
|
public Optional<String> getReport() {
|
|
Multimap<String, String> 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();
|
|
}
|
|
}
|
|
}
|
|
}
|