info.unterrainer.commons.jreutils.collections.SizeLimitedHashMap Maven / Gradle / Ivy
package info.unterrainer.commons.jreutils.collections;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* A size-limited hash-map.
*/
public class SizeLimitedHashMap extends LinkedHashMap {
private static final long serialVersionUID = 6994714918898609875L;
private final int maxSize;
public SizeLimitedHashMap(final int maxSize) {
this.maxSize = maxSize;
}
@Override
protected boolean removeEldestEntry(final Map.Entry eldest) {
return size() > maxSize;
}
}