Groovy web console

subscribe to the feed Subscribe
to this
site

maps

Published 2 weeks ago by me
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
// Simple map.
def devcfg = [foo: 'devbar', boo: 'devgoo']
def testcfg = [foo: 'testbar', boo: 'testgoo']
def m = ['dev': devcfg, 'test': testcfg]

def getWithDefault(Map<String, Map> m, String what, Map defaultValue) {
    return m.containsKey(what) ? m.get(what) : defaultValue
}


print getWithDefault(m, 'dev', devcfg)
print getWithDefault(m, 'test', devcfg)
print getWithDefault(m, 'default', devcfg)