ajwang / groovypptest

Automatically exported from code.google.com/p/groovypptest
0 stars 0 forks source link

Add FHashMap.get(key, defaultValue) #349

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
like in DefaultGroovyMethods

Original issue reported on code.google.com by gromop...@gmail.com on 11 Mar 2011 at 10:35

GoogleCodeExporter commented 8 years ago
A possibility to lazily evaluate the defaultValue parameter (or pass a closure) 
would be a plus

Original comment by gromop...@gmail.com on 11 Mar 2011 at 10:44

GoogleCodeExporter commented 8 years ago

Original comment by alex.tka...@gmail.com on 11 Mar 2011 at 10:50

GoogleCodeExporter commented 8 years ago

Original comment by alex.tka...@gmail.com on 11 Mar 2011 at 10:55

GoogleCodeExporter commented 8 years ago
I guess the next thing you will ask will be putIfAbsent with lazy evaluation

Original comment by alex.tka...@gmail.com on 11 Mar 2011 at 10:56

GoogleCodeExporter commented 8 years ago
It will be like this

  final V get(K key, V defaultValue) { getAt(0, key, key.hashCode()) ?: defaultValue }

  final V getOr(K key, Callable<V> defaultValue) { getAt(0, key, key.hashCode()) ?: defaultValue() }

Original comment by alex.tka...@gmail.com on 11 Mar 2011 at 11:22

GoogleCodeExporter commented 8 years ago

Original comment by alex.tka...@gmail.com on 11 Mar 2011 at 11:24