12
12
* Interface for exposing a set of {@link BoltPlugin}s and {@link BoltIssue}s
13
13
* in a read-only way.
14
14
*/
15
- public interface PluginCollection <T extends BoltPlugin > extends Iterable <PluginDescriptor <? extends T >> {
15
+ public interface PluginCollection <T extends BoltPlugin > extends Iterable <PluginDescriptor <T >> {
16
16
17
- List <PluginDescriptor <? extends T >> getPlugins ();
17
+ List <PluginDescriptor <T >> getPlugins ();
18
18
19
- default Iterator <PluginDescriptor <? extends T >> iterator () {
19
+ default Iterator <PluginDescriptor <T >> iterator () {
20
20
return getPlugins ().iterator ();
21
21
}
22
22
23
- List <BoltIssue <? extends T >> getIssues ();
23
+ List <BoltIssue <T >> getIssues ();
24
24
25
25
default List <T > newInstances () {
26
- List <T > insts = getPlugins ().stream ().map (p -> p .create ()).collect (Collectors .toList ());
26
+ List <T > insts = getPlugins ()
27
+ .stream ()
28
+ .map (p -> p .create ())
29
+ .filter (Optional ::isPresent )
30
+ .map (Optional ::get )
31
+ .collect (Collectors .toList ());
27
32
Collections .sort (insts , (f1 , f2 ) -> f1 .pluginName ().compareTo (f1 .pluginName ()));
28
33
return insts ;
29
34
}
30
35
31
36
PluginRegistry <T > getManager ();
32
37
33
- default PluginDescriptor <? extends T > getByUUID (String uuid ) {
34
- for (PluginDescriptor <? extends T > plugin : getPlugins ()) {
38
+ default Optional < PluginDescriptor <T > > getByUUID (String uuid ) {
39
+ for (PluginDescriptor <T > plugin : getPlugins ()) {
35
40
if (plugin .getUUID ().equals (uuid )) {
36
- return plugin ;
41
+ return Optional . of ( plugin ) ;
37
42
}
38
43
}
39
- return null ;
44
+ return Optional . empty () ;
40
45
}
41
46
42
- default Optional <PluginDescriptor <? extends T >> getByClass (Class <? extends T > cls ) {
47
+ default Optional <PluginDescriptor <T >> getByClass (Class <? extends T > cls ) {
43
48
synchronized (this ) {
44
49
for (var plugin : getPlugins ()) {
45
50
if (plugin .getReferenceInstance ().getClass ().equals (cls )) {
@@ -51,7 +56,7 @@ default Optional<PluginDescriptor<? extends T>> getByClass(Class<? extends T> cl
51
56
}
52
57
53
58
default boolean hasUUID (String uuid ) {
54
- return getByUUID (uuid ) != null ;
59
+ return getByUUID (uuid ). isPresent () ;
55
60
}
56
61
57
62
default int size () {
@@ -72,17 +77,31 @@ default boolean isEmpty() {
72
77
* @param other the other collection to compare against
73
78
* @return true if this collection is a proper upgrade for the other, false otherwise
74
79
*/
75
- default boolean isUpgradeFor (PluginCollection <? extends T > other ) {
80
+ default boolean isUpgradeFor (PluginCollection <T > other ) {
76
81
//get all the UUIDs from the other plugin set
77
82
List <String > otherUUIDs = other .getPlugins ().stream ().map (p -> p .getUUID ()).collect (Collectors .toList ());
78
83
84
+ // For every uuid in THEIR collection, we wee if OUR collection
85
+ // also has that uuid. If we do, we must check if OUR matching
86
+ // plugin is an upgrade for THEIR plugin
79
87
//if this set is missing any of the UUIDs, it's not an upgrade
80
- for (String otherUUID : otherUUIDs ) {
81
- if (!this .hasUUID (otherUUID )) {
88
+ for (String uuid : otherUUIDs ) {
89
+
90
+ // Try to get OUR plugin for this uuid
91
+ var ourLookup = this .getByUUID (uuid );
92
+ if (ourLookup .isEmpty ()) {
82
93
return false ;
83
94
}
84
- boolean isUpgrade = this .getByUUID (otherUUID ).isUpgradeFor (other .getByUUID (otherUUID ));
85
- if (!isUpgrade ) {
95
+ var ourPlugin = ourLookup .get ();
96
+
97
+ // Try to get THEIR plugin for this uuid
98
+ var theirLookup = other .getByUUID (uuid );
99
+ if (theirLookup .isEmpty ()) {
100
+ return false ;
101
+ }
102
+ var theirPlugin = theirLookup .get ();
103
+
104
+ if ( ! ourPlugin .isUpgradeFor (theirPlugin ) ) {
86
105
return false ;
87
106
}
88
107
}
0 commit comments