mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
246e61678e
commit
d458b1451c
@ -2,7 +2,7 @@ package cn.hutool.core.classloader;
|
||||
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
import cn.hutool.core.reflect.MethodUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -13,7 +13,13 @@ import cn.hutool.core.text.StrUtil;
|
||||
*/
|
||||
public class Base16Codec implements Encoder<byte[], char[]>, Decoder<CharSequence, byte[]> {
|
||||
|
||||
/**
|
||||
* 编码解码器:小写
|
||||
*/
|
||||
public static final Base16Codec CODEC_LOWER = new Base16Codec(true);
|
||||
/**
|
||||
* 编码解码器:大写
|
||||
*/
|
||||
public static final Base16Codec CODEC_UPPER = new Base16Codec(false);
|
||||
|
||||
private final char[] alphabets;
|
||||
|
@ -166,7 +166,9 @@ public class PercentCodec implements Encoder<byte[], byte[]>, Serializable {
|
||||
* @author looly
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public static class Builder implements cn.hutool.core.builder.Builder<PercentCodec> {
|
||||
public static class Builder implements cn.hutool.core.lang.builder.Builder<PercentCodec> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 从已知PercentCodec创建PercentCodec,会复制给定PercentCodec的安全字符
|
||||
*
|
||||
|
@ -2,7 +2,7 @@ package cn.hutool.core.compiler;
|
||||
|
||||
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
@ -8,7 +8,7 @@ import cn.hutool.core.io.resource.FileResource;
|
||||
import cn.hutool.core.io.resource.Resource;
|
||||
import cn.hutool.core.io.resource.StringResource;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
|
||||
|
@ -2,7 +2,7 @@ package cn.hutool.core.compiler;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
import java.io.BufferedInputStream;
|
||||
|
@ -20,7 +20,7 @@ import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.reflect.ClassUtil;
|
||||
import cn.hutool.core.regex.ReUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
import cn.hutool.core.compress.ZipUtil;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
|
@ -3,7 +3,7 @@ package cn.hutool.core.io.resource;
|
||||
import cn.hutool.core.classloader.ClassLoaderUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
|
||||
|
@ -3,7 +3,7 @@ package cn.hutool.core.io.resource;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
@ -7,7 +7,7 @@ import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.classloader.ClassLoaderUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
|
@ -2,7 +2,7 @@ package cn.hutool.core.io.resource;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
@ -4,7 +4,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.watch.watchers.WatcherChain;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.hutool.core.io.watch;
|
||||
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.core.builder;
|
||||
package cn.hutool.core.lang.builder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -16,4 +16,4 @@ public interface Builder<T> extends Serializable{
|
||||
* @return 被构建的对象
|
||||
*/
|
||||
T build();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.core.builder;
|
||||
package cn.hutool.core.lang.builder;
|
||||
|
||||
import cn.hutool.core.lang.func.SerConsumer3;
|
||||
|
||||
@ -55,6 +55,7 @@ import java.util.function.Supplier;
|
||||
*
|
||||
* @author TomXin VampireAchao
|
||||
* @since 5.7.21
|
||||
* @param <T> 构建对象类型
|
||||
*/
|
||||
public class GenericBuilder<T> implements Builder<T> {
|
||||
private static final long serialVersionUID = 1L;
|
@ -5,4 +5,4 @@
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
package cn.hutool.core.builder;
|
||||
package cn.hutool.core.lang.builder;
|
@ -1,7 +1,7 @@
|
||||
package cn.hutool.core.map;
|
||||
|
||||
|
||||
import cn.hutool.core.builder.Builder;
|
||||
import cn.hutool.core.lang.builder.Builder;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.map.multi;
|
||||
|
||||
import cn.hutool.core.builder.Builder;
|
||||
import cn.hutool.core.lang.builder.Builder;
|
||||
import cn.hutool.core.collection.iter.ComputeIter;
|
||||
import cn.hutool.core.collection.iter.IterUtil;
|
||||
import cn.hutool.core.collection.iter.TransIter;
|
||||
|
@ -22,6 +22,9 @@ import java.util.regex.Matcher;
|
||||
*/
|
||||
public class Ipv4Util {
|
||||
|
||||
/**
|
||||
* 本地IP:127.0.0.1
|
||||
*/
|
||||
public static final String LOCAL_IP = "127.0.0.1";
|
||||
|
||||
/**
|
||||
@ -162,9 +165,6 @@ public class Ipv4Util {
|
||||
if (matcher.matches()) {
|
||||
return matchAddress(matcher);
|
||||
}
|
||||
// Validator.validateIpv4(strIP, "Invalid IPv4 address!");
|
||||
// final long[] ip = Convert.convert(long[].class, StrUtil.split(strIP, CharUtil.DOT));
|
||||
// return (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3];
|
||||
throw new IllegalArgumentException("Invalid IPv4 address!");
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
* @since 4.0.3
|
||||
*
|
||||
*/
|
||||
public class LocalPortGenerater implements Serializable{
|
||||
public class LocalPortGenerator implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 备选的本地端口 */
|
||||
@ -23,7 +23,7 @@ public class LocalPortGenerater implements Serializable{
|
||||
*
|
||||
* @param beginPort 起始端口号
|
||||
*/
|
||||
public LocalPortGenerater(final int beginPort) {
|
||||
public LocalPortGenerator(final int beginPort) {
|
||||
alternativePort = new AtomicInteger(beginPort);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.core.net;
|
||||
package cn.hutool.core.net.ssl;
|
||||
|
||||
import javax.net.ssl.SSLEngine;
|
||||
import javax.net.ssl.X509ExtendedTrustManager;
|
@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.net;
|
||||
package cn.hutool.core.net.ssl;
|
||||
|
||||
import cn.hutool.core.builder.Builder;
|
||||
import cn.hutool.core.lang.builder.Builder;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.core.net;
|
||||
package cn.hutool.core.net.ssl;
|
||||
|
||||
/**
|
||||
* SSL或TLS协议
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.core.net;
|
||||
package cn.hutool.core.net.ssl;
|
||||
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
|
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* SSL相关封装
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
package cn.hutool.core.net.ssl;
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.core.net;
|
||||
package cn.hutool.core.net.url;
|
||||
|
||||
import cn.hutool.core.codec.PercentCodec;
|
||||
|
2
hutool-core/src/main/java/cn/hutool/core/net/RFC3986.java → hutool-core/src/main/java/cn/hutool/core/net/url/RFC3986.java
Executable file → Normal file
2
hutool-core/src/main/java/cn/hutool/core/net/RFC3986.java → hutool-core/src/main/java/cn/hutool/core/net/url/RFC3986.java
Executable file → Normal file
@ -1,4 +1,4 @@
|
||||
package cn.hutool.core.net;
|
||||
package cn.hutool.core.net.url;
|
||||
|
||||
import cn.hutool.core.codec.PercentCodec;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.core.net;
|
||||
package cn.hutool.core.net.url;
|
||||
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.core.net;
|
||||
package cn.hutool.core.net.url;
|
||||
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.util.CharUtil;
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.core.net;
|
||||
package cn.hutool.core.net.url;
|
||||
|
||||
import cn.hutool.core.classloader.ClassLoaderUtil;
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
@ -7,7 +7,6 @@ import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.net.url.UrlQuery;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
|
@ -1,11 +1,9 @@
|
||||
package cn.hutool.core.net.url;
|
||||
|
||||
import cn.hutool.core.builder.Builder;
|
||||
import cn.hutool.core.lang.builder.Builder;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.net.RFC3986;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
@ -63,7 +61,7 @@ public final class UrlBuilder implements Builder<String> {
|
||||
* 是否需要编码`%`<br>
|
||||
* 区别对待,如果是,则生成URL时需要重新全部编码,否则跳过所有`%`
|
||||
*/
|
||||
private boolean needEncodePercent;
|
||||
private final boolean needEncodePercent;
|
||||
|
||||
/**
|
||||
* 使用URI构建UrlBuilder
|
||||
@ -119,7 +117,7 @@ public final class UrlBuilder implements Builder<String> {
|
||||
/**
|
||||
* 使用URL字符串构建UrlBuilder,默认使用UTF-8编码
|
||||
*
|
||||
* @param url URL字符串
|
||||
* @param url URL字符串
|
||||
* @return UrlBuilder
|
||||
*/
|
||||
public static UrlBuilder of(final String url) {
|
||||
@ -197,6 +195,8 @@ public final class UrlBuilder implements Builder<String> {
|
||||
*/
|
||||
public UrlBuilder() {
|
||||
this.charset = CharsetUtil.UTF_8;
|
||||
// 编码非空情况下做解码
|
||||
this.needEncodePercent = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,8 +3,6 @@ package cn.hutool.core.net.url;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.net.RFC3986;
|
||||
import cn.hutool.core.net.URLDecoder;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
|
@ -6,9 +6,6 @@ import cn.hutool.core.collection.iter.IterUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.map.TableMap;
|
||||
import cn.hutool.core.net.FormUrlencoded;
|
||||
import cn.hutool.core.net.RFC3986;
|
||||
import cn.hutool.core.net.URLDecoder;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
@ -234,7 +231,7 @@ public class UrlQuery {
|
||||
* @return URL查询字符串
|
||||
*/
|
||||
public String build(final Charset charset) {
|
||||
return build(charset, true);
|
||||
return build(charset, null != charset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,8 +6,8 @@ import cn.hutool.core.collection.iter.EnumerationIter;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.net.URLDecoder;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLDecoder;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
|
@ -6,8 +6,8 @@ import cn.hutool.core.convert.BasicType;
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.net.URLDecoder;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLDecoder;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
|
@ -268,7 +268,7 @@ public class EasyStream<T> extends AbstractEnhancedWrappedStream<T, EasyStream<T
|
||||
*
|
||||
* @author VampireAchao
|
||||
*/
|
||||
public interface Builder<T> extends Consumer<T>, cn.hutool.core.builder.Builder<EasyStream<T>> {
|
||||
public interface Builder<T> extends Consumer<T>, cn.hutool.core.lang.builder.Builder<EasyStream<T>> {
|
||||
|
||||
/**
|
||||
* Adds an element to the unwrap being built.
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.thread;
|
||||
|
||||
import cn.hutool.core.builder.Builder;
|
||||
import cn.hutool.core.lang.builder.Builder;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.thread;
|
||||
|
||||
import cn.hutool.core.builder.Builder;
|
||||
import cn.hutool.core.lang.builder.Builder;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
|
@ -25,13 +25,16 @@ import java.util.function.Predicate;
|
||||
* @author liangbaikai
|
||||
* @since 5.2.1
|
||||
*/
|
||||
public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
public class MapTree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final TreeNodeConfig treeNodeConfig;
|
||||
private Tree<T> parent;
|
||||
private MapTree<T> parent;
|
||||
|
||||
public Tree() {
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public MapTree() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
@ -40,7 +43,7 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
*
|
||||
* @param treeNodeConfig TreeNode配置
|
||||
*/
|
||||
public Tree(final TreeNodeConfig treeNodeConfig) {
|
||||
public MapTree(final TreeNodeConfig treeNodeConfig) {
|
||||
this.treeNodeConfig = ObjUtil.defaultIfNull(
|
||||
treeNodeConfig, TreeNodeConfig.DEFAULT_CONFIG);
|
||||
}
|
||||
@ -61,7 +64,7 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
* @return 父节点
|
||||
* @since 5.2.4
|
||||
*/
|
||||
public Tree<T> getParent() {
|
||||
public MapTree<T> getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@ -73,7 +76,7 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
* @return 节点
|
||||
* @since 5.2.4
|
||||
*/
|
||||
public Tree<T> getNode(final T id) {
|
||||
public MapTree<T> getNode(final T id) {
|
||||
return TreeUtil.getNode(this, id);
|
||||
}
|
||||
|
||||
@ -115,7 +118,7 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
* @return this
|
||||
* @since 5.2.4
|
||||
*/
|
||||
public Tree<T> setParent(final Tree<T> parent) {
|
||||
public MapTree<T> setParent(final MapTree<T> parent) {
|
||||
this.parent = parent;
|
||||
if (null != parent) {
|
||||
this.setParentId(parent.getId());
|
||||
@ -130,7 +133,7 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree<T> setId(final T id) {
|
||||
public MapTree<T> setId(final T id) {
|
||||
this.put(treeNodeConfig.getIdKey(), id);
|
||||
return this;
|
||||
}
|
||||
@ -142,7 +145,7 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree<T> setParentId(final T parentId) {
|
||||
public MapTree<T> setParentId(final T parentId) {
|
||||
this.put(treeNodeConfig.getParentIdKey(), parentId);
|
||||
return this;
|
||||
}
|
||||
@ -153,7 +156,7 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree<T> setName(final CharSequence name) {
|
||||
public MapTree<T> setName(final CharSequence name) {
|
||||
this.put(treeNodeConfig.getNameKey(), name);
|
||||
return this;
|
||||
}
|
||||
@ -164,7 +167,7 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree<T> setWeight(final Comparable<?> weight) {
|
||||
public MapTree<T> setWeight(final Comparable<?> weight) {
|
||||
this.put(treeNodeConfig.getWeightKey(), weight);
|
||||
return this;
|
||||
}
|
||||
@ -175,8 +178,8 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
* @return 所有子节点
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Tree<T>> getChildren() {
|
||||
return (List<Tree<T>>) this.get(treeNodeConfig.getChildrenKey());
|
||||
public List<MapTree<T>> getChildren() {
|
||||
return (List<MapTree<T>>) this.get(treeNodeConfig.getChildrenKey());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -195,7 +198,7 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
* @param consumer 节点处理器
|
||||
* @since 5.7.16
|
||||
*/
|
||||
public void walk(final Consumer<Tree<T>> consumer) {
|
||||
public void walk(final Consumer<MapTree<T>> consumer) {
|
||||
walk(consumer, false);
|
||||
}
|
||||
|
||||
@ -206,27 +209,27 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
* @param broadFirst 是否广度优先遍历
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public void walk(final Consumer<Tree<T>> consumer, final boolean broadFirst) {
|
||||
public void walk(final Consumer<MapTree<T>> consumer, final boolean broadFirst) {
|
||||
if (broadFirst) { // 广度优先遍历
|
||||
// 加入FIFO队列
|
||||
final Queue<Tree<T>> queue = new LinkedList<>();
|
||||
final Queue<MapTree<T>> queue = new LinkedList<>();
|
||||
queue.offer(this);
|
||||
while (false == queue.isEmpty()) {
|
||||
final Tree<T> node = queue.poll();
|
||||
final MapTree<T> node = queue.poll();
|
||||
consumer.accept(node);
|
||||
final List<Tree<T>> children = node.getChildren();
|
||||
final List<MapTree<T>> children = node.getChildren();
|
||||
if (CollUtil.isNotEmpty(children)) {
|
||||
children.forEach(queue::offer);
|
||||
}
|
||||
}
|
||||
} else { // 深度优先遍历
|
||||
// 入栈,FILO
|
||||
final Stack<Tree<T>> stack = new Stack<>();
|
||||
final Stack<MapTree<T>> stack = new Stack<>();
|
||||
stack.add(this);
|
||||
while (false == stack.isEmpty()) {
|
||||
final Tree<T> node = stack.pop();
|
||||
final MapTree<T> node = stack.pop();
|
||||
consumer.accept(node);
|
||||
final List<Tree<T>> children = node.getChildren();
|
||||
final List<MapTree<T>> children = node.getChildren();
|
||||
if (CollUtil.isNotEmpty(children)) {
|
||||
children.forEach(stack::push);
|
||||
}
|
||||
@ -243,7 +246,7 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
* @see #filter(Predicate)
|
||||
* @since 5.7.17
|
||||
*/
|
||||
public Tree<T> filterNew(final Predicate<Tree<T>> predicate) {
|
||||
public MapTree<T> filterNew(final Predicate<MapTree<T>> predicate) {
|
||||
return cloneTree().filter(predicate);
|
||||
}
|
||||
|
||||
@ -256,18 +259,18 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
* @see #filterNew(Predicate)
|
||||
* @since 5.7.17
|
||||
*/
|
||||
public Tree<T> filter(final Predicate<Tree<T>> predicate) {
|
||||
public MapTree<T> filter(final Predicate<MapTree<T>> predicate) {
|
||||
if (null == predicate || predicate.test(this)) {
|
||||
// 本节点满足,则包括所有子节点都保留
|
||||
return this;
|
||||
}
|
||||
|
||||
final List<Tree<T>> children = getChildren();
|
||||
final List<MapTree<T>> children = getChildren();
|
||||
if (CollUtil.isNotEmpty(children)) {
|
||||
// 递归过滤子节点
|
||||
final List<Tree<T>> filteredChildren = new ArrayList<>(children.size());
|
||||
Tree<T> filteredChild;
|
||||
for (final Tree<T> child : children) {
|
||||
final List<MapTree<T>> filteredChildren = new ArrayList<>(children.size());
|
||||
MapTree<T> filteredChild;
|
||||
for (final MapTree<T> child : children) {
|
||||
filteredChild = child.filter(predicate);
|
||||
if (null != filteredChild) {
|
||||
filteredChildren.add(filteredChild);
|
||||
@ -291,7 +294,7 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
* @param children 子节点列表,如果为{@code null}表示移除子节点
|
||||
* @return this
|
||||
*/
|
||||
public Tree<T> setChildren(final List<Tree<T>> children) {
|
||||
public MapTree<T> setChildren(final List<MapTree<T>> children) {
|
||||
if (null == children) {
|
||||
this.remove(treeNodeConfig.getChildrenKey());
|
||||
}
|
||||
@ -307,14 +310,14 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
* @since 5.6.7
|
||||
*/
|
||||
@SafeVarargs
|
||||
public final Tree<T> addChildren(final Tree<T>... children) {
|
||||
public final MapTree<T> addChildren(final MapTree<T>... children) {
|
||||
if (ArrayUtil.isNotEmpty(children)) {
|
||||
List<Tree<T>> childrenList = this.getChildren();
|
||||
List<MapTree<T>> childrenList = this.getChildren();
|
||||
if (null == childrenList) {
|
||||
childrenList = new ArrayList<>();
|
||||
setChildren(childrenList);
|
||||
}
|
||||
for (final Tree<T> child : children) {
|
||||
for (final MapTree<T> child : children) {
|
||||
child.setParent(this);
|
||||
childrenList.add(child);
|
||||
}
|
||||
@ -347,8 +350,8 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
* @return 新的节点
|
||||
* @since 5.7.17
|
||||
*/
|
||||
public Tree<T> cloneTree() {
|
||||
final Tree<T> result = ObjUtil.clone(this);
|
||||
public MapTree<T> cloneTree() {
|
||||
final MapTree<T> result = ObjUtil.clone(this);
|
||||
result.setChildren(cloneChildren());
|
||||
return result;
|
||||
}
|
||||
@ -358,12 +361,12 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
*
|
||||
* @return 新的子节点列表
|
||||
*/
|
||||
private List<Tree<T>> cloneChildren() {
|
||||
final List<Tree<T>> children = getChildren();
|
||||
private List<MapTree<T>> cloneChildren() {
|
||||
final List<MapTree<T>> children = getChildren();
|
||||
if (null == children) {
|
||||
return null;
|
||||
}
|
||||
final List<Tree<T>> newChildren = new ArrayList<>(children.size());
|
||||
final List<MapTree<T>> newChildren = new ArrayList<>(children.size());
|
||||
children.forEach((t) -> newChildren.add(t.cloneTree()));
|
||||
return newChildren;
|
||||
}
|
||||
@ -375,13 +378,13 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Node<T> {
|
||||
* @param writer Writer
|
||||
* @param intent 缩进量
|
||||
*/
|
||||
private static void printTree(final Tree<?> tree, final PrintWriter writer, final int intent) {
|
||||
private static void printTree(final MapTree<?> tree, final PrintWriter writer, final int intent) {
|
||||
writer.println(StrUtil.format("{}{}[{}]", StrUtil.repeat(CharUtil.SPACE, intent), tree.getName(), tree.getId()));
|
||||
writer.flush();
|
||||
|
||||
final List<? extends Tree<?>> children = tree.getChildren();
|
||||
final List<? extends MapTree<?>> children = tree.getChildren();
|
||||
if (CollUtil.isNotEmpty(children)) {
|
||||
for (final Tree<?> child : children) {
|
||||
for (final MapTree<?> child : children) {
|
||||
printTree(child, writer, intent + 2);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.tree;
|
||||
|
||||
import cn.hutool.core.builder.Builder;
|
||||
import cn.hutool.core.lang.builder.Builder;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.tree.parser.NodeParser;
|
||||
@ -17,11 +17,11 @@ import java.util.Map;
|
||||
*
|
||||
* @param <E> ID类型
|
||||
*/
|
||||
public class TreeBuilder<E> implements Builder<Tree<E>> {
|
||||
public class TreeBuilder<E> implements Builder<MapTree<E>> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Tree<E> root;
|
||||
private final Map<E, Tree<E>> idTreeMap;
|
||||
private final MapTree<E> root;
|
||||
private final Map<E, MapTree<E>> idTreeMap;
|
||||
private boolean isBuild;
|
||||
|
||||
/**
|
||||
@ -54,7 +54,7 @@ public class TreeBuilder<E> implements Builder<Tree<E>> {
|
||||
* @param config 配置
|
||||
*/
|
||||
public TreeBuilder(final E rootId, final TreeNodeConfig config) {
|
||||
root = new Tree<>(config);
|
||||
root = new MapTree<>(config);
|
||||
root.setId(rootId);
|
||||
this.idTreeMap = new HashMap<>();
|
||||
}
|
||||
@ -127,7 +127,7 @@ public class TreeBuilder<E> implements Builder<Tree<E>> {
|
||||
* @param map 节点列表
|
||||
* @return this
|
||||
*/
|
||||
public TreeBuilder<E> append(final Map<E, Tree<E>> map) {
|
||||
public TreeBuilder<E> append(final Map<E, MapTree<E>> map) {
|
||||
checkBuilt();
|
||||
|
||||
this.idTreeMap.putAll(map);
|
||||
@ -140,10 +140,10 @@ public class TreeBuilder<E> implements Builder<Tree<E>> {
|
||||
* @param trees 节点列表
|
||||
* @return this
|
||||
*/
|
||||
public TreeBuilder<E> append(final Iterable<Tree<E>> trees) {
|
||||
public TreeBuilder<E> append(final Iterable<MapTree<E>> trees) {
|
||||
checkBuilt();
|
||||
|
||||
for (final Tree<E> tree : trees) {
|
||||
for (final MapTree<E> tree : trees) {
|
||||
this.idTreeMap.put(tree.getId(), tree);
|
||||
}
|
||||
return this;
|
||||
@ -161,10 +161,10 @@ public class TreeBuilder<E> implements Builder<Tree<E>> {
|
||||
checkBuilt();
|
||||
|
||||
final TreeNodeConfig config = this.root.getConfig();
|
||||
final Map<E, Tree<E>> map = new LinkedHashMap<>(list.size(), 1);
|
||||
Tree<E> node;
|
||||
final Map<E, MapTree<E>> map = new LinkedHashMap<>(list.size(), 1);
|
||||
MapTree<E> node;
|
||||
for (final T t : list) {
|
||||
node = new Tree<>(config);
|
||||
node = new MapTree<>(config);
|
||||
nodeParser.parse(t, node);
|
||||
map.put(node.getId(), node);
|
||||
}
|
||||
@ -185,7 +185,7 @@ public class TreeBuilder<E> implements Builder<Tree<E>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree<E> build() {
|
||||
public MapTree<E> build() {
|
||||
checkBuilt();
|
||||
|
||||
buildFromMap();
|
||||
@ -211,7 +211,7 @@ public class TreeBuilder<E> implements Builder<Tree<E>> {
|
||||
*
|
||||
* @return 树列表
|
||||
*/
|
||||
public List<Tree<E>> buildList() {
|
||||
public List<MapTree<E>> buildList() {
|
||||
if (isBuild) {
|
||||
// 已经构建过了
|
||||
return this.root.getChildren();
|
||||
@ -227,9 +227,9 @@ public class TreeBuilder<E> implements Builder<Tree<E>> {
|
||||
return;
|
||||
}
|
||||
|
||||
final Map<E, Tree<E>> eTreeMap = MapUtil.sortByValue(this.idTreeMap, false);
|
||||
final Map<E, MapTree<E>> eTreeMap = MapUtil.sortByValue(this.idTreeMap, false);
|
||||
E parentId;
|
||||
for (final Tree<E> node : eTreeMap.values()) {
|
||||
for (final MapTree<E> node : eTreeMap.values()) {
|
||||
if (null == node) {
|
||||
continue;
|
||||
}
|
||||
@ -239,7 +239,7 @@ public class TreeBuilder<E> implements Builder<Tree<E>> {
|
||||
continue;
|
||||
}
|
||||
|
||||
final Tree<E> parentNode = eTreeMap.get(parentId);
|
||||
final MapTree<E> parentNode = eTreeMap.get(parentId);
|
||||
if (null != parentNode) {
|
||||
parentNode.addChildren(node);
|
||||
}
|
||||
@ -265,7 +265,7 @@ public class TreeBuilder<E> implements Builder<Tree<E>> {
|
||||
* @param currentDepp 当前层级
|
||||
* @param maxDeep 最大层级
|
||||
*/
|
||||
private void cutTree(final Tree<E> tree, final int currentDepp, final int maxDeep) {
|
||||
private void cutTree(final MapTree<E> tree, final int currentDepp, final int maxDeep) {
|
||||
if (null == tree) {
|
||||
return;
|
||||
}
|
||||
@ -275,9 +275,9 @@ public class TreeBuilder<E> implements Builder<Tree<E>> {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Tree<E>> children = tree.getChildren();
|
||||
final List<MapTree<E>> children = tree.getChildren();
|
||||
if (CollUtil.isNotEmpty(children)) {
|
||||
for (final Tree<E> child : children) {
|
||||
for (final MapTree<E> child : children) {
|
||||
cutTree(child, currentDepp + 1, maxDeep);
|
||||
}
|
||||
}
|
||||
|
@ -21,10 +21,10 @@ public class TreeUtil {
|
||||
* 构建单root节点树
|
||||
*
|
||||
* @param list 源数据集合
|
||||
* @return {@link Tree}
|
||||
* @return {@link MapTree}
|
||||
* @since 5.7.2
|
||||
*/
|
||||
public static Tree<Integer> buildSingle(final List<TreeNode<Integer>> list) {
|
||||
public static MapTree<Integer> buildSingle(final List<TreeNode<Integer>> list) {
|
||||
return buildSingle(list, 0);
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ public class TreeUtil {
|
||||
* @param list 源数据集合
|
||||
* @return List
|
||||
*/
|
||||
public static List<Tree<Integer>> build(final List<TreeNode<Integer>> list) {
|
||||
public static List<MapTree<Integer>> build(final List<TreeNode<Integer>> list) {
|
||||
return build(list, 0);
|
||||
}
|
||||
|
||||
@ -45,10 +45,10 @@ public class TreeUtil {
|
||||
* @param <E> ID类型
|
||||
* @param list 源数据集合
|
||||
* @param parentId 最顶层父id值 一般为 0 之类
|
||||
* @return {@link Tree}
|
||||
* @return {@link MapTree}
|
||||
* @since 5.7.2
|
||||
*/
|
||||
public static <E> Tree<E> buildSingle(final List<TreeNode<E>> list, final E parentId) {
|
||||
public static <E> MapTree<E> buildSingle(final List<TreeNode<E>> list, final E parentId) {
|
||||
return buildSingle(list, parentId, TreeNodeConfig.DEFAULT_CONFIG, new DefaultNodeParser<>());
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ public class TreeUtil {
|
||||
* @param parentId 最顶层父id值 一般为 0 之类
|
||||
* @return List
|
||||
*/
|
||||
public static <E> List<Tree<E>> build(final List<TreeNode<E>> list, final E parentId) {
|
||||
public static <E> List<MapTree<E>> build(final List<TreeNode<E>> list, final E parentId) {
|
||||
return build(list, parentId, TreeNodeConfig.DEFAULT_CONFIG, new DefaultNodeParser<>());
|
||||
}
|
||||
|
||||
@ -73,10 +73,10 @@ public class TreeUtil {
|
||||
* @param list 源数据集合
|
||||
* @param parentId 最顶层父id值 一般为 0 之类
|
||||
* @param nodeParser 转换器
|
||||
* @return {@link Tree}
|
||||
* @return {@link MapTree}
|
||||
* @since 5.7.2
|
||||
*/
|
||||
public static <T, E> Tree<E> buildSingle(final List<T> list, final E parentId, final NodeParser<T, E> nodeParser) {
|
||||
public static <T, E> MapTree<E> buildSingle(final List<T> list, final E parentId, final NodeParser<T, E> nodeParser) {
|
||||
return buildSingle(list, parentId, TreeNodeConfig.DEFAULT_CONFIG, nodeParser);
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ public class TreeUtil {
|
||||
* @param nodeParser 转换器
|
||||
* @return List
|
||||
*/
|
||||
public static <T, E> List<Tree<E>> build(final List<T> list, final E parentId, final NodeParser<T, E> nodeParser) {
|
||||
public static <T, E> List<MapTree<E>> build(final List<T> list, final E parentId, final NodeParser<T, E> nodeParser) {
|
||||
return build(list, parentId, TreeNodeConfig.DEFAULT_CONFIG, nodeParser);
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ public class TreeUtil {
|
||||
* @param nodeParser 转换器
|
||||
* @return List
|
||||
*/
|
||||
public static <T, E> List<Tree<E>> build(final List<T> list, final E rootId, final TreeNodeConfig treeNodeConfig, final NodeParser<T, E> nodeParser) {
|
||||
public static <T, E> List<MapTree<E>> build(final List<T> list, final E rootId, final TreeNodeConfig treeNodeConfig, final NodeParser<T, E> nodeParser) {
|
||||
return buildSingle(list, rootId, treeNodeConfig, nodeParser).getChildren();
|
||||
}
|
||||
|
||||
@ -119,10 +119,10 @@ public class TreeUtil {
|
||||
* @param rootId 最顶层父id值 一般为 0 之类
|
||||
* @param treeNodeConfig 配置
|
||||
* @param nodeParser 转换器
|
||||
* @return {@link Tree}
|
||||
* @return {@link MapTree}
|
||||
* @since 5.7.2
|
||||
*/
|
||||
public static <T, E> Tree<E> buildSingle(final List<T> list, final E rootId, final TreeNodeConfig treeNodeConfig, final NodeParser<T, E> nodeParser) {
|
||||
public static <T, E> MapTree<E> buildSingle(final List<T> list, final E rootId, final TreeNodeConfig treeNodeConfig, final NodeParser<T, E> nodeParser) {
|
||||
return TreeBuilder.of(rootId, treeNodeConfig)
|
||||
.append(list, nodeParser).build();
|
||||
}
|
||||
@ -136,7 +136,7 @@ public class TreeUtil {
|
||||
* @return List
|
||||
* @since 5.6.7
|
||||
*/
|
||||
public static <E> List<Tree<E>> build(final Map<E, Tree<E>> map, final E rootId) {
|
||||
public static <E> List<MapTree<E>> build(final Map<E, MapTree<E>> map, final E rootId) {
|
||||
return buildSingle(map, rootId).getChildren();
|
||||
}
|
||||
|
||||
@ -147,11 +147,11 @@ public class TreeUtil {
|
||||
* @param <E> ID类型
|
||||
* @param map 源数据Map
|
||||
* @param rootId 根节点id值 一般为 0 之类
|
||||
* @return {@link Tree}
|
||||
* @return {@link MapTree}
|
||||
* @since 5.7.2
|
||||
*/
|
||||
public static <E> Tree<E> buildSingle(final Map<E, Tree<E>> map, final E rootId) {
|
||||
final Tree<E> tree = CollUtil.getFirstNoneNull(map.values());
|
||||
public static <E> MapTree<E> buildSingle(final Map<E, MapTree<E>> map, final E rootId) {
|
||||
final MapTree<E> tree = CollUtil.getFirstNoneNull(map.values());
|
||||
if (null != tree) {
|
||||
final TreeNodeConfig config = tree.getConfig();
|
||||
return TreeBuilder.of(rootId, config)
|
||||
@ -172,19 +172,19 @@ public class TreeUtil {
|
||||
* @return 节点
|
||||
* @since 5.2.4
|
||||
*/
|
||||
public static <T> Tree<T> getNode(final Tree<T> node, final T id) {
|
||||
public static <T> MapTree<T> getNode(final MapTree<T> node, final T id) {
|
||||
if (ObjUtil.equals(id, node.getId())) {
|
||||
return node;
|
||||
}
|
||||
|
||||
final List<Tree<T>> children = node.getChildren();
|
||||
final List<MapTree<T>> children = node.getChildren();
|
||||
if (null == children) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 查找子节点
|
||||
Tree<T> childNode;
|
||||
for (final Tree<T> child : children) {
|
||||
MapTree<T> childNode;
|
||||
for (final MapTree<T> child : children) {
|
||||
childNode = child.getNode(id);
|
||||
if (null != childNode) {
|
||||
return childNode;
|
||||
@ -208,7 +208,7 @@ public class TreeUtil {
|
||||
* @return 所有父节点名称列表,node为null返回空List
|
||||
* @since 5.2.4
|
||||
*/
|
||||
public static <T> List<CharSequence> getParentsName(final Tree<T> node, final boolean includeCurrentNode) {
|
||||
public static <T> List<CharSequence> getParentsName(final MapTree<T> node, final boolean includeCurrentNode) {
|
||||
final List<CharSequence> result = new ArrayList<>();
|
||||
if (null == node) {
|
||||
return result;
|
||||
@ -218,7 +218,7 @@ public class TreeUtil {
|
||||
result.add(node.getName());
|
||||
}
|
||||
|
||||
Tree<T> parent = node.getParent();
|
||||
MapTree<T> parent = node.getParent();
|
||||
while (null != parent) {
|
||||
result.add(parent.getName());
|
||||
parent = parent.getParent();
|
||||
@ -231,11 +231,11 @@ public class TreeUtil {
|
||||
*
|
||||
* @param id 节点ID
|
||||
* @param <E> 节点ID类型
|
||||
* @return {@link Tree}
|
||||
* @return {@link MapTree}
|
||||
* @since 5.7.2
|
||||
*/
|
||||
public static <E> Tree<E> createEmptyNode(final E id) {
|
||||
return new Tree<E>().setId(id);
|
||||
public static <E> MapTree<E> createEmptyNode(final E id) {
|
||||
return new MapTree<E>().setId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -246,11 +246,11 @@ public class TreeUtil {
|
||||
* @param <E> 节点ID类型
|
||||
* @return 树所有节点列表
|
||||
*/
|
||||
public static <E> List<Tree<E>> toList(final Tree<E> root, final boolean broadFirst) {
|
||||
public static <E> List<MapTree<E>> toList(final MapTree<E> root, final boolean broadFirst) {
|
||||
if (Objects.isNull(root)) {
|
||||
return null;
|
||||
}
|
||||
final List<Tree<E>> list = new ArrayList<>();
|
||||
final List<MapTree<E>> list = new ArrayList<>();
|
||||
root.walk(list::add, broadFirst);
|
||||
|
||||
return list;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.hutool.core.tree.parser;
|
||||
|
||||
import cn.hutool.core.tree.TreeNode;
|
||||
import cn.hutool.core.tree.Tree;
|
||||
import cn.hutool.core.tree.MapTree;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
|
||||
import java.util.Map;
|
||||
@ -15,7 +15,7 @@ import java.util.Map;
|
||||
public class DefaultNodeParser<T> implements NodeParser<TreeNode<T>, T> {
|
||||
|
||||
@Override
|
||||
public void parse(final TreeNode<T> treeNode, final Tree<T> tree) {
|
||||
public void parse(final TreeNode<T> treeNode, final MapTree<T> tree) {
|
||||
tree.setId(treeNode.getId());
|
||||
tree.setParentId(treeNode.getParentId());
|
||||
tree.setWeight(treeNode.getWeight());
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.tree.parser;
|
||||
|
||||
import cn.hutool.core.tree.Tree;
|
||||
import cn.hutool.core.tree.MapTree;
|
||||
|
||||
/**
|
||||
* 树节点解析器 可以参考{@link DefaultNodeParser}
|
||||
@ -14,6 +14,6 @@ public interface NodeParser<T, E> {
|
||||
* @param object 源数据实体
|
||||
* @param treeNode 树节点实体
|
||||
*/
|
||||
void parse(T object, Tree<E> treeNode);
|
||||
void parse(T object, MapTree<E> treeNode);
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,9 @@ import java.util.concurrent.atomic.LongAdder;
|
||||
*/
|
||||
public class ByteUtil {
|
||||
|
||||
/**
|
||||
* 默认字节序:大端在前,小端在后
|
||||
*/
|
||||
public static final ByteOrder DEFAULT_ORDER = ByteOrder.LITTLE_ENDIAN;
|
||||
/**
|
||||
* CPU的字节序
|
||||
|
@ -25,6 +25,9 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class CreditCodeUtil {
|
||||
|
||||
/**
|
||||
* 统一社会信用代码正则
|
||||
*/
|
||||
public static final Pattern CREDIT_CODE_PATTERN = PatternPool.CREDIT_CODE;
|
||||
|
||||
/**
|
||||
|
@ -174,7 +174,7 @@ public class PageUtil {
|
||||
* @param pageSize 每页数
|
||||
* @return 总页数
|
||||
*/
|
||||
public static int totalPage(int totalCount, int pageSize) {
|
||||
public static int totalPage(final int totalCount, final int pageSize) {
|
||||
return totalPage((long) totalCount, pageSize);
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ public class PageUtil {
|
||||
* @return 总页数
|
||||
* @since 5.8.5
|
||||
*/
|
||||
public static int totalPage(long totalCount, int pageSize) {
|
||||
public static int totalPage(final long totalCount, final int pageSize) {
|
||||
if (pageSize == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -1487,7 +1487,6 @@ public class XmlUtil {
|
||||
*/
|
||||
private void examineNode(final Node node, final boolean attributesOnly) {
|
||||
final NamedNodeMap attributes = node.getAttributes();
|
||||
//noinspection ConstantConditions
|
||||
if (null != attributes) {
|
||||
final int length = attributes.getLength();
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.builder;
|
||||
|
||||
import cn.hutool.core.lang.builder.GenericBuilder;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.lang;
|
||||
|
||||
import cn.hutool.core.builder.GenericBuilder;
|
||||
import cn.hutool.core.lang.builder.GenericBuilder;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.map.Dict;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.net;
|
||||
|
||||
import cn.hutool.core.net.url.FormUrlencoded;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.net;
|
||||
|
||||
import cn.hutool.core.net.url.RFC3986;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package cn.hutool.core.net;
|
||||
|
||||
import cn.hutool.core.net.url.URLDecoder;
|
||||
import cn.hutool.core.net.url.URLEncoder;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.net;
|
||||
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.net;
|
||||
|
||||
import cn.hutool.core.net.url.URLDecoder;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.net;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
import cn.hutool.core.net.url.UrlQuery;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
|
@ -19,7 +19,7 @@ public class Issue2279Test {
|
||||
new TestTree(4, 2, 4, 4)
|
||||
);
|
||||
|
||||
final List<Tree<String>> stringTree = TreeUtil.build(list, "0",
|
||||
final List<MapTree<String>> stringTree = TreeUtil.build(list, "0",
|
||||
(object, treeNode) -> {
|
||||
treeNode.setId(object.getId());
|
||||
treeNode.setName(object.getName());
|
||||
@ -28,7 +28,7 @@ public class Issue2279Test {
|
||||
}
|
||||
);
|
||||
|
||||
final Tree<String> result = stringTree.get(0);
|
||||
final MapTree<String> result = stringTree.get(0);
|
||||
Assert.assertEquals(2, result.getChildren().size());
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,5 @@
|
||||
package cn.hutool.core.tree;
|
||||
|
||||
import cn.hutool.core.tree.Tree;
|
||||
import cn.hutool.core.tree.TreeNode;
|
||||
import cn.hutool.core.tree.TreeUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -30,10 +27,10 @@ public class TreeSearchTest {
|
||||
|
||||
@Test
|
||||
public void searchNode() {
|
||||
final List<Tree<Long>> treeItems= TreeUtil.build(all_menu, 0L);
|
||||
final List<MapTree<Long>> treeItems= TreeUtil.build(all_menu, 0L);
|
||||
|
||||
final Tree<Long> tree=treeItems.get(0);
|
||||
final Tree<Long> searchResult=tree.getNode(3L);
|
||||
final MapTree<Long> tree=treeItems.get(0);
|
||||
final MapTree<Long> searchResult=tree.getNode(3L);
|
||||
|
||||
Assert.assertEquals("module-B", searchResult.getName());
|
||||
}
|
||||
|
@ -31,16 +31,16 @@ public class TreeTest {
|
||||
|
||||
@Test
|
||||
public void sampleTreeTest() {
|
||||
final List<Tree<String>> treeList = TreeUtil.build(nodeList, "0");
|
||||
for (final Tree<String> tree : treeList) {
|
||||
final List<MapTree<String>> treeList = TreeUtil.build(nodeList, "0");
|
||||
for (final MapTree<String> tree : treeList) {
|
||||
Assert.assertNotNull(tree);
|
||||
Assert.assertEquals("0", tree.getParentId());
|
||||
// Console.log(tree);
|
||||
}
|
||||
|
||||
// 测试通过子节点查找父节点
|
||||
final Tree<String> rootNode0 = treeList.get(0);
|
||||
final Tree<String> parent = rootNode0.getChildren().get(0).getParent();
|
||||
final MapTree<String> rootNode0 = treeList.get(0);
|
||||
final MapTree<String> parent = rootNode0.getChildren().get(0).getParent();
|
||||
Assert.assertEquals(rootNode0, parent);
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ public class TreeTest {
|
||||
treeNodeConfig.setDeep(2);
|
||||
|
||||
//转换器
|
||||
final List<Tree<String>> treeNodes = TreeUtil.build(nodeList, "0", treeNodeConfig,
|
||||
final List<MapTree<String>> treeNodes = TreeUtil.build(nodeList, "0", treeNodeConfig,
|
||||
(treeNode, tree) -> {
|
||||
tree.setId(treeNode.getId());
|
||||
tree.setParentId(treeNode.getParentId());
|
||||
@ -72,7 +72,7 @@ public class TreeTest {
|
||||
@Test
|
||||
public void walkTest(){
|
||||
final List<String> ids = new ArrayList<>();
|
||||
final Tree<String> tree = TreeUtil.buildSingle(nodeList, "0");
|
||||
final MapTree<String> tree = TreeUtil.buildSingle(nodeList, "0");
|
||||
tree.walk((tr)-> ids.add(tr.getId()));
|
||||
|
||||
Assert .assertEquals(7, ids.size());
|
||||
@ -81,7 +81,7 @@ public class TreeTest {
|
||||
@Test
|
||||
public void walkBroadFirstTest(){
|
||||
final List<String> ids = new ArrayList<>();
|
||||
final Tree<String> tree = TreeUtil.buildSingle(nodeList, "0");
|
||||
final MapTree<String> tree = TreeUtil.buildSingle(nodeList, "0");
|
||||
Console.log(tree);
|
||||
tree.walk((tr)-> ids.add(tr.getId()), true);
|
||||
|
||||
@ -91,8 +91,8 @@ public class TreeTest {
|
||||
|
||||
@Test
|
||||
public void cloneTreeTest(){
|
||||
final Tree<String> tree = TreeUtil.buildSingle(nodeList, "0");
|
||||
final Tree<String> cloneTree = tree.cloneTree();
|
||||
final MapTree<String> tree = TreeUtil.buildSingle(nodeList, "0");
|
||||
final MapTree<String> cloneTree = tree.cloneTree();
|
||||
|
||||
final List<String> ids = new ArrayList<>();
|
||||
cloneTree.walk((tr)-> ids.add(tr.getId()));
|
||||
@ -103,7 +103,7 @@ public class TreeTest {
|
||||
@Test
|
||||
public void filterTest(){
|
||||
// 经过过滤,丢掉"用户添加"节点
|
||||
final Tree<String> tree = TreeUtil.buildSingle(nodeList, "0");
|
||||
final MapTree<String> tree = TreeUtil.buildSingle(nodeList, "0");
|
||||
tree.filter((t)->{
|
||||
final CharSequence name = t.getName();
|
||||
return null != name && name.toString().contains("店铺");
|
||||
@ -116,10 +116,10 @@ public class TreeTest {
|
||||
|
||||
@Test
|
||||
public void filterNewTest(){
|
||||
final Tree<String> tree = TreeUtil.buildSingle(nodeList, "0");
|
||||
final MapTree<String> tree = TreeUtil.buildSingle(nodeList, "0");
|
||||
|
||||
// 经过过滤,生成新的树
|
||||
final Tree<String> newTree = tree.filterNew((t)->{
|
||||
final MapTree<String> newTree = tree.filterNew((t)->{
|
||||
final CharSequence name = t.getName();
|
||||
return null != name && name.toString().contains("店铺");
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.hutool.cron.pattern;
|
||||
|
||||
import cn.hutool.core.builder.Builder;
|
||||
import cn.hutool.core.lang.builder.Builder;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.text.StrJoiner;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import cn.hutool.core.builder.Builder;
|
||||
import cn.hutool.core.lang.builder.Builder;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import cn.hutool.core.builder.Builder;
|
||||
import cn.hutool.core.lang.builder.Builder;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.hutool.extra.mail;
|
||||
|
||||
import cn.hutool.core.builder.Builder;
|
||||
import cn.hutool.core.lang.builder.Builder;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
|
@ -11,7 +11,7 @@ import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.map.CaseInsensitiveMap;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.net.NetUtil;
|
||||
import cn.hutool.core.net.URLEncoder;
|
||||
import cn.hutool.core.net.url.URLEncoder;
|
||||
import cn.hutool.core.net.multipart.MultipartFormData;
|
||||
import cn.hutool.core.net.multipart.UploadSetting;
|
||||
import cn.hutool.core.reflect.ConstructorUtil;
|
||||
|
@ -11,7 +11,7 @@ import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.map.CaseInsensitiveMap;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.net.NetUtil;
|
||||
import cn.hutool.core.net.URLEncoder;
|
||||
import cn.hutool.core.net.url.URLEncoder;
|
||||
import cn.hutool.core.net.multipart.MultipartFormData;
|
||||
import cn.hutool.core.net.multipart.UploadSetting;
|
||||
import cn.hutool.core.reflect.ConstructorUtil;
|
||||
|
@ -3,7 +3,7 @@ package cn.hutool.extra.ssh;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.net.LocalPortGenerater;
|
||||
import cn.hutool.core.net.LocalPortGenerator;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import com.jcraft.jsch.*;
|
||||
@ -31,7 +31,7 @@ public class JschUtil {
|
||||
/**
|
||||
* 本地端口生成器
|
||||
*/
|
||||
private static final LocalPortGenerater portGenerater = new LocalPortGenerater(10000);
|
||||
private static final LocalPortGenerator portGenerater = new LocalPortGenerator(10000);
|
||||
|
||||
/**
|
||||
* 生成一个本地端口,用于远程端口映射
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.net.SSLUtil;
|
||||
import cn.hutool.core.net.ssl.SSLUtil;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
import cn.hutool.core.reflect.FieldUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
|
@ -10,12 +10,12 @@ import cn.hutool.core.io.resource.Resource;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.map.TableMap;
|
||||
import cn.hutool.core.net.SSLUtil;
|
||||
import cn.hutool.core.net.ssl.SSLUtil;
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
import cn.hutool.core.net.url.UrlQuery;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.http.body.BytesBody;
|
||||
import cn.hutool.http.body.FormUrlEncodedBody;
|
||||
import cn.hutool.http.body.MultipartBody;
|
||||
|
@ -7,7 +7,7 @@ import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.StreamProgress;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.net.URLEncoder;
|
||||
import cn.hutool.core.net.url.URLEncoder;
|
||||
import cn.hutool.core.regex.ReUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.http.cookie.GlobalCookieManager;
|
||||
|
@ -6,8 +6,8 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.StreamProgress;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.net.RFC3986;
|
||||
import cn.hutool.core.net.URLEncoder;
|
||||
import cn.hutool.core.net.url.RFC3986;
|
||||
import cn.hutool.core.net.url.URLEncoder;
|
||||
import cn.hutool.core.net.url.UrlQuery;
|
||||
import cn.hutool.core.regex.ReUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
@ -2,7 +2,7 @@ package cn.hutool.http.cookie;
|
||||
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
import cn.hutool.http.HttpConnection;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -3,7 +3,7 @@ package cn.hutool.http.server;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.net.URLEncoder;
|
||||
import cn.hutool.core.net.url.URLEncoder;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.http.ContentType;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.hutool.http.ssl;
|
||||
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.net.SSLProtocols;
|
||||
import cn.hutool.core.net.ssl.SSLProtocols;
|
||||
|
||||
/**
|
||||
* 兼容android低版本SSL连接<br>
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.hutool.http.ssl;
|
||||
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.net.SSLUtil;
|
||||
import cn.hutool.core.net.ssl.SSLUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
|
||||
import javax.net.ssl.SSLSocket;
|
||||
|
@ -3,7 +3,7 @@ package cn.hutool.http;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.StopWatch;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.net.SSLProtocols;
|
||||
import cn.hutool.core.net.ssl.SSLProtocols;
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import org.junit.Ignore;
|
||||
|
@ -0,0 +1,13 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IssueI5TFPUTest {
|
||||
@Test
|
||||
public void urlBuilderTest() {
|
||||
final UrlBuilder urlBuilder = UrlBuilder.of("https://hutool.cn", null).addQuery("opt", "%");
|
||||
Assert.assertEquals("https://hutool.cn?opt=%", urlBuilder.toString());
|
||||
}
|
||||
}
|
@ -178,7 +178,7 @@ public interface JSON extends Converter, Cloneable, Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
default Object convert(Type targetType, Object value) throws ConvertException {
|
||||
default Object convert(final Type targetType, final Object value) throws ConvertException {
|
||||
return JSONConverter.of(getConfig()).convert(targetType, value);
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,9 @@
|
||||
* </ul>
|
||||
* JSON封装主要包括JSON表示和JSON转换:
|
||||
*
|
||||
* <pre>
|
||||
* Java对象 <----> JSON对象 <----> JSON字符串
|
||||
* </pre>
|
||||
* <pre>{@code
|
||||
* Java对象 <----> JSON对象 <----> JSON字符串
|
||||
* }</pre>
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
|
@ -13,7 +13,7 @@ import cn.hutool.core.map.SafeConcurrentHashMap;
|
||||
import cn.hutool.core.map.TableMap;
|
||||
import cn.hutool.core.map.multi.RowKeyTable;
|
||||
import cn.hutool.core.map.multi.Table;
|
||||
import cn.hutool.core.net.URLEncoder;
|
||||
import cn.hutool.core.net.url.URLEncoder;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.poi.excel.cell.CellLocation;
|
||||
|
@ -3,7 +3,7 @@ package cn.hutool.setting;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
|
Loading…
x
Reference in New Issue
Block a user