
net.jrouter.util.LRUMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jrouter Show documentation
Show all versions of jrouter Show documentation
jrouter是一个围绕对象方法基于责任链(拦截器)模式设计的开源轻量级Java容器。它专注于方法的映射、调用、拦截和结果处理,采用基于配置和注解的方式来抽取和收集程序中对象的方法(method)以用于路由映射,HTTP控制器,RPC,各种应用等。
/*
* Copyright (C) 2010-2111 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package net.jrouter.util;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* A simple LRU cache that implements the{@code Map} interface. Instances are not
* thread-safe and should be synchronized externally, for instance by using
* {@link java.util.Collections#synchronizedMap}.
*
* @param the type of keys maintained by this map
* @param the type of mapped values
*/
public class LRUMap extends LinkedHashMap {
private static final long serialVersionUID = 1L;
/**
* The max number of key-value mappings contained in this map.
*/
private final int maxEntries;
/**
* 构造一个带指定最大条目数的空{@code LRUMap}实例。
* @param maxEntries 最大条目数。
*/
public LRUMap(int maxEntries) {
this(128, maxEntries);
}
/**
* 构造一个带指定初始容量、最大条目数的空{@code LRUMap}实例。
* @param initialEntries 初始容量。
* @param maxEntries 最大条目数。
*/
public LRUMap(int initialEntries, int maxEntries) {
super(initialEntries, .75f, true);
this.maxEntries = maxEntries;
}
@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > maxEntries;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy