fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From my...@apache.org
Subject [fineract-cn-api] 12/13: De-uglified some twisted optional use.
Date Mon, 22 Jan 2018 15:08:40 GMT
This is an automated email from the ASF dual-hosted git repository.

myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-api.git

commit 69fee9001e89b69e9e301cb5098bfc9613ed01a5
Author: myrle-krantz <mkrantz@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) {

-- 
To stop receiving notification emails like this one, please contact
myrle@apache.org.

Mime
View raw message