You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2020/07/20 03:34:15 UTC

[groovy] branch GROOVY-9420 created (now 5b46327)

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

emilles pushed a change to branch GROOVY-9420
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at 5b46327  GROOVY-9420: trump getAt(Object,String) with getAt(Map<String,?>,String)

This branch includes the following new commits:

     new 5b46327  GROOVY-9420: trump getAt(Object,String) with getAt(Map<String,?>,String)

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.



[groovy] 01/01: GROOVY-9420: trump getAt(Object, String) with getAt(Map, String)

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

emilles pushed a commit to branch GROOVY-9420
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 5b46327c94d4afe01ba79006d9365586a149fbe6
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Jul 19 22:33:59 2020 -0500

    GROOVY-9420: trump getAt(Object,String) with getAt(Map<String,?>,String)
---
 .../groovy/runtime/DefaultGroovyMethods.java       | 37 ++++++++++++++++++++--
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index ff84038..c472c8c 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -7966,12 +7966,17 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
 
     /**
      * Support the subscript operator for a Map.
-     * <pre class="groovyTestCase">def map = [a:10]
-     * assert map["a"] == 10</pre>
+     *
+     * <pre class="groovyTestCase">
+     * def map = [1:10]
+     * assert map[1] == 10
+     * assert map.getAt(1) == 10
+     * </pre>
      *
      * @param self a Map
      * @param key  an Object as a key for the map
      * @return the value corresponding to the given key
+     *
      * @since 1.0
      */
     public static <K,V> V getAt(Map<K,V> self, Object key) {
@@ -7979,6 +7984,25 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
     }
 
     /**
+     * Support the subscript operator for a Map.
+     *
+     * <pre class="groovyTestCase">
+     * def map = [a:10]
+     * assert map['a'] == 10
+     * assert map.getAt('a') == 10
+     * </pre>
+     *
+     * @param self a Map
+     * @param key  a String as a key for the map
+     * @return the value corresponding to the given key
+     *
+     * @since 3.0.6
+     */
+    public static <V> V getAt(Map<String, V> self, String key) {
+        return self.get(key);
+    }
+
+    /**
      * Returns a new <code>Map</code> containing all entries from <code>left</code> and <code>right</code>,
      * giving precedence to <code>right</code>.  Any keys appearing in both Maps
      * will appear in the resultant map with values from the <code>right</code>
@@ -8005,12 +8029,19 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
     }
 
     /**
-     * A helper method to allow maps to work with subscript operators
+     * Support the subscript operator for Map.
+     *
+     * <pre class="groovyTestCase">
+     * def map = [:]
+     * assert map['a'] = 1
+     * assert map.get('a') == 1
+     * </pre>
      *
      * @param self  a Map
      * @param key   an Object as a key for the map
      * @param value the value to put into the map
      * @return the value corresponding to the given key
+     *
      * @since 1.0
      */
     public static <K,V> V putAt(Map<K,V> self, K key, V value) {