<commit_before>/**
 * 
 */
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 <NAME> <EMAIL>
 * 
 * @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,
			Supplier<ConcurrentMap<K, V>> initialMapFunction) {
		super(initialMapFunction);
		this.lambdaFunction = lambdaFunction;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Map#get(java.lang.Object)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public V get(Object key) {
		return computeIfAbsent((K) key, lambdaFunction);
	}
}
<commit_msg>Allow default dict to wrap existing maps<commit_after>/**
 * 
 */
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 <NAME> <EMAIL>
 * 
 * @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;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Map#get(java.lang.Object)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public V get(Object key) {
		return computeIfAbsent((K) key, lambdaFunction);
	}
}

{'fraction_non_alphanumeric': 0.11651542649727768, 'fraction_numerical': 0.0, 'mean_word_length': 4.11317254174397, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1217283', 'n_tokens_mistral': 875, 'n_tokens_neox': 837, 'n_words': 239}