From 1df4e181cfa43f0f8f23e2bd35320c88f39848e7 Mon Sep 17 00:00:00 2001 From: GedMarc Date: Sun, 14 Apr 2024 07:40:33 +0200 Subject: [PATCH] Cleanup rest service dependencies for Vert.x --- .../guicedinjection/GuiceContext.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/guicedee/guicedinjection/GuiceContext.java b/src/main/java/com/guicedee/guicedinjection/GuiceContext.java index 24cf021..41fe3a0 100644 --- a/src/main/java/com/guicedee/guicedinjection/GuiceContext.java +++ b/src/main/java/com/guicedee/guicedinjection/GuiceContext.java @@ -29,6 +29,8 @@ import java.util.regex.Pattern; import static com.guicedee.guicedinjection.properties.GlobalProperties.getSystemPropertyOrEnvironment; +import static java.util.stream.Collectors.groupingBy; +import static java.util.stream.Collectors.toSet; /** * Provides an interface for reflection and injection in one. @@ -772,8 +774,10 @@ public static void setScanner(ClassGraph scanner) private void loadPostStartups() { Set startupSet = loadPostStartupServices(); + Map> groupedPostStartup = startupSet.stream() + .collect(groupingBy(IGuicePostStartup::sortOrder, toSet())); + /* Map>> postStartupGroups = new TreeMap<>(); - Map>> postStartupGroups = new TreeMap<>(); for (IGuicePostStartup postStartup : startupSet) { Integer sortOrder = postStartup.sortOrder(); @@ -781,11 +785,11 @@ private void loadPostStartups() .computeIfAbsent(sortOrder, k -> new TreeSet<>()) .add(postStartup); } - - for (Map.Entry>> entry : postStartupGroups.entrySet()) +*/ + for (Map.Entry> entry : groupedPostStartup.entrySet()) { Integer key = entry.getKey(); - Set> value = entry.getValue(); + Set value = entry.getValue(); if (value.size() == 1) { //run in order @@ -843,7 +847,7 @@ public GuiceConfig getConfig() */ public Set loadPostStartupServices() { - return getLoader(IGuicePostStartup.class, ServiceLoader.load(IGuicePostStartup.class)); + return new TreeSet<>(getLoader(IGuicePostStartup.class, ServiceLoader.load(IGuicePostStartup.class))); } /** @@ -886,7 +890,7 @@ public Set loadJarInclusionScanners() */ public Set loadPreStartupServices() { - return getLoader(IGuicePreStartup.class, true, ServiceLoader.load(IGuicePreStartup.class)); + return new TreeSet<>(getLoader(IGuicePreStartup.class, true, ServiceLoader.load(IGuicePreStartup.class))); } /** @@ -896,7 +900,7 @@ public Set loadPreStartupServices() */ public Set loadIGuiceModules() { - return getLoader(IGuiceModule.class, true, ServiceLoader.load(IGuiceModule.class)); + return new TreeSet<>(getLoader(IGuiceModule.class, true, ServiceLoader.load(IGuiceModule.class))); } /** @@ -915,9 +919,7 @@ public Set loadIGuiceConfigs() private void loadPreStartups() { Set preStartups = loadPreStartupServices(); - List startups = new ArrayList<>(preStartups); - startups.sort(Comparator.comparing(IGuicePreStartup::sortOrder)); - for (IGuicePreStartup startup : startups) + for (IGuicePreStartup startup : preStartups) { GuiceContext.log.config("Loading IGuicePreStartup - " + startup .getClass()