<commit_before>/**
 * Copyright (c) 2014-2016 by <NAME>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Any modifications to this file must keep this entire header intact.
 */

package com.icafe4j.util;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.Collections;
import java.util.Collection;

/**
 * LRUCache.java.
 * 
 * A wrapper class implements Least-Recently-Used cache backed by a LinkedHashMap.
 * 
 * @author <NAME>, <EMAIL>
 * @version 1.0 09/19/2012
 * @see com.icafe4j.util.SoftHashMap
 */
public class LRUCache<K,V> implements Map<K,V>, java.io.Serializable {

	private static final long serialVersionUID = 4874219673008997966L;
	
	private Map<K,V> map = null;
	
	public LRUCache()
	{
	   this(10, false);	
	}
	
	public LRUCache(boolean isThreadsafe)
	{
		this(10, isThreadsafe);
	}
	
	public LRUCache(final int limit, boolean isThreadsafe)
	{
		map = new LinkedHashMap<K,V>() {
			    private static final long serialVersionUID = 3195834455030574184L;

				public boolean removeEldestEntry (Map.Entry<K,V> eldest){
					return size() > limit;
				}
			};
		
		if(isThreadsafe)
		{
			map = Collections.synchronizedMap(map);
		}	
	}	
	// Delegates all other method calls to the underlying Map object
	public V put(K key,V value)	{ return map.put(key, value); }
	
	public V get(Object key) { return map.get(key); }
	
	public V remove(Object key)	{ return map.remove(key); }
	
	public void clear()	{ map.clear(); }
	
	public boolean containsKey(Object key) { return map.containsKey(key); }
	
	public boolean containsValue(Object value) { return map.containsValue(value); }
	
	public int size() {	return map.size(); }
	
	public Set<Map.Entry<K,V>> entrySet() { return map.entrySet(); }
	<commit_msg>Use the access-order constructor to create the LinkedHashMap<commit_after>/**
 * Copyright (c) 2014-2016 by <NAME>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Any modifications to this file must keep this entire header intact.
 */

package com.icafe4j.util;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.Collections;
import java.util.Collection;

/**
 * LRUCache.java.
 * 
 * A wrapper class implements Least-Recently-Used cache backed by a LinkedHashMap.
 * 
 * @author <NAME>, <EMAIL>
 * @version 1.0 09/19/2012
 * @see com.icafe4j.util.SoftHashMap
 */
public class LRUCache<K,V> implements Map<K,V>, java.io.Serializable {

	private static final long serialVersionUID = 4874219673008997966L;
	
	private Map<K,V> map = null;
	
	public LRUCache() {
	   this(10, false);	
	}
	
	public LRUCache(boolean isThreadsafe) {
		this(10, isThreadsafe);
	}
	
	public LRUCache(final int limit, boolean isThreadsafe) {
		map = new LinkedHashMap<K,V>(16, 0.75f, true) {
			    private static final long serialVersionUID = 3195834455030574184L;

				public boolean removeEldestEntry (Map.Entry<K,V> eldest){
					return size() > limit;
				}
			};
		
		if(isThreadsafe) {
			map = Collections.synchronizedMap(map);
		}	
	}	
	// Delegates all other method calls to the underlying Map object
	public V put(K key,V value)	{ return map.put(key, value); }
	
	public V get(Object key) { return map.get(key); }
	
	public V remove(Object key)	{ return map.remove(key); }
	
	public void clear()	{ map.clear(); }
	
	public boolean containsKey(Object key) { return map.containsKey(key); }
	
	public boolean containsValue(Object value) { return map.containsValue(value); }
	
	public int size() {	return map.size(); }
	
	public Set<Map.Entry<K,V>> entrySet() { return map.entrySet(); }
	
{'fraction_non_alphanumeric': 0.11510429756220156, 'fraction_numerical': 0.03443076149786378, 'mean_word_length': 3.871481028151775, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3379300', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1263, 'n_words': 379}