Skip to content

Commit 1df4e18

Browse files
committed
Cleanup rest service dependencies for Vert.x
1 parent 4b3d284 commit 1df4e18

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/main/java/com/guicedee/guicedinjection/GuiceContext.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.util.regex.Pattern;
3030

3131
import static com.guicedee.guicedinjection.properties.GlobalProperties.getSystemPropertyOrEnvironment;
32+
import static java.util.stream.Collectors.groupingBy;
33+
import static java.util.stream.Collectors.toSet;
3234

3335
/**
3436
* Provides an interface for reflection and injection in one.
@@ -772,20 +774,22 @@ public static void setScanner(ClassGraph scanner)
772774
private void loadPostStartups()
773775
{
774776
Set<IGuicePostStartup> startupSet = loadPostStartupServices();
777+
Map<Integer, Set<IGuicePostStartup>> groupedPostStartup = startupSet.stream()
778+
.collect(groupingBy(IGuicePostStartup::sortOrder, toSet()));
779+
/* Map<Integer, Set<IGuicePostStartup<?>>> postStartupGroups = new TreeMap<>();
775780
776-
Map<Integer, Set<IGuicePostStartup<?>>> postStartupGroups = new TreeMap<>();
777781
for (IGuicePostStartup<?> postStartup : startupSet)
778782
{
779783
Integer sortOrder = postStartup.sortOrder();
780784
postStartupGroups
781785
.computeIfAbsent(sortOrder, k -> new TreeSet<>())
782786
.add(postStartup);
783787
}
784-
785-
for (Map.Entry<Integer, Set<IGuicePostStartup<?>>> entry : postStartupGroups.entrySet())
788+
*/
789+
for (Map.Entry<Integer, Set<IGuicePostStartup>> entry : groupedPostStartup.entrySet())
786790
{
787791
Integer key = entry.getKey();
788-
Set<IGuicePostStartup<?>> value = entry.getValue();
792+
Set<IGuicePostStartup> value = entry.getValue();
789793
if (value.size() == 1)
790794
{
791795
//run in order
@@ -843,7 +847,7 @@ public GuiceConfig<?> getConfig()
843847
*/
844848
public Set<IGuicePostStartup> loadPostStartupServices()
845849
{
846-
return getLoader(IGuicePostStartup.class, ServiceLoader.load(IGuicePostStartup.class));
850+
return new TreeSet<>(getLoader(IGuicePostStartup.class, ServiceLoader.load(IGuicePostStartup.class)));
847851
}
848852

849853
/**
@@ -886,7 +890,7 @@ public Set<IGuiceScanJarInclusions> loadJarInclusionScanners()
886890
*/
887891
public Set<IGuicePreStartup> loadPreStartupServices()
888892
{
889-
return getLoader(IGuicePreStartup.class, true, ServiceLoader.load(IGuicePreStartup.class));
893+
return new TreeSet<>(getLoader(IGuicePreStartup.class, true, ServiceLoader.load(IGuicePreStartup.class)));
890894
}
891895

892896
/**
@@ -896,7 +900,7 @@ public Set<IGuicePreStartup> loadPreStartupServices()
896900
*/
897901
public Set<IGuiceModule> loadIGuiceModules()
898902
{
899-
return getLoader(IGuiceModule.class, true, ServiceLoader.load(IGuiceModule.class));
903+
return new TreeSet<>(getLoader(IGuiceModule.class, true, ServiceLoader.load(IGuiceModule.class)));
900904
}
901905

902906
/**
@@ -915,9 +919,7 @@ public Set<IGuiceConfigurator> loadIGuiceConfigs()
915919
private void loadPreStartups()
916920
{
917921
Set<IGuicePreStartup> preStartups = loadPreStartupServices();
918-
List<IGuicePreStartup> startups = new ArrayList<>(preStartups);
919-
startups.sort(Comparator.comparing(IGuicePreStartup::sortOrder));
920-
for (IGuicePreStartup startup : startups)
922+
for (IGuicePreStartup startup : preStartups)
921923
{
922924
GuiceContext.log.config("Loading IGuicePreStartup - " + startup
923925
.getClass()

0 commit comments

Comments
 (0)