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