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 53cc36a8c27f4d7047df62305eb92c37094b5945
Author: Eric Milles <[email protected]>
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..5fd95e8 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 = [:]
+     * map[1] = 'a'
+     * assert map.get(1) == 'a'
+     * </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) {

Reply via email to