Package org.miaixz.bus.core.center.map
Class FixedLinkedHashMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,V>
org.miaixz.bus.core.center.map.FixedLinkedHashMap<K,V>
- Type Parameters:
K- 键类型V- 值类型
- All Implemented Interfaces:
Serializable,Cloneable,Map<K,,V> SequencedMap<K,V>
固定大小的
LinkedHashMap 实现
注意此类非线程安全,由于LinkedHashMap.get(Object)操作会修改链表的顺序结构,因此也不可以使用读写锁。- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint获取容量protected booleanremoveEldestEntry(Map.Entry<K, V> eldest) voidsetCapacity(int capacity) 设置容量voidsetRemoveListener(Consumer<Map.Entry<K, V>> removeListener) 设置自定义移除监听Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, newLinkedHashMap, putFirst, putLast, replaceAll, reversed, sequencedEntrySet, sequencedKeySet, sequencedValues, valuesMethods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replace, sizeMethods inherited from class java.util.AbstractMap
equals, hashCode, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, sizeMethods inherited from interface java.util.SequencedMap
firstEntry, lastEntry, pollFirstEntry, pollLastEntry
-
Constructor Details
-
FixedLinkedHashMap
public FixedLinkedHashMap(int capacity) 构造- Parameters:
capacity- 容量,实际初始容量比容量大1
-
-
Method Details
-
getCapacity
public int getCapacity()获取容量- Returns:
- 容量
-
setCapacity
public void setCapacity(int capacity) 设置容量- Parameters:
capacity- 容量
-
setRemoveListener
设置自定义移除监听- Parameters:
removeListener- 移除监听
-
removeEldestEntry
- Overrides:
removeEldestEntryin classLinkedHashMap<K,V>
-