Skip to content

Commit 20e3c1a

Browse files
committed
refactor: clean-up ResultCondition
Signed-off-by: Chris Laprun <claprun@redhat.com>
1 parent ac99dc4 commit 20e3c1a

File tree

2 files changed

+34
-33
lines changed

2 files changed

+34
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.javaoperatorsdk.operator.processing.dependent.workflow;
2+
3+
public class DefaultResult<T> implements ResultCondition.Result<T> {
4+
private final T result;
5+
private final boolean success;
6+
7+
public DefaultResult(boolean success, T result) {
8+
this.result = result;
9+
this.success = success;
10+
}
11+
12+
@Override
13+
public T getResult() {
14+
return result;
15+
}
16+
17+
@Override
18+
public boolean isSuccess() {
19+
return success;
20+
}
21+
22+
@Override
23+
public String toString() {
24+
return asString();
25+
}
26+
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ResultCondition.java

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,20 @@ default boolean isMet(DependentResource<R, P> dependentResource, P primary, Cont
1212
return detailedIsMet(dependentResource, primary, context).isSuccess();
1313
}
1414

15+
@SuppressWarnings({"rawtypes", "unchecked"})
1516
interface Result<T> {
16-
Result metWithoutResult = new Result() {
17-
@Override
18-
public Object getResult() {
19-
return null;
20-
}
21-
22-
@Override
23-
public boolean isSuccess() {
24-
return true;
25-
}
26-
27-
@Override
28-
public String toString() {
29-
return asString();
30-
}
31-
};
32-
33-
Result unmetWithoutResult = new Result() {
34-
@Override
35-
public Object getResult() {
36-
return null;
37-
}
38-
39-
@Override
40-
public boolean isSuccess() {
41-
return false;
42-
}
43-
44-
@Override
45-
public String toString() {
46-
return asString();
47-
}
48-
};
17+
ResultCondition.Result metWithoutResult = new DefaultResult(true, null);
18+
19+
ResultCondition.Result unmetWithoutResult = new DefaultResult(false, null);
4920

5021
static Result withoutResult(boolean success) {
5122
return success ? metWithoutResult : unmetWithoutResult;
5223
}
5324

25+
static <T> Result<T> withResult(boolean success, T result) {
26+
return new DefaultResult<>(success, result);
27+
}
28+
5429
default String asString() {
5530
return "Result: " + getResult() + " met: " + isSuccess();
5631
}

0 commit comments

Comments
 (0)