From f5636c082e29e5d14c3742148a30f0a8a75dbdb3 Mon Sep 17 00:00:00 2001 From: Frank van der Heijden Date: Mon, 30 Aug 2021 23:09:45 +0200 Subject: [PATCH] No more guava --- .../serverutils/common/util/HashGraph.java | 48 +++++++++++++++++++ .../common/utils/DependencyUtils.java | 8 ++-- build.gradle | 20 -------- 3 files changed, 51 insertions(+), 25 deletions(-) create mode 100644 Common/src/main/java/net/frankheijden/serverutils/common/util/HashGraph.java diff --git a/Common/src/main/java/net/frankheijden/serverutils/common/util/HashGraph.java b/Common/src/main/java/net/frankheijden/serverutils/common/util/HashGraph.java new file mode 100644 index 0000000..e17956c --- /dev/null +++ b/Common/src/main/java/net/frankheijden/serverutils/common/util/HashGraph.java @@ -0,0 +1,48 @@ +package net.frankheijden.serverutils.common.util; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class HashGraph { + + private final Set nodes; + private final Map> successors; + private final Map> predecessors; + + public HashGraph() { + this(16); + } + + /** + * Constructs a new hash-based graph. + */ + public HashGraph(int initialCapacity) { + this.nodes = new HashSet<>(initialCapacity); + this.successors = new HashMap<>(initialCapacity); + this.predecessors = new HashMap<>(initialCapacity); + } + + public void addNode(T node) { + this.nodes.add(node); + } + + public void putEdge(T from, T to) { + this.successors.computeIfAbsent(from, k -> new HashSet<>()).add(to); + this.predecessors.computeIfAbsent(to, k -> new HashSet<>()).add(from); + } + + public Set nodes() { + return this.nodes; + } + + public Set successors(T node) { + return this.successors.getOrDefault(node, Collections.emptySet()); + } + + public Set predecessors(T node) { + return this.predecessors.getOrDefault(node, Collections.emptySet()); + } +} diff --git a/Common/src/main/java/net/frankheijden/serverutils/common/utils/DependencyUtils.java b/Common/src/main/java/net/frankheijden/serverutils/common/utils/DependencyUtils.java index ea0022b..cec4934 100644 --- a/Common/src/main/java/net/frankheijden/serverutils/common/utils/DependencyUtils.java +++ b/Common/src/main/java/net/frankheijden/serverutils/common/utils/DependencyUtils.java @@ -1,8 +1,5 @@ package net.frankheijden.serverutils.common.utils; -import com.google.common.graph.Graph; -import com.google.common.graph.GraphBuilder; -import com.google.common.graph.MutableGraph; import java.util.ArrayList; import java.util.Deque; import java.util.HashMap; @@ -10,6 +7,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; +import net.frankheijden.serverutils.common.util.HashGraph; public class DependencyUtils { @@ -22,7 +20,7 @@ public class DependencyUtils { */ @SuppressWarnings("UnstableApiUsage") public static List determineOrder(Map> dependencyMap) throws IllegalStateException { - MutableGraph dependencyGraph = GraphBuilder.directed().allowsSelfLoops(true).build(); + HashGraph dependencyGraph = new HashGraph<>(); for (T node : dependencyMap.keySet()) { dependencyGraph.addNode(node); } @@ -45,7 +43,7 @@ public class DependencyUtils { @SuppressWarnings("UnstableApiUsage") private static void visitNode( - Graph dependencyGraph, + HashGraph dependencyGraph, T node, Map marks, List orderedList, diff --git a/build.gradle b/build.gradle index 091d40c..9fb6834 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,6 @@ subprojects { implementation "cloud.commandframework:cloud-core:${rootProject.cloudVersion}" implementation "cloud.commandframework:cloud-brigadier:${rootProject.cloudVersion}" implementation 'com.github.FrankHeijden:MinecraftReflection:1.0.0' - implementation 'com.google.guava:guava:30.1.1-jre' implementation 'com.google.code.gson:gson:2.8.6' implementation 'me.lucko:commodore:1.10' compileOnly 'com.mojang:brigadier:1.0.17' @@ -72,26 +71,7 @@ subprojects { exclude 'com/mojang/**' exclude 'javax/annotation/**' exclude 'org/checkerframework/**' - exclude 'com/google/errorprone/**' - exclude 'com/google/j2objc/**' - exclude 'com/google/thirdparty/**' - exclude 'com/google/common/annotations/**' - exclude 'com/google/common/base/**' - exclude 'com/google/common/cache/**' - exclude 'com/google/common/collect/**' - exclude 'com/google/common/escape/**' - exclude 'com/google/common/eventbus/**' - exclude 'com/google/common/hash/**' - exclude 'com/google/common/html/**' - exclude 'com/google/common/io/**' - exclude 'com/google/common/math/**' - exclude 'com/google/common/net/**' - exclude 'com/google/common/primitives/**' - exclude 'com/google/common/reflect/**' - exclude 'com/google/common/util/**' - exclude 'com/google/common/xml/**' relocate 'com.google.gson', dependencyDir + '.gson' - relocate 'com.google.common.graph', dependencyDir + '.common.graph' relocate 'dev.frankheijden.minecraftreflection', dependencyDir + '.minecraftreflection' relocate 'cloud.commandframework', dependencyDir + '.cloud' relocate 'me.lucko.commodore', dependencyDir + '.commodore'