@@ -34,6 +34,40 @@ protected Map<DependentResource, Detail<?>> results() {
34
34
return results ;
35
35
}
36
36
37
+ /**
38
+ * Retrieves the {@link DependentResource} associated with the specified name if it exists,
39
+ * {@link Optional#empty()} otherwise.
40
+ *
41
+ * @param name the name of the {@link DependentResource} to retrieve
42
+ * @return the {@link DependentResource} associated with the specified name if it exists,
43
+ * {@link Optional#empty()} otherwise
44
+ */
45
+ public Optional <DependentResource > getDependentResourceByName (String name ) {
46
+ if (name == null || name .isEmpty ()) {
47
+ return Optional .empty ();
48
+ }
49
+ return results .keySet ().stream ().filter (dr -> dr .name ().equals (name )).findFirst ();
50
+ }
51
+
52
+ /**
53
+ * Retrieves the optional result of the condition with the specified type for the specified
54
+ * dependent resource.
55
+ *
56
+ * @param <T> the expected result type of the condition
57
+ * @param dependentResourceName the dependent resource for which we want to retrieve a condition
58
+ * result
59
+ * @param conditionType the condition type which result we're interested in
60
+ * @param expectedResultType the expected result type of the condition
61
+ * @return the dependent condition result if it exists or {@link Optional#empty()} otherwise
62
+ * @throws IllegalArgumentException if a result exists but is not of the expected type
63
+ */
64
+ public <T > Optional <T > getDependentConditionResult (String dependentResourceName ,
65
+ Condition .Type conditionType , Class <T > expectedResultType ) {
66
+ return getDependentConditionResult (
67
+ getDependentResourceByName (dependentResourceName ).orElse (null ), conditionType ,
68
+ expectedResultType );
69
+ }
70
+
37
71
/**
38
72
* Retrieves the optional result of the condition with the specified type for the specified
39
73
* dependent resource.
@@ -48,6 +82,10 @@ protected Map<DependentResource, Detail<?>> results() {
48
82
*/
49
83
public <T > Optional <T > getDependentConditionResult (DependentResource dependentResource ,
50
84
Condition .Type conditionType , Class <T > expectedResultType ) {
85
+ if (dependentResource == null ) {
86
+ return Optional .empty ();
87
+ }
88
+
51
89
final var result = new Object [1 ];
52
90
try {
53
91
return Optional .ofNullable (results ().get (dependentResource ))
0 commit comments