You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by en...@apache.org on 2020/09/28 12:04:36 UTC

[sling-org-apache-sling-api] branch master updated: SLING-9774 Use a simpler fix that also passes the tests.

This is an automated email from the ASF dual-hosted git repository.

enorman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-api.git


The following commit(s) were added to refs/heads/master by this push:
     new 99af984  SLING-9774 Use a simpler fix that also passes the tests.
99af984 is described below

commit 99af984b5b9b3a5c6826cfdaa7076e4bd6b045e4
Author: Eric Norman <en...@apache.org>
AuthorDate: Mon Sep 28 05:04:18 2020 -0700

    SLING-9774 Use a simpler fix that also passes the tests.
    
    Thanks to review by Julian.
---
 .../sling/api/wrappers/impl/MergingValueMap.java   | 35 ++--------------------
 1 file changed, 2 insertions(+), 33 deletions(-)

diff --git a/src/main/java/org/apache/sling/api/wrappers/impl/MergingValueMap.java b/src/main/java/org/apache/sling/api/wrappers/impl/MergingValueMap.java
index 6cd2e5f..f21ab62 100644
--- a/src/main/java/org/apache/sling/api/wrappers/impl/MergingValueMap.java
+++ b/src/main/java/org/apache/sling/api/wrappers/impl/MergingValueMap.java
@@ -25,7 +25,6 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
-import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -109,42 +108,12 @@ public class MergingValueMap implements ValueMap {
     @Override
     public Object get(Object key) {
         return valueMaps.stream()
-                .map(vm -> getOrEmpty(vm, key)) // SLING-9774
-                .filter(Objects::nonNull)
+                .filter(vm -> vm.containsKey(key)) // SLING-9774
                 .findFirst()
-                .filter(Optional::isPresent)    // skip if Optional#empty
-                .map(Optional::get)             // dig the value out of the Optional
+                .map(vm -> vm.get(key))
                 .orElse(null);
     }
 
-    /**
-     * SLING-9774 - Returns an {@code Optional} describing the value in the map value for
-     * the supplied key.  Special handling is supplied for an existing key that
-     * resolves to a null value.
-     *
-     * @param vm the map to get the value from
-     * @param key the key to get the value for
-     * @return an {@code Optional} with a present value if the specified value
-     * is non-null, otherwise if the map contains the key then an empty {@code Optional},
-     * otherwise null
-     */
-    private Optional<Object> getOrEmpty(ValueMap vm, Object key) {
-        Optional<Object> opt = null;
-        Object value = vm.get(key);
-        if (value == null) {
-            // check if the null value is for a real entry
-            if (vm.containsKey(key)) {
-                // key exists so return the empty Optional
-                //   instead of null
-                opt = Optional.empty();
-            }
-        } else {
-            // not null so just wrap the value
-            opt = Optional.of(value);
-        }
-        return opt;
-    }
-
     @NotNull
     @Override
     public Set<String> keySet() {