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

io.polaris.core.map.LimitedLinkedHashMap Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
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, false);
	}

	public LimitedLinkedHashMap(int maxCapacity, boolean accessOrder) {
		this(maxCapacity, accessOrder, 128, .75f);
	}

	public LimitedLinkedHashMap(int maxCapacity, boolean accessOrder, int initialCapacity) {
		this(maxCapacity, accessOrder, initialCapacity, .75f);
	}

	public LimitedLinkedHashMap(int maxCapacity, boolean accessOrder, int initialCapacity, float loadFactor) {
		super(initialCapacity, loadFactor, accessOrder);
		this.maxCapacity = maxCapacity;
	}

	public int getMaxCapacity() {
		return maxCapacity;
	}

	public void setMaxCapacity(int maxCapacity) {
		this.maxCapacity = maxCapacity;
	}

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy