Skip to content

Commit

Permalink
subscript access
Browse files Browse the repository at this point in the history
  • Loading branch information
sdelamo committed Dec 17, 2018
1 parent 52014be commit a892fc7
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import groovy.transform.EqualsAndHashCode
import org.codehaus.groovy.runtime.DefaultGroovyMethods

import java.util.Map.Entry
import java.util.regex.Matcher
import java.util.regex.Pattern

@EqualsAndHashCode
Expand Down Expand Up @@ -75,9 +76,23 @@ class NavigableMap implements Map<String, Object>, Cloneable {
delegateMap.containsValue value
}

@CompileDynamic
@Override
Object get(Object key) {
delegateMap.get(key)
Object result = delegateMap.get(key)
if (result) {
return result
}
if (key ==~ SUBSCRIPT_REGEX) {
Matcher matcher = key =~ SUBSCRIPT_REGEX
String name = matcher[0][2]
int subscriptIndex = matcher[0][3] as int
result = delegateMap.get(name)
if (result instanceof List && ((List)result).size() > subscriptIndex) {
return ((List) result).get(subscriptIndex)
}
}
null
}

@Override
Expand Down

0 comments on commit a892fc7

Please sign in to comment.