|
23 | 23 | import java.util.List; |
24 | 24 | import java.util.Objects; |
25 | 25 |
|
| 26 | +import static dev.failsafe.FailurePredicates.resultPredicateFor; |
| 27 | +import static dev.failsafe.FailurePredicates.*; |
| 28 | + |
26 | 29 | /** |
27 | 30 | * A Policy that allows configurable conditions to determine whether an execution is a failure. |
28 | 31 | * <ul> |
@@ -135,53 +138,4 @@ public S handleResultIf(CheckedPredicate<R> resultPredicate) { |
135 | 138 | config.failureConditions.add(resultPredicateFor(resultPredicate)); |
136 | 139 | return (S) this; |
137 | 140 | } |
138 | | - |
139 | | - /** |
140 | | - * Returns a predicate that evaluates whether the {@code result} equals an execution result. |
141 | | - */ |
142 | | - static <R> CheckedBiPredicate<R, Throwable> resultPredicateFor(R result) { |
143 | | - return (t, u) -> result == null ? t == null && u == null : Objects.equals(result, t); |
144 | | - } |
145 | | - |
146 | | - /** |
147 | | - * Returns a predicate that evaluates the {@code failurePredicate} against a failure. |
148 | | - */ |
149 | | - @SuppressWarnings("unchecked") |
150 | | - static <R> CheckedBiPredicate<R, Throwable> failurePredicateFor( |
151 | | - CheckedPredicate<? extends Throwable> failurePredicate) { |
152 | | - return (t, u) -> u != null && ((CheckedPredicate<Throwable>) failurePredicate).test(u); |
153 | | - } |
154 | | - |
155 | | - /** |
156 | | - * Returns a predicate that evaluates the {@code resultPredicate} against a result, when present. |
157 | | - * <p> |
158 | | - * Short-circuits to false without invoking {@code resultPredicate}, when result is not present (i.e. |
159 | | - * BiPredicate.test(null, Throwable)). |
160 | | - */ |
161 | | - static <R> CheckedBiPredicate<R, Throwable> resultPredicateFor(CheckedPredicate<R> resultPredicate) { |
162 | | - return (t, u) -> { |
163 | | - if (u == null) { |
164 | | - return resultPredicate.test(t); |
165 | | - } else { |
166 | | - // resultPredicate is only defined over the success type. |
167 | | - // It doesn't know how to handle a failure of type Throwable, |
168 | | - // so we return false here. |
169 | | - return false; |
170 | | - } |
171 | | - }; |
172 | | - } |
173 | | - |
174 | | - /** |
175 | | - * Returns a predicate that returns whether any of the {@code failures} are assignable from an execution failure. |
176 | | - */ |
177 | | - static <R> CheckedBiPredicate<R, Throwable> failurePredicateFor(List<Class<? extends Throwable>> failures) { |
178 | | - return (t, u) -> { |
179 | | - if (u == null) |
180 | | - return false; |
181 | | - for (Class<? extends Throwable> failureType : failures) |
182 | | - if (failureType.isAssignableFrom(u.getClass())) |
183 | | - return true; |
184 | | - return false; |
185 | | - }; |
186 | | - } |
187 | 141 | } |
0 commit comments