You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ju...@apache.org on 2019/10/09 07:39:13 UTC
[fineract-cn-api] 12/38: De-uglified some twisted optional use.
This is an automated email from the ASF dual-hosted git repository.
juhan pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-api.git
commit 69fee9001e89b69e9e301cb5098bfc9613ed01a5
Author: myrle-krantz <mk...@mifos.org>
AuthorDate: Wed Jun 14 15:29:07 2017 +0200
De-uglified some twisted optional use.
---
.../java/io/mifos/core/api/util/AnnotatedErrorDecoder.java | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/src/main/java/io/mifos/core/api/util/AnnotatedErrorDecoder.java b/src/main/java/io/mifos/core/api/util/AnnotatedErrorDecoder.java
index 192ad8c..367b741 100644
--- a/src/main/java/io/mifos/core/api/util/AnnotatedErrorDecoder.java
+++ b/src/main/java/io/mifos/core/api/util/AnnotatedErrorDecoder.java
@@ -50,16 +50,16 @@ public class AnnotatedErrorDecoder implements ErrorDecoder {
public Exception decode(
final String methodKey,
final Response response) {
- final Optional<Optional<Optional<Exception>>> ret =
+ final Optional<Exception> ret =
Arrays.stream(feignClientClass.getMethods())
.filter(method -> Feign.configKey(feignClientClass, method).equals(methodKey))
.map(method -> {
final Optional<ThrowsException> annotation = getMatchingAnnotation(response, method);
- return annotation.map(a -> constructException(response, a));
+ return annotation.flatMap(a -> constructException(response, a));
})
- .findAny();
+ .findAny().flatMap(x -> x);
- return unwrapEmbeddedOptional(ret, getAlternative(methodKey, response));
+ return ret.orElse(getAlternative(methodKey, response));
}
private RuntimeException getAlternative(final String methodKey, final Response response) {
@@ -115,12 +115,6 @@ public class AnnotatedErrorDecoder implements ErrorDecoder {
return throwsExceptionAnnotation.status().value() == response.status();
}
- @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
- private <T> T unwrapEmbeddedOptional(
- final Optional<Optional<Optional<T>>> embeddedOptional, T alternative) {
- return embeddedOptional.orElse(Optional.empty()).orElse(Optional.empty()).orElse(alternative);
- }
-
private Optional<Exception> constructException(
final Response response,
final ThrowsException throwsExceptionAnnotations) {