io.polaris.core.map.LimitedLinkedHashMap Maven / Gradle / Ivy
package io.polaris.core.map;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author Qt
* @since 1.8
*/
public class LimitedLinkedHashMap extends LinkedHashMap {
private int maxCapacity = 0;
public LimitedLinkedHashMap(int maxCapacity) {
this.maxCapacity = maxCapacity;
}
public LimitedLinkedHashMap(int maxCapacity, boolean accessOrder) {
super(16, .75f, accessOrder);
this.maxCapacity = maxCapacity;
}
public LimitedLinkedHashMap(int maxCapacity, boolean accessOrder, int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor, accessOrder);
this.maxCapacity = maxCapacity;
}
@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > maxCapacity;
}
}