/**
 * 
 */
package com.github.ansell.jdefaultdict;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * An implementation of the Python defaultdict pattern using Java.
 * 
 * All calls to get are transparently mapped to computeIfAbsent, using the
 * lambda function provided in the constructor to create objects if they do not
 * exist.
 * 
 * @author Peter Ansell p_ansell@yahoo.com
 * 
 * @param <K>
 *            The key type
 * @param <V>
 *            The value type
 */
public class JDefaultDict<K, V> extends ConcurrentMapDelegate<K, V> {

	private final Function<? super K, ? extends V> lambdaFunction;

	public JDefaultDict(Function<? super K, ? extends V> lambdaFunction) {
		this(lambdaFunction, () -> new ConcurrentHashMap<K, V>());
	}

	public JDefaultDict(Function<? super K, ? extends V> lambdaFunction,
			ConcurrentMap<K, V> delegate) {
		super(delegate);
		this.lambdaFunction = lambdaFunction;
	}

	public JDefaultDict(Function<? super K, ? extends V> lambdaFunction,
			Supplier<ConcurrentMap<K, V>> initialMapFunction) {
		super(initialMapFunction);
		this.lambdaFunction = lambdaFunction;
	}

	/**
	 * Returns the value that exists for the given key if it exists, or creates
	 * a new entry using the lambda function that was given to the constructor.
	 * 
	 * @param key
	 *            The key object to search for, returning the value if it
	 *            exists, or inserts a new value using the lambda function that
	 *            was given to the constructor.
	 */
	@SuppressWarnings("unchecked")
	@Override
	public V get(Object key) {
		return computeIfAbsent((K) key, lambdaFunction);
	}
}

@@ -300,19 +300,36 @@
 alls to 
-get
+%7B@link #get(Object)%7D
  are tra
@@ -348,17 +348,28 @@
 apped to
- 
+%0A * %7B@link #
 computeI
@@ -375,16 +375,35 @@
 IfAbsent
+(Object, Function)%7D
 , using 
@@ -405,19 +405,16 @@
 sing the
-%0A *
  lambda 
@@ -421,16 +421,19 @@
 function
+%0A *
  provide
@@ -436,24 +436,45 @@
 vided in the
+ %7B@link JDefaultDict%7D
  constructor
@@ -473,16 +473,17 @@
 structor
+s
  to crea
@@ -489,33 +489,45 @@
 ate 
-object
+default value
 s if
+%0A *
  the
+ ke
 y do
+es
  not
-%0A *
  exi

clarify JDefaultDict javadoc