Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Tim's long adder test with streams but groovier :-)
import java.util.Random
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.LongAdder
def frequencyMap = new ConcurrentHashMap<>()
def rnd = new Random()
IntStream.range( 0, 10000 )
.forEach { n ->
def key = Double.valueOf( rnd.nextGaussian() + 5 ).intValue()
frequencyMap.computeIfAbsent( key, { k -> new LongAdder() } ).increment()
println frequencyMap
Copy link

glaforge commented Apr 30, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment