/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.collect.HashMultimap * com.google.common.collect.Multimap */ package net.minecraft.util; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Consumer; public class DependencySorter> { private final Map contents = new HashMap(); public DependencySorter addEntry(K id, V value) { this.contents.put(id, value); return this; } private void visitDependenciesAndElement(Multimap dependencies, Set alreadyVisited, K id, BiConsumer output) { if (!alreadyVisited.add(id)) { return; } dependencies.get(id).forEach(dependency -> this.visitDependenciesAndElement(dependencies, alreadyVisited, dependency, output)); Entry current = (Entry)this.contents.get(id); if (current != null) { output.accept(id, current); } } private static boolean isCyclic(Multimap directDependencies, K from, K to) { Collection dependencies = directDependencies.get(to); if (dependencies.contains(from)) { return true; } return dependencies.stream().anyMatch(dep -> DependencySorter.isCyclic(directDependencies, from, dep)); } private static void addDependencyIfNotCyclic(Multimap directDependencies, K from, K to) { if (!DependencySorter.isCyclic(directDependencies, from, to)) { directDependencies.put(from, to); } } public void orderByDependencies(BiConsumer output) { HashMultimap directDependencies = HashMultimap.create(); this.contents.forEach((arg_0, arg_1) -> DependencySorter.lambda$orderByDependencies$3((Multimap)directDependencies, arg_0, arg_1)); this.contents.forEach((arg_0, arg_1) -> DependencySorter.lambda$orderByDependencies$5((Multimap)directDependencies, arg_0, arg_1)); HashSet alreadyVisited = new HashSet(); this.contents.keySet().forEach(arg_0 -> this.lambda$orderByDependencies$6((Multimap)directDependencies, alreadyVisited, output, arg_0)); } private /* synthetic */ void lambda$orderByDependencies$6(Multimap directDependencies, Set alreadyVisited, BiConsumer output, Object topId) { this.visitDependenciesAndElement(directDependencies, alreadyVisited, topId, output); } private static /* synthetic */ void lambda$orderByDependencies$5(Multimap directDependencies, Object id, Entry value) { value.visitOptionalDependencies(dep -> DependencySorter.addDependencyIfNotCyclic(directDependencies, id, dep)); } private static /* synthetic */ void lambda$orderByDependencies$3(Multimap directDependencies, Object id, Entry value) { value.visitRequiredDependencies(dep -> DependencySorter.addDependencyIfNotCyclic(directDependencies, id, dep)); } public static interface Entry { public void visitRequiredDependencies(Consumer var1); public void visitOptionalDependencies(Consumer var1); } }