K - key类型V - 值类型public class LinkedForestMap<K,V> extends Object implements ForestMap<K,V>
ForestMap的基本实现。
该集合可以被视为以LinkedForestMap.TreeEntryNode.getKey()作为key,LinkedForestMap.TreeEntryNode实例作为value的LinkedHashMap。
使用时,将每一对键与值对视为一个LinkedForestMap.TreeEntryNode节点,节点的id即为LinkedForestMap.TreeEntryNode.getKey(),
任何情况下使用相同的key都将会访问到同一个节点。
节点通过key形成父子关系,并最终构成多叉树结构,多组平行的多叉树将在当前集合中构成森林。
使用者可以通过ForestMap本身的方法来对森林进行操作或访问,
也可以在获取到TreeEntry后,使用节点本身的方法对数进行操作或访问。
| Modifier and Type | Class and Description |
|---|---|
static class |
LinkedForestMap.EntryNodeWrapper<K,V,N extends TreeEntry<K,V>>
Map.Entry包装类 |
static class |
LinkedForestMap.TreeEntryNode<K,V>
树节点
|
| Constructor and Description |
|---|
LinkedForestMap(boolean allowOverrideParent)
构建
LinkedForestMap |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
将当前集合清空,并清除全部节点间的引用关系
|
boolean |
containsKey(Object key)
当前实例中是否存在key对应的节点
|
boolean |
containsValue(Object value)
当前实例中是否存在对应的
TreeEntry实例 |
Set<Map.Entry<K,TreeEntry<K,V>>> |
entrySet()
|
TreeEntry<K,V> |
get(Object key)
获取key对应的节点
|
boolean |
isEmpty()
当前实例是否为空
|
Set<K> |
keySet()
返回当前实例中全部的key组成的
Set集合 |
void |
linkNodes(K parentKey,
K childKey,
BiConsumer<TreeEntry<K,V>,TreeEntry<K,V>> consumer)
为指定的节点建立父子关系,若
parentKey或childKey对应节点不存在,则会创建一个对应的值为null的空节点 |
void |
putLinkedNodes(K parentKey,
K childKey,
V childValue)
添加子节点,并为子节点指定父节点:
若
parentKey或childKey对应的节点不存在,则会根据键值创建一个对应的节点;
若parentKey或childKey对应的节点存在,则会更新对应节点的值;
|
void |
putLinkedNodes(K parentKey,
V parentValue,
K childKey,
V childValue)
同时添加父子节点:
若
parentKey或childKey对应的节点不存在,则会根据键值创建一个对应的节点;
若parentKey或childKey对应的节点存在,则会更新对应节点的值;
该操作等同于:
TreeEntry<K, V> parent = putNode(parentKey, parentValue);
TreeEntry<K, V> child = putNode(childKey, childValue);
linkNodes(parentKey, childKey);
|
LinkedForestMap.TreeEntryNode<K,V> |
putNode(K key,
V value)
添加一个节点
若key对应节点不存在,则以传入的键值创建一个新的节点;
若key对应节点存在,则将该节点的值替换为
node指定的值;
|
TreeEntry<K,V> |
remove(Object key)
将指定节点从当前
Map中删除
若存在父节点或子节点,则将其断开其与父节点或子节点的引用关系;
若同时存在父节点或子节点,则会在删除后将让子节点直接成为父节点的子节点,比如:现有引用关系 a -> b -> c,删除 b 后,将有 a -> c |
int |
size()
获取当前实例中的节点个数
|
void |
unlinkNode(K parentKey,
K childKey)
移除指定父节点与其直接关联的子节点间的引用关系,但是不会将该节点从集合中删除
|
Collection<TreeEntry<K,V>> |
values()
返回当前实例中全部
TreeEntry组成的Collection集合 |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcontainsChildNode, containsParentNode, getChildNodes, getDeclaredChildNodes, getDeclaredParentNode, getNodeValue, getParentNode, getRootNode, getTreeNodes, linkNodes, put, putAll, putAllNodecompute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAllpublic LinkedForestMap(boolean allowOverrideParent)
LinkedForestMapallowOverrideParent - 当指定节点已经与其他节点构成了父子关系,是否允许将该节点的父节点强制替换为指定节点public int size()
public boolean isEmpty()
public boolean containsKey(Object key)
public TreeEntry<K,V> remove(Object key)
Map中删除
public void clear()
public Collection<TreeEntry<K,V>> values()
TreeEntry组成的Collection集合public LinkedForestMap.TreeEntryNode<K,V> putNode(K key, V value)
node指定的值;public void putLinkedNodes(K parentKey, V parentValue, K childKey, V childValue)
parentKey或childKey对应的节点不存在,则会根据键值创建一个对应的节点;parentKey或childKey对应的节点存在,则会更新对应节点的值;
TreeEntry<K, V> parent = putNode(parentKey, parentValue);
TreeEntry<K, V> child = putNode(childKey, childValue);
linkNodes(parentKey, childKey);
putLinkedNodes in interface ForestMap<K,V>parentKey - 父节点的keyparentValue - 父节点的valuechildKey - 子节点的keychildValue - 子节点的值public void putLinkedNodes(K parentKey, K childKey, V childValue)
parentKey或childKey对应的节点不存在,则会根据键值创建一个对应的节点;parentKey或childKey对应的节点存在,则会更新对应节点的值;putLinkedNodes in interface ForestMap<K,V>parentKey - 父节点的keychildKey - 子节点的keychildValue - 子节点的值public void linkNodes(K parentKey, K childKey, BiConsumer<TreeEntry<K,V>,TreeEntry<K,V>> consumer)
parentKey或childKey对应节点不存在,则会创建一个对应的值为null的空节点Copyright © 2025. All rights reserved.