All Downloads are FREE. Search and download functionalities are using the official Maven repository.

panda.lang.collection.LRUMap Maven / Gradle / Ivy

Go to download

Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.

There is a newer version: 1.8.0
Show newest version
package panda.lang.collection;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * A simple LRU cache that implements the Map interface. Instances
 * are not thread-safe and should be synchronized externally, for instance by
 * using {@link java.util.Collections#synchronizedMap}.
 * 
 * @param  the key type
 * @param  the value type
 */
public class LRUMap extends LinkedHashMap implements Serializable {
	private static final long serialVersionUID = 1L;

	private final int maxEntries;

	public LRUMap(int maxEntries) {
		super( maxEntries, .75f, true );
		this.maxEntries = maxEntries;
	}

	@Override
	protected boolean removeEldestEntry(Map.Entry eldest) {
		return ( size() > maxEntries );
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy