You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2018/01/15 13:09:06 UTC

[sling-org-apache-sling-scripting-sightly-compiler] branch issue/SLING-7380 created (now 3e84210)

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

radu pushed a change to branch issue/SLING-7380
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler.git.


      at 3e84210  SLING-7380 - Querying maps with Integer keys returns null

This branch includes the following new commits:

     new 3e84210  SLING-7380 - Querying maps with Integer keys returns null

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


-- 
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].

[sling-org-apache-sling-scripting-sightly-compiler] 01/01: SLING-7380 - Querying maps with Integer keys returns null

Posted by ra...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

radu pushed a commit to branch issue/SLING-7380
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler.git

commit 3e842104510ec04c99260888762f63443e410e15
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Jan 15 14:00:30 2018 +0100

    SLING-7380 - Querying maps with Integer keys returns null
    
    * allow maps with any type of key to be queried directly
---
 .../sightly/compiler/util/ObjectModel.java         |  2 +-
 .../scripting/sightly/util/ObjectModelTest.java    | 24 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/scripting/sightly/compiler/util/ObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/compiler/util/ObjectModel.java
index 1e1096f..ea6eb2a 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/compiler/util/ObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/compiler/util/ObjectModel.java
@@ -113,7 +113,7 @@ public final class ObjectModel {
             String propertyName = toString(property);
             if (StringUtils.isNotEmpty(propertyName)) {
                 if (target instanceof Map) {
-                    resolved = ((Map) target).get(propertyName);
+                    resolved = ((Map) target).get(property);
                 }
                 if (resolved == null) {
                     resolved = getField(target, propertyName);
diff --git a/src/test/java/org/apache/sling/scripting/sightly/util/ObjectModelTest.java b/src/test/java/org/apache/sling/scripting/sightly/util/ObjectModelTest.java
index 711dc07..d3e0924 100644
--- a/src/test/java/org/apache/sling/scripting/sightly/util/ObjectModelTest.java
+++ b/src/test/java/org/apache/sling/scripting/sightly/util/ObjectModelTest.java
@@ -153,6 +153,12 @@ public class ObjectModelTest {
         assertEquals(1, ObjectModel.resolveProperty(map, "one"));
         assertNull(ObjectModel.resolveProperty(map, null));
         assertNull(ObjectModel.resolveProperty(map, ""));
+        Map<Integer, String> stringMap = new HashMap<Integer, String>(){{
+            put(1, "one");
+            put(2, "two");
+        }};
+        assertEquals("one", ObjectModel.resolveProperty(stringMap, 1));
+        assertEquals("two", ObjectModel.resolveProperty(stringMap, 2));
         Person johnDoe = AdultFactory.createAdult("John", "Doe");
         assertEquals("Expected to be able to access public static final constants.", 1l, ObjectModel.resolveProperty(johnDoe, "CONSTANT"));
         assertNull("Did not expect to be able to access public fields from package protected classes.", ObjectModel.resolveProperty(johnDoe,
@@ -165,6 +171,24 @@ public class ObjectModelTest {
         assertNull("Expected null result for inexistent method.", ObjectModel.resolveProperty(johnDoe, "nomethod"));
     }
 
+    @Test
+    public void testGetIndex() {
+        Integer[] testArray = new Integer[] {1, 2, 3};
+        assertEquals(2, ObjectModel.getIndex(testArray, 1));
+        assertNull(ObjectModel.getIndex(testArray, 3));
+        assertNull(ObjectModel.getIndex(testArray, -1));
+        List<Integer> testList = Arrays.asList(testArray);
+        assertEquals(2, ObjectModel.getIndex(testList, 1));
+        assertNull(ObjectModel.getIndex(testList, 3));
+        assertNull(ObjectModel.getIndex(testList, -1));
+        Map<Integer, String> stringMap = new HashMap<Integer, String>(){{
+            put(1, "one");
+            put(2, "two");
+        }};
+        assertNull(ObjectModel.getIndex(stringMap, 1));
+        assertNull(ObjectModel.getIndex(stringMap, 2));
+    }
+
 
     private class Bag<T> implements Iterable<T> {
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.