Class TableMap<K,V>

java.lang.Object
org.miaixz.bus.core.center.map.TableMap<K,V>
Type Parameters:
K - 键类型
V - 值类型
All Implemented Interfaces:
Serializable, Iterable<Map.Entry<K,V>>, Map<K,V>

public class TableMap<K,V> extends Object implements Map<K,V>, Iterable<Map.Entry<K,V>>, Serializable
可重复键和值的Map 通过键值单独建立List方式,使键值对一一对应,实现正向和反向两种查找 无论是正向还是反向,都是遍历列表查找过程,相比标准的HashMap要慢,数据越多越慢
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • TableMap

      public TableMap()
      构造
    • TableMap

      public TableMap(int size)
      构造
      Parameters:
      size - 初始容量
    • TableMap

      public TableMap(K[] keys, V[] values)
      构造
      Parameters:
      keys - 键列表
      values - 值列表
  • Method Details

    • size

      public int size()
      Specified by:
      size in interface Map<K,V>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K,V>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<K,V>
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<K,V>
    • get

      public V get(Object key)
      Specified by:
      get in interface Map<K,V>
    • getKey

      public K getKey(V value)
      根据value获得对应的key,只返回找到的第一个value对应的key值
      Parameters:
      value - 值
      Returns:
    • getValues

      public List<V> getValues(K key)
      获取指定key对应的所有值
      Parameters:
      key - 键
      Returns:
      值列表
    • getKeys

      public List<K> getKeys(V value)
      获取指定value对应的所有key
      Parameters:
      value - 值
      Returns:
      值列表
    • put

      public V put(K key, V value)
      Specified by:
      put in interface Map<K,V>
    • remove

      public V remove(Object key)
      移除指定的所有键和对应的所有值
      Specified by:
      remove in interface Map<K,V>
      Parameters:
      key - 键
      Returns:
      最后一个移除的值
    • removeByIndex

      public V removeByIndex(int index)
      移除指定位置的键值对
      Parameters:
      index - 位置,不能越界
      Returns:
      移除的值
    • putAll

      public void putAll(Map<? extends K,? extends V> m)
      Specified by:
      putAll in interface Map<K,V>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K,V>
    • keySet

      public Set<K> keySet()
      Specified by:
      keySet in interface Map<K,V>
    • keys

      public List<K> keys()
      获取所有键,可重复,不可修改
      Returns:
      键列表
    • values

      public Collection<V> values()
      Specified by:
      values in interface Map<K,V>
    • entrySet

      public Set<Map.Entry<K,V>> entrySet()
      Specified by:
      entrySet in interface Map<K,V>
    • iterator

      public Iterator<Map.Entry<K,V>> iterator()
      Specified by:
      iterator in interface Iterable<K>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • forEach

      public void forEach(BiConsumer<? super K,? super V> action)
      Specified by:
      forEach in interface Map<K,V>
    • remove

      public boolean remove(Object key, Object value)
      Specified by:
      remove in interface Map<K,V>
    • replaceAll

      public void replaceAll(BiFunction<? super K,? super V,? extends V> function)
      Specified by:
      replaceAll in interface Map<K,V>
    • replace

      public boolean replace(K key, V oldValue, V newValue)
      Specified by:
      replace in interface Map<K,V>
    • replace

      public V replace(K key, V value)
      替换指定key的所有值为指定值
      Specified by:
      replace in interface Map<K,V>
      Parameters:
      key - 指定的key
      value - 替换的值
      Returns:
      最后替换的值
    • computeIfPresent

      public V computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
      Specified by:
      computeIfPresent in interface Map<K,V>