29
29
import java .util .regex .Pattern ;
30
30
31
31
import static com .guicedee .guicedinjection .properties .GlobalProperties .getSystemPropertyOrEnvironment ;
32
+ import static java .util .stream .Collectors .groupingBy ;
33
+ import static java .util .stream .Collectors .toSet ;
32
34
33
35
/**
34
36
* Provides an interface for reflection and injection in one.
@@ -772,20 +774,22 @@ public static void setScanner(ClassGraph scanner)
772
774
private void loadPostStartups ()
773
775
{
774
776
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<>();
775
780
776
- Map <Integer , Set <IGuicePostStartup <?>>> postStartupGroups = new TreeMap <>();
777
781
for (IGuicePostStartup<?> postStartup : startupSet)
778
782
{
779
783
Integer sortOrder = postStartup.sortOrder();
780
784
postStartupGroups
781
785
.computeIfAbsent(sortOrder, k -> new TreeSet<>())
782
786
.add(postStartup);
783
787
}
784
-
785
- for (Map .Entry <Integer , Set <IGuicePostStartup <?>>> entry : postStartupGroups .entrySet ())
788
+ */
789
+ for (Map .Entry <Integer , Set <IGuicePostStartup >> entry : groupedPostStartup .entrySet ())
786
790
{
787
791
Integer key = entry .getKey ();
788
- Set <IGuicePostStartup <?> > value = entry .getValue ();
792
+ Set <IGuicePostStartup > value = entry .getValue ();
789
793
if (value .size () == 1 )
790
794
{
791
795
//run in order
@@ -843,7 +847,7 @@ public GuiceConfig<?> getConfig()
843
847
*/
844
848
public Set <IGuicePostStartup > loadPostStartupServices ()
845
849
{
846
- return getLoader (IGuicePostStartup .class , ServiceLoader .load (IGuicePostStartup .class ));
850
+ return new TreeSet <>( getLoader (IGuicePostStartup .class , ServiceLoader .load (IGuicePostStartup .class ) ));
847
851
}
848
852
849
853
/**
@@ -886,7 +890,7 @@ public Set<IGuiceScanJarInclusions> loadJarInclusionScanners()
886
890
*/
887
891
public Set <IGuicePreStartup > loadPreStartupServices ()
888
892
{
889
- return getLoader (IGuicePreStartup .class , true , ServiceLoader .load (IGuicePreStartup .class ));
893
+ return new TreeSet <>( getLoader (IGuicePreStartup .class , true , ServiceLoader .load (IGuicePreStartup .class ) ));
890
894
}
891
895
892
896
/**
@@ -896,7 +900,7 @@ public Set<IGuicePreStartup> loadPreStartupServices()
896
900
*/
897
901
public Set <IGuiceModule > loadIGuiceModules ()
898
902
{
899
- return getLoader (IGuiceModule .class , true , ServiceLoader .load (IGuiceModule .class ));
903
+ return new TreeSet <>( getLoader (IGuiceModule .class , true , ServiceLoader .load (IGuiceModule .class ) ));
900
904
}
901
905
902
906
/**
@@ -915,9 +919,7 @@ public Set<IGuiceConfigurator> loadIGuiceConfigs()
915
919
private void loadPreStartups ()
916
920
{
917
921
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 )
921
923
{
922
924
GuiceContext .log .config ("Loading IGuicePreStartup - " + startup
923
925
.getClass ()
0 commit comments