Monday, April 20, 2009

Fluent assertions, bonus questions

Alex Ruiz tipped me off to an update to FEST, a fluent assertion library. Thanks, Alex!

Bonus questions. Everyone know this idiom:

<K, V> V get(final K key) {
    final V value = concurrentMap.get(key);
    if (null != value) return value;
    concurrentMap.putIfAbsent(key, factoryMethodForV());
    return concurrentMap.get(key);

Easier question: How do you support valid null values for the concurrent map? (Hint: monads)

Harder question: Suppose factoryMethodForV() is expensive. How do you guarantee it is only ever called once for a given key?

UPDATE: Fixed some typos.

Post a Comment