mirror of
https://gitee.com/dromara/hutool.git
synced 2025-07-15 05:13:18 +08:00
fix comment
This commit is contained in:
parent
6ac537d6c3
commit
bc19e6a924
@ -32,6 +32,7 @@ public interface SynthesizedAnnotationSelector {
|
|||||||
/**
|
/**
|
||||||
* 比较两个被合成的注解,选择其中的一个并返回
|
* 比较两个被合成的注解,选择其中的一个并返回
|
||||||
*
|
*
|
||||||
|
* @param <T> 复合注解类型
|
||||||
* @param oldAnnotation 已存在的注解,该参数不允许为空
|
* @param oldAnnotation 已存在的注解,该参数不允许为空
|
||||||
* @param newAnnotation 新获取的注解,该参数不允许为空
|
* @param newAnnotation 新获取的注解,该参数不允许为空
|
||||||
* @return 被合成的注解
|
* @return 被合成的注解
|
||||||
|
@ -74,7 +74,7 @@ public abstract class AbstractTypeAnnotationScanner<T extends AbstractTypeAnnota
|
|||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
this.excludeTypes = excludeTypes;
|
this.excludeTypes = excludeTypes;
|
||||||
this.converters = new ArrayList<>();
|
this.converters = new ArrayList<>();
|
||||||
this.typedThis = (T)this;
|
this.typedThis = (T) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -219,16 +219,22 @@ public abstract class AbstractTypeAnnotationScanner<T extends AbstractTypeAnnota
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前类是否不需要处理
|
* 当前类是否不需要处理
|
||||||
|
*
|
||||||
|
* @param accessedTypes 访问类型
|
||||||
|
* @param targetClass 目标类型
|
||||||
*/
|
*/
|
||||||
protected boolean isNotNeedProcess(Set<Class<?>> accessedTypes, Class<?> targetClass) {
|
protected boolean isNotNeedProcess(Set<Class<?>> accessedTypes, Class<?> targetClass) {
|
||||||
return ObjectUtil.isNull(targetClass)
|
return ObjectUtil.isNull(targetClass)
|
||||||
|| accessedTypes.contains(targetClass)
|
|| accessedTypes.contains(targetClass)
|
||||||
|| excludeTypes.contains(targetClass)
|
|| excludeTypes.contains(targetClass)
|
||||||
|| filter.negate().test(targetClass);
|
|| filter.negate().test(targetClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 若{@link #includeInterfaces}为{@code true},则将目标类的父接口也添加到nextClasses
|
* 若{@link #includeInterfaces}为{@code true},则将目标类的父接口也添加到nextClasses
|
||||||
|
*
|
||||||
|
* @param nextClasses 下一个类集合
|
||||||
|
* @param targetClass 目标类型
|
||||||
*/
|
*/
|
||||||
protected void scanInterfaceIfNecessary(List<Class<?>> nextClasses, Class<?> targetClass) {
|
protected void scanInterfaceIfNecessary(List<Class<?>> nextClasses, Class<?> targetClass) {
|
||||||
if (includeInterfaces) {
|
if (includeInterfaces) {
|
||||||
@ -241,6 +247,9 @@ public abstract class AbstractTypeAnnotationScanner<T extends AbstractTypeAnnota
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 若{@link #includeSupperClass}为{@code true},则将目标类的父类也添加到nextClasses
|
* 若{@link #includeSupperClass}为{@code true},则将目标类的父类也添加到nextClasses
|
||||||
|
*
|
||||||
|
* @param nextClassQueue 下一个类队列
|
||||||
|
* @param targetClass 目标类型
|
||||||
*/
|
*/
|
||||||
protected void scanSuperClassIfNecessary(List<Class<?>> nextClassQueue, Class<?> targetClass) {
|
protected void scanSuperClassIfNecessary(List<Class<?>> nextClassQueue, Class<?> targetClass) {
|
||||||
if (includeSupperClass) {
|
if (includeSupperClass) {
|
||||||
@ -253,6 +262,8 @@ public abstract class AbstractTypeAnnotationScanner<T extends AbstractTypeAnnota
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 若存在转换器,则使用转换器对目标类进行转换
|
* 若存在转换器,则使用转换器对目标类进行转换
|
||||||
|
*
|
||||||
|
* @param target 目标类
|
||||||
*/
|
*/
|
||||||
protected Class<?> convert(Class<?> target) {
|
protected Class<?> convert(Class<?> target) {
|
||||||
if (hasConverters) {
|
if (hasConverters) {
|
||||||
|
@ -66,7 +66,7 @@ public interface ForestMap<K, V> extends Map<K, TreeEntry<K, V>> {
|
|||||||
* <li>若存在父节点或子节点,则将其断开其与父节点或子节点的引用关系;</li>
|
* <li>若存在父节点或子节点,则将其断开其与父节点或子节点的引用关系;</li>
|
||||||
* <li>
|
* <li>
|
||||||
* 若同时存在父节点或子节点,则会在删除后将让子节点直接成为父节点的子节点,比如:<br>
|
* 若同时存在父节点或子节点,则会在删除后将让子节点直接成为父节点的子节点,比如:<br>
|
||||||
* 现有引用关系 a -> b -> c,删除 b 后,将有 a -> c
|
* 现有引用关系 a -> b -> c,删除 b 后,将有 a -> c
|
||||||
* </li>
|
* </li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
@ -87,13 +87,14 @@ public interface ForestMap<K, V> extends Map<K, TreeEntry<K, V>> {
|
|||||||
/**
|
/**
|
||||||
* 批量添加节点
|
* 批量添加节点
|
||||||
*
|
*
|
||||||
|
* @param <C> 集合类型
|
||||||
* @param values 要添加的值
|
* @param values 要添加的值
|
||||||
* @param keyGenerator 从值中获取key的方法
|
* @param keyGenerator 从值中获取key的方法
|
||||||
* @param parentKeyGenerator 从值中获取父节点key的方法
|
* @param parentKeyGenerator 从值中获取父节点key的方法
|
||||||
* @param ignoreNullNode 是否获取到的key为null的子节点/父节点
|
* @param ignoreNullNode 是否获取到的key为null的子节点/父节点
|
||||||
*/
|
*/
|
||||||
default <C extends Collection<V>> void putAllNode(
|
default <C extends Collection<V>> void putAllNode(
|
||||||
C values, Function<V, K> keyGenerator, Function<V, K> parentKeyGenerator, boolean ignoreNullNode) {
|
C values, Function<V, K> keyGenerator, Function<V, K> parentKeyGenerator, boolean ignoreNullNode) {
|
||||||
if (CollUtil.isEmpty(values)) {
|
if (CollUtil.isEmpty(values)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -102,8 +103,8 @@ public interface ForestMap<K, V> extends Map<K, TreeEntry<K, V>> {
|
|||||||
final K parentKey = parentKeyGenerator.apply(v);
|
final K parentKey = parentKeyGenerator.apply(v);
|
||||||
|
|
||||||
// 不忽略keu为null节点
|
// 不忽略keu为null节点
|
||||||
boolean hasKey = ObjectUtil.isNotNull(key);
|
final boolean hasKey = ObjectUtil.isNotNull(key);
|
||||||
boolean hasParentKey = ObjectUtil.isNotNull(parentKey);
|
final boolean hasParentKey = ObjectUtil.isNotNull(parentKey);
|
||||||
if (!ignoreNullNode || (hasKey && hasParentKey)) {
|
if (!ignoreNullNode || (hasKey && hasParentKey)) {
|
||||||
linkNodes(parentKey, key);
|
linkNodes(parentKey, key);
|
||||||
get(key).setValue(v);
|
get(key).setValue(v);
|
||||||
@ -207,7 +208,7 @@ public interface ForestMap<K, V> extends Map<K, TreeEntry<K, V>> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定节点所在树结构的全部树节点 <br>
|
* 获取指定节点所在树结构的全部树节点 <br>
|
||||||
* 比如:存在 a -> b -> c 的关系,则输入 a/b/c 都将返回 a, b, c
|
* 比如:存在 a -> b -> c 的关系,则输入 a/b/c 都将返回 a, b, c
|
||||||
*
|
*
|
||||||
* @param key 指定节点的key
|
* @param key 指定节点的key
|
||||||
* @return 节点
|
* @return 节点
|
||||||
@ -217,47 +218,48 @@ public interface ForestMap<K, V> extends Map<K, TreeEntry<K, V>> {
|
|||||||
if (ObjectUtil.isNull(target)) {
|
if (ObjectUtil.isNull(target)) {
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
Set<TreeEntry<K, V>> results = CollUtil.newLinkedHashSet(target.getRoot());
|
final Set<TreeEntry<K, V>> results = CollUtil.newLinkedHashSet(target.getRoot());
|
||||||
CollUtil.addAll(results, target.getRoot().getChildren().values());
|
CollUtil.addAll(results, target.getRoot().getChildren().values());
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取以指定节点作为叶子节点的树结构,然后获取该树结构的根节点 <br>
|
* 获取以指定节点作为叶子节点的树结构,然后获取该树结构的根节点 <br>
|
||||||
* 比如:存在 a -> b -> c 的关系,则输入 a/b/c 都将返回 a
|
* 比如:存在 a -> b -> c 的关系,则输入 a/b/c 都将返回 a
|
||||||
*
|
*
|
||||||
* @param key 指定节点的key
|
* @param key 指定节点的key
|
||||||
* @return 节点
|
* @return 节点
|
||||||
*/
|
*/
|
||||||
default TreeEntry<K, V> getRootNode(K key) {
|
default TreeEntry<K, V> getRootNode(K key) {
|
||||||
return Opt.ofNullable(get(key))
|
return Opt.ofNullable(get(key))
|
||||||
.map(TreeEntry::getRoot)
|
.map(TreeEntry::getRoot)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定节点的直接父节点 <br>
|
* 获取指定节点的直接父节点 <br>
|
||||||
* 比如:若存在 a -> b -> c 的关系,此时输入 a 将返回 null,输入 b 将返回 a,输入 c 将返回 b
|
* 比如:若存在 a -> b -> c 的关系,此时输入 a 将返回 null,输入 b 将返回 a,输入 c 将返回 b
|
||||||
*
|
*
|
||||||
* @param key 指定节点的key
|
* @param key 指定节点的key
|
||||||
* @return 节点
|
* @return 节点
|
||||||
*/
|
*/
|
||||||
default TreeEntry<K, V> getDeclaredParentNode(K key) {
|
default TreeEntry<K, V> getDeclaredParentNode(K key) {
|
||||||
return Opt.ofNullable(get(key))
|
return Opt.ofNullable(get(key))
|
||||||
.map(TreeEntry::getDeclaredParent)
|
.map(TreeEntry::getDeclaredParent)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取以指定节点作为叶子节点的树结构,然后获取该树结构中指定节点的指定父节点
|
* 获取以指定节点作为叶子节点的树结构,然后获取该树结构中指定节点的指定父节点
|
||||||
*
|
*
|
||||||
* @param key 指定父节点的key
|
* @param key 指定节点的key
|
||||||
|
* @param parentKey 指定父节点key
|
||||||
* @return 节点
|
* @return 节点
|
||||||
*/
|
*/
|
||||||
default TreeEntry<K, V> getParentNode(K key, K parentKey) {
|
default TreeEntry<K, V> getParentNode(K key, K parentKey) {
|
||||||
return Opt.ofNullable(get(key))
|
return Opt.ofNullable(get(key))
|
||||||
.map(t -> t.getParent(parentKey))
|
.map(t -> t.getParent(parentKey))
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -269,8 +271,8 @@ public interface ForestMap<K, V> extends Map<K, TreeEntry<K, V>> {
|
|||||||
*/
|
*/
|
||||||
default boolean containsParentNode(K key, K parentKey) {
|
default boolean containsParentNode(K key, K parentKey) {
|
||||||
return Opt.ofNullable(get(key))
|
return Opt.ofNullable(get(key))
|
||||||
.map(m -> m.containsParent(parentKey))
|
.map(m -> m.containsParent(parentKey))
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===================== 子节点相关方法 =====================
|
// ===================== 子节点相关方法 =====================
|
||||||
@ -284,36 +286,36 @@ public interface ForestMap<K, V> extends Map<K, TreeEntry<K, V>> {
|
|||||||
*/
|
*/
|
||||||
default boolean containsChildNode(K parentKey, K childKey) {
|
default boolean containsChildNode(K parentKey, K childKey) {
|
||||||
return Opt.ofNullable(get(parentKey))
|
return Opt.ofNullable(get(parentKey))
|
||||||
.map(m -> m.containsChild(childKey))
|
.map(m -> m.containsChild(childKey))
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定父节点直接关联的子节点 <br>
|
* 获取指定父节点直接关联的子节点 <br>
|
||||||
* 比如:若存在 a -> b -> c 的关系,此时输入 b 将返回 c,输入 a 将返回 b
|
* 比如:若存在 a -> b -> c 的关系,此时输入 b 将返回 c,输入 a 将返回 b
|
||||||
*
|
*
|
||||||
* @param key key
|
* @param key key
|
||||||
* @return 节点
|
* @return 节点
|
||||||
*/
|
*/
|
||||||
default Collection<TreeEntry<K, V>> getDeclaredChildNodes(K key) {
|
default Collection<TreeEntry<K, V>> getDeclaredChildNodes(K key) {
|
||||||
return Opt.ofNullable(get(key))
|
return Opt.ofNullable(get(key))
|
||||||
.map(TreeEntry::getDeclaredChildren)
|
.map(TreeEntry::getDeclaredChildren)
|
||||||
.map(Map::values)
|
.map(Map::values)
|
||||||
.orElseGet(Collections::emptyList);
|
.orElseGet(Collections::emptyList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定父节点的全部子节点 <br>
|
* 获取指定父节点的全部子节点 <br>
|
||||||
* 比如:若存在 a -> b -> c 的关系,此时输入 b 将返回 c,输入 a 将返回 b,c
|
* 比如:若存在 a -> b -> c 的关系,此时输入 b 将返回 c,输入 a 将返回 b,c
|
||||||
*
|
*
|
||||||
* @param key key
|
* @param key key
|
||||||
* @return 该节点的全部子节点
|
* @return 该节点的全部子节点
|
||||||
*/
|
*/
|
||||||
default Collection<TreeEntry<K, V>> getChildNodes(K key) {
|
default Collection<TreeEntry<K, V>> getChildNodes(K key) {
|
||||||
return Opt.ofNullable(get(key))
|
return Opt.ofNullable(get(key))
|
||||||
.map(TreeEntry::getChildren)
|
.map(TreeEntry::getChildren)
|
||||||
.map(Map::values)
|
.map(Map::values)
|
||||||
.orElseGet(Collections::emptyList);
|
.orElseGet(Collections::emptyList);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ public class LinkedForestMap<K, V> implements ForestMap<K, V> {
|
|||||||
final Map<K, TreeEntry<K, V>> targetChildren = target.getChildren();
|
final Map<K, TreeEntry<K, V>> targetChildren = target.getChildren();
|
||||||
parent.removeDeclaredChild(target.getKey());
|
parent.removeDeclaredChild(target.getKey());
|
||||||
target.clear();
|
target.clear();
|
||||||
targetChildren.forEach((k, c) -> parent.addChild((TreeEntryNode<K, V>)c));
|
targetChildren.forEach((k, c) -> parent.addChild((TreeEntryNode<K, V>) c));
|
||||||
}
|
}
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
@ -174,8 +174,8 @@ public class LinkedForestMap<K, V> implements ForestMap<K, V> {
|
|||||||
@Override
|
@Override
|
||||||
public Set<Map.Entry<K, TreeEntry<K, V>>> entrySet() {
|
public Set<Map.Entry<K, TreeEntry<K, V>>> entrySet() {
|
||||||
return nodes.entrySet().stream()
|
return nodes.entrySet().stream()
|
||||||
.map(this::wrap)
|
.map(this::wrap)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -262,7 +262,8 @@ public class LinkedForestMap<K, V> implements ForestMap<K, V> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void linkNodes(K parentKey, K childKey, BiConsumer<TreeEntry<K, V>, TreeEntry<K, V>> consumer) {
|
public void linkNodes(K parentKey, K childKey, BiConsumer<TreeEntry<K, V>, TreeEntry<K, V>> consumer) {
|
||||||
consumer = ObjectUtil.defaultIfNull(consumer, (parent, child) -> {});
|
consumer = ObjectUtil.defaultIfNull(consumer, (parent, child) -> {
|
||||||
|
});
|
||||||
final TreeEntryNode<K, V> parentNode = nodes.computeIfAbsent(parentKey, t -> new TreeEntryNode<>(null, t));
|
final TreeEntryNode<K, V> parentNode = nodes.computeIfAbsent(parentKey, t -> new TreeEntryNode<>(null, t));
|
||||||
TreeEntryNode<K, V> childNode = nodes.get(childKey);
|
TreeEntryNode<K, V> childNode = nodes.get(childKey);
|
||||||
|
|
||||||
@ -290,10 +291,10 @@ public class LinkedForestMap<K, V> implements ForestMap<K, V> {
|
|||||||
parentNode.addChild(childNode);
|
parentNode.addChild(childNode);
|
||||||
}
|
}
|
||||||
// 5.子节点存在,且已经与其他节点构成父子关系,但是不允许子节点直接修改其父节点
|
// 5.子节点存在,且已经与其他节点构成父子关系,但是不允许子节点直接修改其父节点
|
||||||
else{
|
else {
|
||||||
throw new IllegalArgumentException(StrUtil.format(
|
throw new IllegalArgumentException(StrUtil.format(
|
||||||
"[{}] has been used as child of [{}], can not be overwrite as child of [{}]",
|
"[{}] has been used as child of [{}], can not be overwrite as child of [{}]",
|
||||||
childNode.getKey(), childNode.getDeclaredParent().getKey(), parentKey
|
childNode.getKey(), childNode.getDeclaredParent().getKey(), parentKey
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
consumer.accept(parentNode, childNode);
|
consumer.accept(parentNode, childNode);
|
||||||
@ -358,18 +359,18 @@ public class LinkedForestMap<K, V> implements ForestMap<K, V> {
|
|||||||
* 创建一个节点
|
* 创建一个节点
|
||||||
*
|
*
|
||||||
* @param parent 节点的父节点
|
* @param parent 节点的父节点
|
||||||
* @param key 节点的key
|
* @param key 节点的key
|
||||||
*/
|
*/
|
||||||
public TreeEntryNode(TreeEntryNode<K, V> parent, K key) {
|
public TreeEntryNode(TreeEntryNode<K, V> parent, K key) {
|
||||||
this(parent, key , null);
|
this(parent, key, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个节点
|
* 创建一个节点
|
||||||
*
|
*
|
||||||
* @param parent 节点的父节点
|
* @param parent 节点的父节点
|
||||||
* @param key 节点的key
|
* @param key 节点的key
|
||||||
* @param value 节点的value
|
* @param value 节点的value
|
||||||
*/
|
*/
|
||||||
public TreeEntryNode(TreeEntryNode<K, V> parent, K key, V value) {
|
public TreeEntryNode(TreeEntryNode<K, V> parent, K key, V value) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
@ -440,7 +441,7 @@ public class LinkedForestMap<K, V> implements ForestMap<K, V> {
|
|||||||
* @return 遍历到的最后一个节点
|
* @return 遍历到的最后一个节点
|
||||||
*/
|
*/
|
||||||
TreeEntryNode<K, V> traverseParentNodes(
|
TreeEntryNode<K, V> traverseParentNodes(
|
||||||
boolean includeCurrent, Consumer<TreeEntryNode<K, V>> consumer, Predicate<TreeEntryNode<K, V>> breakTraverse) {
|
boolean includeCurrent, Consumer<TreeEntryNode<K, V>> consumer, Predicate<TreeEntryNode<K, V>> breakTraverse) {
|
||||||
breakTraverse = ObjectUtil.defaultIfNull(breakTraverse, n -> false);
|
breakTraverse = ObjectUtil.defaultIfNull(breakTraverse, n -> false);
|
||||||
TreeEntryNode<K, V> curr = includeCurrent ? this : this.parent;
|
TreeEntryNode<K, V> curr = includeCurrent ? this : this.parent;
|
||||||
while (ObjectUtil.isNotNull(curr)) {
|
while (ObjectUtil.isNotNull(curr)) {
|
||||||
@ -472,7 +473,8 @@ public class LinkedForestMap<K, V> implements ForestMap<K, V> {
|
|||||||
if (ObjectUtil.isNotNull(this.root)) {
|
if (ObjectUtil.isNotNull(this.root)) {
|
||||||
return this.root;
|
return this.root;
|
||||||
} else {
|
} else {
|
||||||
this.root = traverseParentNodes(true, p -> {}, p -> !p.hasParent());
|
this.root = traverseParentNodes(true, p -> {
|
||||||
|
}, p -> !p.hasParent());
|
||||||
}
|
}
|
||||||
return this.root;
|
return this.root;
|
||||||
}
|
}
|
||||||
@ -495,13 +497,14 @@ public class LinkedForestMap<K, V> implements ForestMap<K, V> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TreeEntryNode<K, V> getParent(K key) {
|
public TreeEntryNode<K, V> getParent(K key) {
|
||||||
return traverseParentNodes(false, p -> {}, p -> p.equalsKey(key));
|
return traverseParentNodes(false, p -> {
|
||||||
|
}, p -> p.equalsKey(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取以当前节点作为根节点的树结构,然后遍历所有节点
|
* 获取以当前节点作为根节点的树结构,然后遍历所有节点
|
||||||
*
|
*
|
||||||
* @param includeSelf 是否处理当前节点
|
* @param includeSelf 是否处理当前节点
|
||||||
* @param nodeConsumer 对节点的处理
|
* @param nodeConsumer 对节点的处理
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -513,6 +516,7 @@ public class LinkedForestMap<K, V> implements ForestMap<K, V> {
|
|||||||
* 指定key与当前节点的key是否相等
|
* 指定key与当前节点的key是否相等
|
||||||
*
|
*
|
||||||
* @param key 要比较的key
|
* @param key 要比较的key
|
||||||
|
* @return 是否key一致
|
||||||
*/
|
*/
|
||||||
public boolean equalsKey(K key) {
|
public boolean equalsKey(K key) {
|
||||||
return ObjectUtil.equal(getKey(), key);
|
return ObjectUtil.equal(getKey(), key);
|
||||||
@ -529,7 +533,7 @@ public class LinkedForestMap<K, V> implements ForestMap<K, V> {
|
|||||||
* @return 遍历到的最后一个节点
|
* @return 遍历到的最后一个节点
|
||||||
*/
|
*/
|
||||||
TreeEntryNode<K, V> traverseChildNodes(
|
TreeEntryNode<K, V> traverseChildNodes(
|
||||||
boolean includeCurrent, BiConsumer<Integer, TreeEntryNode<K, V>> consumer, BiPredicate<Integer, TreeEntryNode<K, V>> breakTraverse) {
|
boolean includeCurrent, BiConsumer<Integer, TreeEntryNode<K, V>> consumer, BiPredicate<Integer, TreeEntryNode<K, V>> breakTraverse) {
|
||||||
breakTraverse = ObjectUtil.defaultIfNull(breakTraverse, (i, n) -> false);
|
breakTraverse = ObjectUtil.defaultIfNull(breakTraverse, (i, n) -> false);
|
||||||
final Deque<List<TreeEntryNode<K, V>>> keyNodeDeque = CollUtil.newLinkedList(CollUtil.newArrayList(this));
|
final Deque<List<TreeEntryNode<K, V>>> keyNodeDeque = CollUtil.newLinkedList(CollUtil.newArrayList(this));
|
||||||
boolean needProcess = includeCurrent;
|
boolean needProcess = includeCurrent;
|
||||||
@ -572,9 +576,9 @@ public class LinkedForestMap<K, V> implements ForestMap<K, V> {
|
|||||||
|
|
||||||
// 检查循环引用
|
// 检查循环引用
|
||||||
traverseParentNodes(true, s -> Assert.notEquals(
|
traverseParentNodes(true, s -> Assert.notEquals(
|
||||||
s.key, child.key,
|
s.key, child.key,
|
||||||
"circular reference between [{}] and [{}]!",
|
"circular reference between [{}] and [{}]!",
|
||||||
s.key, this.key
|
s.key, this.key
|
||||||
), null);
|
), null);
|
||||||
|
|
||||||
// 调整该节点的信息
|
// 调整该节点的信息
|
||||||
@ -594,7 +598,7 @@ public class LinkedForestMap<K, V> implements ForestMap<K, V> {
|
|||||||
* @param key 子节点
|
* @param key 子节点
|
||||||
*/
|
*/
|
||||||
void removeDeclaredChild(K key) {
|
void removeDeclaredChild(K key) {
|
||||||
TreeEntryNode<K, V> child = children.get(key);
|
final TreeEntryNode<K, V> child = children.get(key);
|
||||||
if (ObjectUtil.isNull(child)) {
|
if (ObjectUtil.isNull(child)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -618,7 +622,8 @@ public class LinkedForestMap<K, V> implements ForestMap<K, V> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TreeEntryNode<K, V> getChild(K key) {
|
public TreeEntryNode<K, V> getChild(K key) {
|
||||||
return traverseChildNodes(false, (i, c) -> {}, (i, c) -> c.equalsKey(key));
|
return traverseChildNodes(false, (i, c) -> {
|
||||||
|
}, (i, c) -> c.equalsKey(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -667,7 +672,7 @@ public class LinkedForestMap<K, V> implements ForestMap<K, V> {
|
|||||||
if (o == null || this.getClass().equals(o.getClass()) || ClassUtil.isAssignable(this.getClass(), o.getClass())) {
|
if (o == null || this.getClass().equals(o.getClass()) || ClassUtil.isAssignable(this.getClass(), o.getClass())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final TreeEntry<?, ?> treeEntry = (TreeEntry<?, ?>)o;
|
final TreeEntry<?, ?> treeEntry = (TreeEntry<?, ?>) o;
|
||||||
return ObjectUtil.equals(this.getKey(), treeEntry.getKey());
|
return ObjectUtil.equals(this.getKey(), treeEntry.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -707,17 +712,21 @@ public class LinkedForestMap<K, V> implements ForestMap<K, V> {
|
|||||||
*/
|
*/
|
||||||
public static class EntryNodeWrapper<K, V, N extends TreeEntry<K, V>> implements Map.Entry<K, TreeEntry<K, V>> {
|
public static class EntryNodeWrapper<K, V, N extends TreeEntry<K, V>> implements Map.Entry<K, TreeEntry<K, V>> {
|
||||||
private final N entryNode;
|
private final N entryNode;
|
||||||
|
|
||||||
EntryNodeWrapper(N entryNode) {
|
EntryNodeWrapper(N entryNode) {
|
||||||
this.entryNode = entryNode;
|
this.entryNode = entryNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public K getKey() {
|
public K getKey() {
|
||||||
return entryNode.getKey();
|
return entryNode.getKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TreeEntry<K, V> getValue() {
|
public TreeEntry<K, V> getValue() {
|
||||||
return entryNode;
|
return entryNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TreeEntry<K, V> setValue(TreeEntry<K, V> value) {
|
public TreeEntry<K, V> setValue(TreeEntry<K, V> value) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
Loading…
Reference in New Issue
Block a user