This commit is contained in:
Looly 2022-09-22 03:33:30 +08:00
parent d959f3a24f
commit ba5f1f5264
40 changed files with 143 additions and 235 deletions

View File

@ -19,7 +19,7 @@ import java.util.stream.Stream;
* 并将其包装为{@link MetaAnnotatedElement} <br> * 并将其包装为{@link MetaAnnotatedElement} <br>
* eg: <br> * eg: <br>
* 若存在元素<em>A</em>有对应父类与父接口<em>B</em><em>C</em> * 若存在元素<em>A</em>有对应父类与父接口<em>B</em><em>C</em>
* 则根据<em>A</em>生成的{@link HierarchicalAnnotatedElements}实例将同时包含<em>A</em><em>B</em><em>C</em>, * 则根据<em>A</em>生成的{@code HierarchicalAnnotatedElements}实例将同时包含<em>A</em><em>B</em><em>C</em>,
* 该实例同时支持对这三个实例上直接声明的注解以及这些注解的元注解进行访问 * 该实例同时支持对这三个实例上直接声明的注解以及这些注解的元注解进行访问
* *
* <p><strong>注解搜索范围</strong> * <p><strong>注解搜索范围</strong>
@ -32,7 +32,7 @@ import java.util.stream.Stream;
* <li>被保存的所有{@link AnnotatedElement}上直接声明的注解及这些注解的元注解</li> * <li>被保存的所有{@link AnnotatedElement}上直接声明的注解及这些注解的元注解</li>
* <li>若是类则包括其所有父类和所有父接口上声明的注解和元注解</li> * <li>若是类则包括其所有父类和所有父接口上声明的注解和元注解</li>
* <li> * <li>
* 若是方法且不是静态/私有/<code>final</code>修饰的方法时 * 若是方法且不是静态/私有/{@code final}修饰的方法时
* 则额外获取包括其声明类的所有父类和所有父接口中与该方法具有相同方法签名的方法上的注解和元注解 * 则额外获取包括其声明类的所有父类和所有父接口中与该方法具有相同方法签名的方法上的注解和元注解
* </li> * </li>
* </ol> * </ol>
@ -69,9 +69,9 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
/** /**
* 创建一个分层注解元素 * 创建一个分层注解元素
* *
* @param element 被包装的元素若元素已是{@link HierarchicalAnnotatedElements}则返回其本身 * @param element 被包装的元素若元素已是{@code HierarchicalAnnotatedElements}则返回其本身
* @return {@link HierarchicalAnnotatedElements}实例 * @return {@code HierarchicalAnnotatedElements}实例
* {@code element}也是一个{@link HierarchicalAnnotatedElements}返回{@code element}本身 * {@code element}也是一个{@code HierarchicalAnnotatedElements}返回{@code element}本身
*/ */
public static HierarchicalAnnotatedElements create(final AnnotatedElement element) { public static HierarchicalAnnotatedElements create(final AnnotatedElement element) {
return create(element, (es, e) -> e); return create(element, (es, e) -> e);
@ -80,10 +80,10 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
/** /**
* 创建一个分层注解元素 * 创建一个分层注解元素
* *
* @param element 被包装的元素若元素已是{@link HierarchicalAnnotatedElements}则返回其本身 * @param element 被包装的元素若元素已是{@code HierarchicalAnnotatedElements}则返回其本身
* @param elementFactory 创建{@link AnnotatedElement}的工厂方法当返回{@code null}时将忽略该元素 * @param elementFactory 创建{@link AnnotatedElement}的工厂方法当返回{@code null}时将忽略该元素
* @return {@link HierarchicalAnnotatedElements}实例 * @return {@code HierarchicalAnnotatedElements}实例
* {@code element}也是一个{@link HierarchicalAnnotatedElements}返回{@code element}本身 * {@code element}也是一个{@code HierarchicalAnnotatedElements}返回{@code element}本身
*/ */
public static HierarchicalAnnotatedElements create( public static HierarchicalAnnotatedElements create(
final AnnotatedElement element, final AnnotatedElement element,
@ -156,8 +156,6 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
* @param <A> 注解类型 * @param <A> 注解类型
* @return 注解对象 * @return 注解对象
*/ */
@SuppressWarnings("unchecked")
@Override
public <A extends Annotation> A[] getAnnotationsByType(final Class<A> annotationType) { public <A extends Annotation> A[] getAnnotationsByType(final Class<A> annotationType) {
return getElementMappings().stream() return getElementMappings().stream()
.map(e -> e.getAnnotationsByType(annotationType)) .map(e -> e.getAnnotationsByType(annotationType))
@ -239,14 +237,14 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
* @return 是否 * @return 是否
*/ */
@Override @Override
public boolean equals(Object o) { public boolean equals(final Object o) {
if (this == o) { if (this == o) {
return true; return true;
} }
if (o == null || getClass() != o.getClass()) { if (o == null || getClass() != o.getClass()) {
return false; return false;
} }
HierarchicalAnnotatedElements that = (HierarchicalAnnotatedElements)o; final HierarchicalAnnotatedElements that = (HierarchicalAnnotatedElements)o;
return elementFactory.equals(that.elementFactory) && source.equals(that.source); return elementFactory.equals(that.elementFactory) && source.equals(that.source);
} }
@ -294,8 +292,8 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
/** /**
* 将元素转为{@link MetaAnnotatedElement}后添加至{@code mappings} * 将元素转为{@link MetaAnnotatedElement}后添加至{@code mappings}
*/ */
private void collectElement(Set<AnnotatedElement> elements, final AnnotatedElement element) { private void collectElement(final Set<AnnotatedElement> elements, final AnnotatedElement element) {
AnnotatedElement target = elementFactory.apply(elements, element); final AnnotatedElement target = elementFactory.apply(elements, element);
if (Objects.nonNull(target)) { if (Objects.nonNull(target)) {
elements.add(target); elements.add(target);
} }
@ -309,7 +307,7 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
if (Objects.isNull(elementMappings)) { if (Objects.isNull(elementMappings)) {
synchronized (this) { synchronized (this) {
if (Objects.isNull(elementMappings)) { if (Objects.isNull(elementMappings)) {
Set<AnnotatedElement> mappings = initElementMappings(); final Set<AnnotatedElement> mappings = initElementMappings();
elementMappings = Collections.unmodifiableSet(mappings); elementMappings = Collections.unmodifiableSet(mappings);
} }
} }
@ -320,7 +318,7 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
* 遍历层级结构获取层级结构中所有关联的{@link AnnotatedElement}并添加到{@link #elementMappings} * 遍历层级结构获取层级结构中所有关联的{@link AnnotatedElement}并添加到{@link #elementMappings}
*/ */
private Set<AnnotatedElement> initElementMappings() { private Set<AnnotatedElement> initElementMappings() {
Set<AnnotatedElement> mappings = new LinkedHashSet<>(); final Set<AnnotatedElement> mappings = new LinkedHashSet<>();
// 原始元素是类 // 原始元素是类
if (source instanceof Class) { if (source instanceof Class) {
scanHierarchy(mappings, (Class<?>)source, false, source); scanHierarchy(mappings, (Class<?>)source, false, source);
@ -344,8 +342,8 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
* 按广度优先遍历{@code type}的父类以及父接口并从类上/类中指定方法上获得所需的注解 * 按广度优先遍历{@code type}的父类以及父接口并从类上/类中指定方法上获得所需的注解
*/ */
private void scanHierarchy( private void scanHierarchy(
Set<AnnotatedElement> mappings, Class<?> type, final boolean isMethod, final AnnotatedElement source) { final Set<AnnotatedElement> mappings, Class<?> type, final boolean isMethod, final AnnotatedElement source) {
Method methodSource = isMethod ? (Method)source : null; final Method methodSource = isMethod ? (Method)source : null;
final Deque<Class<?>> deque = new LinkedList<>(); final Deque<Class<?>> deque = new LinkedList<>();
deque.addLast(type); deque.addLast(type);
final Set<Class<?>> accessed = new HashSet<>(); final Set<Class<?>> accessed = new HashSet<>();
@ -379,7 +377,7 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
* <li>该类不为{@link Object}</li> * <li>该类不为{@link Object}</li>
* </ul> * </ul>
*/ */
private boolean isNeedMapping(Class<?> type, Set<Class<?>> accessedTypes) { private boolean isNeedMapping(final Class<?> type, final Set<Class<?>> accessedTypes) {
return Objects.nonNull(type) return Objects.nonNull(type)
&& !accessedTypes.contains(type) && !accessedTypes.contains(type)
&& !Objects.equals(type, Object.class); && !Objects.equals(type, Object.class);

View File

@ -8,6 +8,7 @@ import cn.hutool.core.map.SafeConcurrentHashMap;
import cn.hutool.core.map.WeakConcurrentMap; import cn.hutool.core.map.WeakConcurrentMap;
import cn.hutool.core.text.CharPool; import cn.hutool.core.text.CharPool;
import cn.hutool.core.text.StrUtil; import cn.hutool.core.text.StrUtil;
import cn.hutool.core.util.CharUtil;
import java.io.File; import java.io.File;
import java.lang.reflect.Array; import java.lang.reflect.Array;
@ -40,7 +41,7 @@ public class ClassLoaderUtil {
/** /**
* 包名分界符: '.' * 包名分界符: '.'
*/ */
private static final char PACKAGE_SEPARATOR = StrUtil.C_DOT; private static final char PACKAGE_SEPARATOR = CharUtil.DOT;
/** /**
* 内部类分界符: '$' * 内部类分界符: '$'
*/ */

View File

@ -98,8 +98,8 @@ public class CompareUtil {
* *
* <ul> * <ul>
* <li>如需对null友好操作如下</li> * <li>如需对null友好操作如下</li>
* <li><code>Comparator.nullsLast(CompareUtil.natural())</code></li> * <li>{@code Comparator.nullsLast(CompareUtil.natural())}</li>
* <li><code>Comparator.nullsFirst(CompareUtil.natural())</code></li> * <li>{@code Comparator.nullsFirst(CompareUtil.natural())}</li>
* </ul> * </ul>
* *
* @param <E> 排序节点类型 * @param <E> 排序节点类型
@ -115,8 +115,8 @@ public class CompareUtil {
* *
* <ul> * <ul>
* <li>如需对null友好操作如下</li> * <li>如需对null友好操作如下</li>
* <li><code>Comparator.nullsLast(CompareUtil.naturalReverse())</code></li> * <li>{@code Comparator.nullsLast(CompareUtil.naturalReverse())}</li>
* <li><code>Comparator.nullsFirst(CompareUtil.naturalReverse())</code></li> * <li>{@code Comparator.nullsFirst(CompareUtil.naturalReverse())}</li>
* </ul> * </ul>
* *
* @param <E> 排序节点类型 * @param <E> 排序节点类型
@ -314,7 +314,7 @@ public class CompareUtil {
* *
* @param keyExtractor 从对象中提取排序键的函数(参与比较的内容) * @param keyExtractor 从对象中提取排序键的函数(参与比较的内容)
* @param atEndIfMiss 如果不在列表中是否排在后边; true:排在后边; false:排在前边 * @param atEndIfMiss 如果不在列表中是否排在后边; true:排在后边; false:排在前边
* @param objs 参与排序的数组数组的元素位置决定了对象的排序先后, 示例<code>int[] objs = new int[]{3, 2, 1, 4, 5,6};</code> * @param objs 参与排序的数组数组的元素位置决定了对象的排序先后, 示例{@code int[] objs = new int[]{3, 2, 1, 4, 5,6};}
* @param <T> 对象类型 * @param <T> 对象类型
* @param <U> 数组对象类型 * @param <U> 数组对象类型
* @return 索引比较器 * @return 索引比较器

View File

@ -16,6 +16,7 @@ import cn.hutool.core.math.NumberUtil;
import cn.hutool.core.regex.PatternPool; import cn.hutool.core.regex.PatternPool;
import cn.hutool.core.regex.ReUtil; import cn.hutool.core.regex.ReUtil;
import cn.hutool.core.text.StrUtil; import cn.hutool.core.text.StrUtil;
import cn.hutool.core.util.CharUtil;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
import java.text.DateFormat; import java.text.DateFormat;
@ -1624,7 +1625,7 @@ public class DateUtil extends CalendarUtil {
return 0; return 0;
} }
final List<String> hms = StrUtil.splitTrim(timeStr, StrUtil.C_COLON, 3); final List<String> hms = StrUtil.splitTrim(timeStr, CharUtil.COLON, 3);
final int lastIndex = hms.size() - 1; final int lastIndex = hms.size() - 1;
int result = 0; int result = 0;

View File

@ -5,6 +5,7 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.reflect.ConstructorUtil; import cn.hutool.core.reflect.ConstructorUtil;
import cn.hutool.core.text.StrUtil; import cn.hutool.core.text.StrUtil;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.CharUtil;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -201,9 +202,9 @@ public class ExceptionUtil {
*/ */
public static String stacktraceToOneLineString(final Throwable throwable, final int limit) { public static String stacktraceToOneLineString(final Throwable throwable, final int limit) {
final Map<Character, String> replaceCharToStrMap = new HashMap<>(); final Map<Character, String> replaceCharToStrMap = new HashMap<>();
replaceCharToStrMap.put(StrUtil.C_CR, StrUtil.SPACE); replaceCharToStrMap.put(CharUtil.CR, StrUtil.SPACE);
replaceCharToStrMap.put(StrUtil.C_LF, StrUtil.SPACE); replaceCharToStrMap.put(CharUtil.LF, StrUtil.SPACE);
replaceCharToStrMap.put(StrUtil.C_TAB, StrUtil.SPACE); replaceCharToStrMap.put(CharUtil.TAB, StrUtil.SPACE);
return stacktraceToString(throwable, limit, replaceCharToStrMap); return stacktraceToString(throwable, limit, replaceCharToStrMap);
} }

View File

@ -1,5 +1,6 @@
package cn.hutool.core.io; package cn.hutool.core.io;
import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.text.StrUtil; import cn.hutool.core.text.StrUtil;
@ -166,9 +167,9 @@ public class BufferUtil {
while (buffer.hasRemaining()) { while (buffer.hasRemaining()) {
b = buffer.get(); b = buffer.get();
charIndex++; charIndex++;
if (b == StrUtil.C_CR) { if (b == CharUtil.CR) {
canEnd = true; canEnd = true;
} else if (b == StrUtil.C_LF) { } else if (b == CharUtil.LF) {
return canEnd ? charIndex - 2 : charIndex - 1; return canEnd ? charIndex - 2 : charIndex - 1;
} else { } else {
// 只有\r无法确认换行 // 只有\r无法确认换行

View File

@ -1306,7 +1306,7 @@ public class FileUtil extends PathUtil {
} }
// 给定的路径已经是绝对路径了 // 给定的路径已经是绝对路径了
return StrUtil.C_SLASH == path.charAt(0) || ReUtil.isMatch(PATTERN_PATH_ABSOLUTE, path); return CharUtil.SLASH == path.charAt(0) || ReUtil.isMatch(PATTERN_PATH_ABSOLUTE, path);
} }
/** /**
@ -1600,7 +1600,7 @@ public class FileUtil extends PathUtil {
if (prefixIndex > -1) { if (prefixIndex > -1) {
// 可能Windows风格路径 // 可能Windows风格路径
prefix = pathToUse.substring(0, prefixIndex + 1); prefix = pathToUse.substring(0, prefixIndex + 1);
if (StrUtil.startWith(prefix, StrUtil.C_SLASH)) { if (StrUtil.startWith(prefix, CharUtil.SLASH)) {
// 去除类似于/C:这类路径开头的斜杠 // 去除类似于/C:这类路径开头的斜杠
prefix = prefix.substring(1); prefix = prefix.substring(1);
} }
@ -1616,7 +1616,7 @@ public class FileUtil extends PathUtil {
pathToUse = pathToUse.substring(1); pathToUse = pathToUse.substring(1);
} }
final List<String> pathList = StrUtil.split(pathToUse, StrUtil.C_SLASH); final List<String> pathList = StrUtil.split(pathToUse, CharUtil.SLASH);
final List<String> pathElements = new LinkedList<>(); final List<String> pathElements = new LinkedList<>();
int tops = 0; int tops = 0;
@ -1887,6 +1887,7 @@ public class FileUtil extends PathUtil {
*/ */
public static BOMInputStream getBOMInputStream(final File file) throws IORuntimeException { public static BOMInputStream getBOMInputStream(final File file) throws IORuntimeException {
try { try {
//noinspection IOStreamConstructor
return new BOMInputStream(new FileInputStream(file)); return new BOMInputStream(new FileInputStream(file));
} catch (final IOException e) { } catch (final IOException e) {
throw new IORuntimeException(e); throw new IORuntimeException(e);
@ -2431,6 +2432,7 @@ public class FileUtil extends PathUtil {
public static BufferedOutputStream getOutputStream(final File file) throws IORuntimeException { public static BufferedOutputStream getOutputStream(final File file) throws IORuntimeException {
final OutputStream out; final OutputStream out;
try { try {
//noinspection IOStreamConstructor
out = new FileOutputStream(touch(file)); out = new FileOutputStream(touch(file));
} catch (final IOException e) { } catch (final IOException e) {
throw new IORuntimeException(e); throw new IORuntimeException(e);

View File

@ -18,7 +18,7 @@ public class NullOutputStream extends OutputStream {
public static final NullOutputStream NULL_OUTPUT_STREAM = new NullOutputStream(); public static final NullOutputStream NULL_OUTPUT_STREAM = new NullOutputStream();
/** /**
* 什么也不做写出到<code>/dev/null</code>. * 什么也不做写出到{@code /dev/null}.
* *
* @param b 写出的数据 * @param b 写出的数据
* @param off 开始位置 * @param off 开始位置
@ -30,7 +30,7 @@ public class NullOutputStream extends OutputStream {
} }
/** /**
* 什么也不做写出到 <code>/dev/null</code>. * 什么也不做写出到 {@code /dev/null}.
* *
* @param b 写出的数据 * @param b 写出的数据
*/ */
@ -40,7 +40,7 @@ public class NullOutputStream extends OutputStream {
} }
/** /**
* 什么也不做写出到 <code>/dev/null</code>. * 什么也不做写出到 {@code /dev/null}.
* *
* @param b 写出的数据 * @param b 写出的数据
* @throws IOException 不抛出 * @throws IOException 不抛出

View File

@ -5,6 +5,7 @@ import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.watch.watchers.WatcherChain; import cn.hutool.core.io.watch.watchers.WatcherChain;
import cn.hutool.core.text.StrUtil; import cn.hutool.core.text.StrUtil;
import cn.hutool.core.net.URLUtil; import cn.hutool.core.net.URLUtil;
import cn.hutool.core.util.CharUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -322,7 +323,7 @@ public class WatchMonitor extends WatchServer {
if (null != lastPathEle) { if (null != lastPathEle) {
final String lastPathEleStr = lastPathEle.toString(); final String lastPathEleStr = lastPathEle.toString();
//带有点表示有扩展名按照未创建的文件对待Linux下.d的为目录排除之 //带有点表示有扩展名按照未创建的文件对待Linux下.d的为目录排除之
if (StrUtil.contains(lastPathEleStr, StrUtil.C_DOT) && false == StrUtil.endWithIgnoreCase(lastPathEleStr, ".d")) { if (StrUtil.contains(lastPathEleStr, CharUtil.DOT) && false == StrUtil.endWithIgnoreCase(lastPathEleStr, ".d")) {
this.filePath = this.path; this.filePath = this.path;
this.path = this.filePath.getParent(); this.path = this.filePath.getParent();
} }

View File

@ -30,7 +30,7 @@ public class Ansi8BitColor implements AnsiElement {
* @param code 颜色代码(0-255) * @param code 颜色代码(0-255)
* @return 前景色ANSI颜色实例 * @return 前景色ANSI颜色实例
*/ */
public static Ansi8BitColor foreground(int code) { public static Ansi8BitColor foreground(final int code) {
return new Ansi8BitColor(PREFIX_FORE, code); return new Ansi8BitColor(PREFIX_FORE, code);
} }
@ -40,7 +40,7 @@ public class Ansi8BitColor implements AnsiElement {
* @param code 颜色代码(0-255) * @param code 颜色代码(0-255)
* @return 背景色ANSI颜色实例 * @return 背景色ANSI颜色实例
*/ */
public static Ansi8BitColor background(int code) { public static Ansi8BitColor background(final int code) {
return new Ansi8BitColor(PREFIX_BACK, code); return new Ansi8BitColor(PREFIX_BACK, code);
} }
@ -52,9 +52,9 @@ public class Ansi8BitColor implements AnsiElement {
* *
* @param prefix 前缀 * @param prefix 前缀
* @param code 颜色代码(0-255) * @param code 颜色代码(0-255)
* @throws IllegalArgumentException 颜色代码不在0~255范围内 * @throws IllegalArgumentException 颜色代码不在 0~255 范围内
*/ */
private Ansi8BitColor(String prefix, int code) { private Ansi8BitColor(final String prefix, final int code) {
Assert.isTrue(code >= 0 && code <= 255, "Code must be between 0 and 255"); Assert.isTrue(code >= 0 && code <= 255, "Code must be between 0 and 255");
this.prefix = prefix; this.prefix = prefix;
this.code = code; this.code = code;
@ -95,14 +95,14 @@ public class Ansi8BitColor implements AnsiElement {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(final Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (obj == null || getClass() != obj.getClass()) { if (obj == null || getClass() != obj.getClass()) {
return false; return false;
} }
Ansi8BitColor other = (Ansi8BitColor) obj; final Ansi8BitColor other = (Ansi8BitColor) obj;
return ObjUtil.equals(this.prefix, other.prefix) && this.code == other.code; return ObjUtil.equals(this.prefix, other.prefix) && this.code == other.code;
} }

View File

@ -16,12 +16,12 @@ import java.util.stream.Stream;
public interface SerRunnable extends Runnable, Serializable { public interface SerRunnable extends Runnable, Serializable {
/** /**
* When an object implementing interface <code>Runnable</code> is used * When an object implementing interface {@code Runnable} is used
* to create a thread, starting the thread causes the object's * to create a thread, starting the thread causes the object's
* <code>run</code> method to be called in that separately executing * {@code run} method to be called in that separately executing
* thread. * thread.
* <p> * <p>
* The general contract of the method <code>run</code> is that it may * The general contract of the method {@code run} is that it may
* take any action whatsoever. * take any action whatsoever.
* *
* @throws Exception wrapped checked exceptions * @throws Exception wrapped checked exceptions
@ -30,12 +30,12 @@ public interface SerRunnable extends Runnable, Serializable {
void running() throws Exception; void running() throws Exception;
/** /**
* When an object implementing interface <code>Runnable</code> is used * When an object implementing interface {@code Runnable} is used
* to create a thread, starting the thread causes the object's * to create a thread, starting the thread causes the object's
* <code>run</code> method to be called in that separately executing * {@code run} method to be called in that separately executing
* thread. * thread.
* <p> * <p>
* The general contract of the method <code>run</code> is that it may * The general contract of the method {@code run} is that it may
* take any action whatsoever. * take any action whatsoever.
* *
* @see Thread#run() * @see Thread#run()

View File

@ -3,7 +3,7 @@ package cn.hutool.core.lang.mutable;
import cn.hutool.core.comparator.CompareUtil; import cn.hutool.core.comparator.CompareUtil;
/** /**
* 可变 <code>int</code> 类型 * 可变 {@code int} 类型
* *
* @see Integer * @see Integer
* @since 3.0.1 * @since 3.0.1

View File

@ -544,7 +544,7 @@ public class ClassUtil {
* @return 包名 * @return 包名
*/ */
public static String getPackagePath(final Class<?> clazz) { public static String getPackagePath(final Class<?> clazz) {
return getPackage(clazz).replace(StrUtil.C_DOT, StrUtil.C_SLASH); return getPackage(clazz).replace(CharUtil.DOT, CharUtil.SLASH);
} }
/** /**

View File

@ -17,7 +17,7 @@ public abstract class AbstractEnhancedWrappedStream<T, S extends AbstractEnhance
implements TerminableWrappedStream<T, S>, TransformableWrappedStream<T, S> { implements TerminableWrappedStream<T, S>, TransformableWrappedStream<T, S> {
/** /**
* 原始流实例 * 原始流实例
*/ */
protected final Stream<T> stream; protected final Stream<T> stream;

View File

@ -4,7 +4,6 @@ import cn.hutool.core.lang.Opt;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjUtil;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Spliterator; import java.util.Spliterator;
import java.util.function.*; import java.util.function.*;

View File

@ -2,7 +2,7 @@ package cn.hutool.core.text;
/** /**
* 常用字符常量 * 常用字符常量
* @see StrPool *
* @author looly * @author looly
* @since 5.6.3 * @since 5.6.3
*/ */

View File

@ -1,6 +1,7 @@
package cn.hutool.core.text; package cn.hutool.core.text;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.CharUtil;
import java.util.Map; import java.util.Map;
@ -67,8 +68,8 @@ public class StrFormatter {
} }
// 转义符 // 转义符
if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == StrUtil.C_BACKSLASH) {// 转义符 if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == CharUtil.BACKSLASH) {// 转义符
if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == StrUtil.C_BACKSLASH) {// 双转义符 if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == CharUtil.BACKSLASH) {// 双转义符
// 转义符之前还有一个转义符占位符依旧有效 // 转义符之前还有一个转义符占位符依旧有效
sbuf.append(strPattern, handledPosition, delimIndex - 1); sbuf.append(strPattern, handledPosition, delimIndex - 1);
sbuf.append(StrUtil.utf8Str(argArray[argIndex])); sbuf.append(StrUtil.utf8Str(argArray[argIndex]));

View File

@ -1,7 +1,5 @@
package cn.hutool.core.text; package cn.hutool.core.text;
import cn.hutool.core.util.XmlUtil;
/** /**
* 常用字符串常量定义 * 常用字符串常量定义
* @see CharPool * @see CharPool
@ -10,82 +8,6 @@ import cn.hutool.core.util.XmlUtil;
* @since 5.6.3 * @since 5.6.3
*/ */
public interface StrPool { public interface StrPool {
/**
* 字符常量空格符 {@code ' '}
*/
char C_SPACE = CharPool.SPACE;
/**
* 字符常量制表符 {@code '\t'}
*/
char C_TAB = CharPool.TAB;
/**
* 字符常量 {@code '.'}
*/
char C_DOT = CharPool.DOT;
/**
* 字符常量斜杠 {@code '/'}
*/
char C_SLASH = CharPool.SLASH;
/**
* 字符常量反斜杠 {@code '\\'}
*/
char C_BACKSLASH = CharPool.BACKSLASH;
/**
* 字符常量回车符 {@code '\r'}
*/
char C_CR = CharPool.CR;
/**
* 字符常量换行符 {@code '\n'}
*/
char C_LF = CharPool.LF;
/**
* 字符常量下划线 {@code '_'}
*/
char C_UNDERLINE = CharPool.UNDERLINE;
/**
* 字符常量逗号 {@code ','}
*/
char C_COMMA = CharPool.COMMA;
/**
* 字符常量花括号 <code>'{'</code>
*/
char C_DELIM_START = CharPool.DELIM_START;
/**
* 字符常量花括号 <code>'}'</code>
*/
char C_DELIM_END = CharPool.DELIM_END;
/**
* 字符常量中括号 {@code '['}
*/
char C_BRACKET_START = CharPool.BRACKET_START;
/**
* 字符常量中括号 {@code ']'}
*/
char C_BRACKET_END = CharPool.BRACKET_END;
/**
* 字符常量冒号 {@code ':'}
*/
char C_COLON = CharPool.COLON;
/**
* 字符常量艾特 {@code '@'}
*/
char C_AT = CharPool.AT;
/** /**
* 字符串常量制表符 {@code "\t"} * 字符串常量制表符 {@code "\t"}
*/ */
@ -174,37 +96,6 @@ public interface StrPool {
*/ */
String AT = "@"; String AT = "@";
/**
* 字符串常量HTML 空格转义 {@code "&nbsp;" -> " "}
*/
String HTML_NBSP = XmlUtil.NBSP;
/**
* 字符串常量HTML And 符转义 {@code "&amp;" -> "&"}
*/
String HTML_AMP = XmlUtil.AMP;
/**
* 字符串常量HTML 双引号转义 {@code "&quot;" -> "\""}
*/
String HTML_QUOTE = XmlUtil.QUOTE;
/**
* 字符串常量HTML 单引号转义 {@code "&apos" -> "'"}
*/
String HTML_APOS = XmlUtil.APOS;
/**
* 字符串常量HTML 小于号转义 {@code "&lt;" -> "<"}
*/
String HTML_LT = XmlUtil.LT;
/**
* 字符串常量HTML 大于号转义 {@code "&gt;" -> ">"}
*/
String HTML_GT = XmlUtil.GT;
/** /**
* 字符串常量 JSON {@code "{}"} * 字符串常量 JSON {@code "{}"}
*/ */

View File

@ -3,6 +3,7 @@ package cn.hutool.core.text.dfa;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.text.StrUtil; import cn.hutool.core.text.StrUtil;
import cn.hutool.core.util.CharUtil;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -17,7 +18,7 @@ import java.util.function.Predicate;
*/ */
public final class SensitiveUtil { public final class SensitiveUtil {
public static final char DEFAULT_SEPARATOR = StrUtil.C_COMMA; public static final char DEFAULT_SEPARATOR = CharUtil.COMMA;
private static final WordTree sensitiveTree = new WordTree(); private static final WordTree sensitiveTree = new WordTree();
/** /**

View File

@ -54,7 +54,7 @@ public class SplitUtil {
* @since 3.0.8 * @since 3.0.8
*/ */
public static List<String> splitPath(final CharSequence str, final int limit) { public static List<String> splitPath(final CharSequence str, final int limit) {
return split(str, StrUtil.C_SLASH, limit, true, true); return split(str, CharUtil.SLASH, limit, true, true);
} }
/** /**

View File

@ -64,7 +64,7 @@ public class ArrayUtil extends PrimitiveArrayUtil {
* 数组是否为空<br> * 数组是否为空<br>
* 此方法会匹配单一对象如果此对象为{@code null}则返回true<br> * 此方法会匹配单一对象如果此对象为{@code null}则返回true<br>
* 如果此对象为非数组理解为此对象为数组的第一个元素则返回false<br> * 如果此对象为非数组理解为此对象为数组的第一个元素则返回false<br>
* 如果此对象为数组对象数组长度大于0情况下返回false否则返回true * 如果此对象为数组对象数组长度大于0情况下返回false否则返回true
* *
* @param array 数组 * @param array 数组
* @return 是否为空 * @return 是否为空

View File

@ -708,7 +708,7 @@ public class IdcardUtil {
case 0: case 0:
return '1'; return '1';
default: default:
return StrUtil.C_SPACE; return CharUtil.SPACE;
} }
} }

View File

@ -4,7 +4,6 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date;
public class ZodiacTest { public class ZodiacTest {
@ -13,7 +12,7 @@ public class ZodiacTest {
Assert.assertEquals("摩羯座", Zodiac.getZodiac(Month.JANUARY, 19)); Assert.assertEquals("摩羯座", Zodiac.getZodiac(Month.JANUARY, 19));
Assert.assertEquals("水瓶座", Zodiac.getZodiac(Month.JANUARY, 20)); Assert.assertEquals("水瓶座", Zodiac.getZodiac(Month.JANUARY, 20));
Assert.assertEquals("巨蟹座", Zodiac.getZodiac(6, 17)); Assert.assertEquals("巨蟹座", Zodiac.getZodiac(6, 17));
Calendar calendar = Calendar.getInstance(); final Calendar calendar = Calendar.getInstance();
calendar.set(2022, Calendar.JULY, 17); calendar.set(2022, Calendar.JULY, 17);
Assert.assertEquals("巨蟹座", Zodiac.getZodiac(calendar.getTime())); Assert.assertEquals("巨蟹座", Zodiac.getZodiac(calendar.getTime()));
Assert.assertEquals("巨蟹座", Zodiac.getZodiac(calendar)); Assert.assertEquals("巨蟹座", Zodiac.getZodiac(calendar));
@ -25,7 +24,7 @@ public class ZodiacTest {
Assert.assertEquals("", Zodiac.getChineseZodiac(1994)); Assert.assertEquals("", Zodiac.getChineseZodiac(1994));
Assert.assertEquals("", Zodiac.getChineseZodiac(2018)); Assert.assertEquals("", Zodiac.getChineseZodiac(2018));
Assert.assertEquals("", Zodiac.getChineseZodiac(2019)); Assert.assertEquals("", Zodiac.getChineseZodiac(2019));
Calendar calendar = Calendar.getInstance(); final Calendar calendar = Calendar.getInstance();
calendar.set(2022, Calendar.JULY, 17); calendar.set(2022, Calendar.JULY, 17);
Assert.assertEquals("", Zodiac.getChineseZodiac(calendar.getTime())); Assert.assertEquals("", Zodiac.getChineseZodiac(calendar.getTime()));
Assert.assertEquals("", Zodiac.getChineseZodiac(calendar)); Assert.assertEquals("", Zodiac.getChineseZodiac(calendar));

View File

@ -6,7 +6,6 @@ import lombok.SneakyThrows;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
/** /**
* 反射工具类单元测试 * 反射工具类单元测试

View File

@ -70,18 +70,20 @@ public class ObjUtilTest {
Assert.assertTrue(ObjUtil.contains(new int[]{1,2,3,4,5}, 1)); Assert.assertTrue(ObjUtil.contains(new int[]{1,2,3,4,5}, 1));
Assert.assertFalse(ObjUtil.contains(null, 1)); Assert.assertFalse(ObjUtil.contains(null, 1));
Assert.assertTrue(ObjUtil.contains("123", "3")); Assert.assertTrue(ObjUtil.contains("123", "3"));
Map<Integer, Integer> map = new HashMap<>(); final Map<Integer, Integer> map = new HashMap<>();
map.put(1, 1); map.put(1, 1);
map.put(2, 2); map.put(2, 2);
Assert.assertTrue(ObjUtil.contains(map, 1)); Assert.assertTrue(ObjUtil.contains(map, 1));
Assert.assertTrue(ObjUtil.contains(Arrays.asList(1, 2, 3).iterator(), 2)); Assert.assertTrue(ObjUtil.contains(Arrays.asList(1, 2, 3).iterator(), 2));
} }
@SuppressWarnings("ConstantConditions")
@Test @Test
public void isNullTest() { public void isNullTest() {
Assert.assertTrue(ObjUtil.isNull(null)); Assert.assertTrue(ObjUtil.isNull(null));
} }
@SuppressWarnings("ConstantConditions")
@Test @Test
public void isNotNullTest() { public void isNotNullTest() {
Assert.assertFalse(ObjUtil.isNotNull(null)); Assert.assertFalse(ObjUtil.isNotNull(null));
@ -124,12 +126,12 @@ public class ObjUtilTest {
Assert.assertSame(val1, ObjUtil.defaultIfNull(val1, Function.identity(), val2)); Assert.assertSame(val1, ObjUtil.defaultIfNull(val1, Function.identity(), val2));
Assert.assertSame(val2, ObjUtil.defaultIfNull(null, Function.identity(), val2)); Assert.assertSame(val2, ObjUtil.defaultIfNull(null, Function.identity(), val2));
SerializableBean obj = new SerializableBean(null); final SerializableBean obj = new SerializableBean(null);
SerializableBean objNull = null; final SerializableBean objNull = null;
String result3 = ObjUtil.defaultIfNull(obj, Object::toString, "fail"); final String result3 = ObjUtil.defaultIfNull(obj, Object::toString, "fail");
Assert.assertNotNull(result3); Assert.assertNotNull(result3);
String result4 = ObjUtil.defaultIfNull(objNull, Object::toString, () -> "fail"); final String result4 = ObjUtil.defaultIfNull(objNull, Object::toString, () -> "fail");
Assert.assertNotNull(result4); Assert.assertNotNull(result4);
} }
@ -242,6 +244,7 @@ public class ObjUtilTest {
@RequiredArgsConstructor @RequiredArgsConstructor
@EqualsAndHashCode @EqualsAndHashCode
private static class SerializableBean implements Serializable { private static class SerializableBean implements Serializable {
private static final long serialVersionUID = -7759522980793544334L;
private final Integer id; private final Integer id;
} }
@ -251,6 +254,7 @@ public class ObjUtilTest {
private final Integer id; private final Integer id;
} }
@SuppressWarnings("unused")
private interface TypeArgument<A, B> {}; private interface TypeArgument<A, B> {};
} }

View File

@ -5,6 +5,7 @@ import cn.hutool.core.date.Month;
import cn.hutool.core.date.Week; import cn.hutool.core.date.Week;
import cn.hutool.core.math.NumberUtil; import cn.hutool.core.math.NumberUtil;
import cn.hutool.core.text.StrUtil; import cn.hutool.core.text.StrUtil;
import cn.hutool.core.util.CharUtil;
import cn.hutool.cron.CronException; import cn.hutool.cron.CronException;
import cn.hutool.cron.pattern.Part; import cn.hutool.cron.pattern.Part;
import cn.hutool.cron.pattern.matcher.AlwaysTrueMatcher; import cn.hutool.cron.pattern.matcher.AlwaysTrueMatcher;
@ -102,7 +103,7 @@ public class PartParser {
private List<Integer> parseArray(final String value) { private List<Integer> parseArray(final String value) {
final List<Integer> values = new ArrayList<>(); final List<Integer> values = new ArrayList<>();
final List<String> parts = StrUtil.split(value, StrUtil.C_COMMA); final List<String> parts = StrUtil.split(value, CharUtil.COMMA);
for (final String part : parts) { for (final String part : parts) {
ListUtil.addAllIfNotContains(values, parseStep(part)); ListUtil.addAllIfNotContains(values, parseStep(part));
} }
@ -122,7 +123,7 @@ public class PartParser {
* @return List * @return List
*/ */
private List<Integer> parseStep(final String value) { private List<Integer> parseStep(final String value) {
final List<String> parts = StrUtil.split(value, StrUtil.C_SLASH); final List<String> parts = StrUtil.split(value, CharUtil.SLASH);
final int size = parts.size(); final int size = parts.size();
final List<Integer> results; final List<Integer> results;

View File

@ -65,7 +65,7 @@ public class AnsiSqlDialect implements Dialect {
final Condition[] where = query.getWhere(); final Condition[] where = query.getWhere();
if (ArrayUtil.isEmpty(where)) { if (ArrayUtil.isEmpty(where)) {
// 对于无条件删除语句直接抛出异常禁止防止误删除 // 对于无条件删除语句直接抛出异常禁止防止误删除
throw new SQLException("No 'WHERE' condition, we can't prepared statement for delete everything."); throw new SQLException("No 'WHERE' condition, we can't prepared statement for delete everything.");
} }
final SqlBuilder delete = SqlBuilder.of(wrapper).delete(query.getFirstTableName()).where(where); final SqlBuilder delete = SqlBuilder.of(wrapper).delete(query.getFirstTableName()).where(where);
@ -79,7 +79,7 @@ public class AnsiSqlDialect implements Dialect {
final Condition[] where = query.getWhere(); final Condition[] where = query.getWhere();
if (ArrayUtil.isEmpty(where)) { if (ArrayUtil.isEmpty(where)) {
// 对于无条件删除语句直接抛出异常禁止防止误删除 // 对于无条件删除语句直接抛出异常禁止防止误删除
throw new SQLException("No 'WHERE' condition, we can't prepare statement for update everything."); throw new SQLException("No 'WHERE' condition, we can't prepare statement for update everything.");
} }

View File

@ -490,7 +490,7 @@ public class Condition implements Cloneable, Serializable {
} }
} }
final List<String> strs = StrUtil.split(valueStr, StrUtil.C_SPACE, 2); final List<String> strs = StrUtil.split(valueStr, CharUtil.SPACE, 2);
if (strs.size() < 2) { if (strs.size() < 2) {
return; return;
} }

View File

@ -16,7 +16,7 @@ import java.util.List;
* *
*/ */
public class MetaUtilTest { public class MetaUtilTest {
DataSource ds = DSFactory.get("test"); final DataSource ds = DSFactory.get("test");
@Test @Test
public void getTablesTest() { public void getTablesTest() {

View File

@ -11,7 +11,7 @@ import java.util.Set;
/** /**
* 基于https://github.com/vdurmont/emoji-java的Emoji表情工具类 * 基于https://github.com/vdurmont/emoji-java的Emoji表情工具类
* <p> * <p>
* emoji-java文档以及别名列表见https://github.com/vdurmont/emoji-java * emoji-java文档以及别名列表见<a href="https://github.com/vdurmont/emoji-java">...</a>
* *
* @author looly * @author looly
* @since 4.2.1 * @since 4.2.1
@ -65,9 +65,9 @@ public class EmojiUtil {
* 例如 * 例如
* *
* <pre> * <pre>
* <code>:smile:</code> 替换为 <code>😄</code> * {@code :smile:} 替换为 {@code 😄}
* <code>&amp;#128516;</code> 替换为 <code>😄</code> * {@code &#128516;} 替换为 {@code 😄}
* <code>:boy|type_6:</code> 替换为 <code>👦🏿</code> * {@code :boy|type_6:} 替换为 {@code 👦🏿}
* </pre> * </pre>
* *
* @param str 包含Emoji别名或者HTML表现形式的字符串 * @param str 包含Emoji别名或者HTML表现形式的字符串
@ -80,22 +80,22 @@ public class EmojiUtil {
/** /**
* 将字符串中的Unicode Emoji字符转换为别名表现形式两个":"包围的格式 * 将字符串中的Unicode Emoji字符转换为别名表现形式两个":"包围的格式
* <p> * <p>
* 例如 <code>😄</code> 转换为 <code>:smile:</code> * 例如 {@code 😄} 转换为 {@code :smile:}
* *
* <p> * <p>
* {@link FitzpatrickAction}参数被设置为{@link FitzpatrickAction#PARSE}则别名后会增加"|"并追加fitzpatrick类型 * {@link FitzpatrickAction}参数被设置为{@link FitzpatrickAction#PARSE}则别名后会增加"|"并追加fitzpatrick类型
* <p> * <p>
* 例如<code>👦🏿</code> 转换为 <code>:boy|type_6:</code> * 例如{@code 👦🏿} 转换为 {@code :boy|type_6:}
* *
* <p> * <p>
* {@link FitzpatrickAction}参数被设置为{@link FitzpatrickAction#REMOVE}则别名后的"|"和类型将被去除 * {@link FitzpatrickAction}参数被设置为{@link FitzpatrickAction#REMOVE}则别名后的"|"和类型将被去除
* <p> * <p>
* 例如<code>👦🏿</code> 转换为 <code>:boy:</code> * 例如{@code 👦🏿} 转换为 {@code :boy:}
* *
* <p> * <p>
* {@link FitzpatrickAction}参数被设置为{@link FitzpatrickAction#IGNORE}则别名后的类型将被忽略 * {@link FitzpatrickAction}参数被设置为{@link FitzpatrickAction#IGNORE}则别名后的类型将被忽略
* <p> * <p>
* 例如<code>👦🏿</code> 转换为 <code>:boy:🏿</code> * 例如{@code 👦🏿} 转换为 {@code :boy:🏿}
* *
* @param str 包含Emoji Unicode字符的字符串 * @param str 包含Emoji Unicode字符的字符串
* @return 替换后的字符串 * @return 替换后的字符串
@ -107,7 +107,7 @@ public class EmojiUtil {
/** /**
* 将字符串中的Unicode Emoji字符转换为别名表现形式两个":"包围的格式别名后会增加"|"并追加fitzpatrick类型 * 将字符串中的Unicode Emoji字符转换为别名表现形式两个":"包围的格式别名后会增加"|"并追加fitzpatrick类型
* <p> * <p>
* 例如<code>👦🏿</code> 转换为 <code>:boy|type_6:</code> * 例如{@code 👦🏿} 转换为 {@code :boy|type_6:}
* *
* @param str 包含Emoji Unicode字符的字符串 * @param str 包含Emoji Unicode字符的字符串
* @param fitzpatrickAction {@link FitzpatrickAction} * @param fitzpatrickAction {@link FitzpatrickAction}
@ -120,7 +120,7 @@ public class EmojiUtil {
/** /**
* 将字符串中的Unicode Emoji字符转换为HTML 16进制表现形式 * 将字符串中的Unicode Emoji字符转换为HTML 16进制表现形式
* <p> * <p>
* 例如<code>👦🏿</code> 转换为 <code>&amp;#x1f466;</code> * 例如{@code 👦🏿} 转换为 {@code &#x1f466;}
* *
* @param str 包含Emoji Unicode字符的字符串 * @param str 包含Emoji Unicode字符的字符串
* @return 替换后的字符串 * @return 替换后的字符串
@ -132,7 +132,7 @@ public class EmojiUtil {
/** /**
* 将字符串中的Unicode Emoji字符转换为HTML表现形式Hex方式 * 将字符串中的Unicode Emoji字符转换为HTML表现形式Hex方式
* <p> * <p>
* 例如<code>👦🏿</code> 转换为 <code>&amp;#128102;</code> * 例如{@code 👦🏿} 转换为 {@code &#128102;}
* *
* @param str 包含Emoji Unicode字符的字符串 * @param str 包含Emoji Unicode字符的字符串
* @return 替换后的字符串 * @return 替换后的字符串
@ -144,8 +144,8 @@ public class EmojiUtil {
/** /**
* 将字符串中的Unicode Emoji字符转换为HTML表现形式例如 * 将字符串中的Unicode Emoji字符转换为HTML表现形式例如
* <pre> * <pre>
* 如果为hex形式<code>👦🏿</code> 转换为 <code>&amp;#x1f466;</code> * 如果为hex形式{@code 👦🏿} 转换为 {@code &#x1f466;}
* 否则<code>👦🏿</code> 转换为 <code>&amp;#128102;</code> * 否则{@code 👦🏿} 转换为 {@code &#128102;}
* </pre> * </pre>
* *
* @param str 包含Emoji Unicode字符的字符串 * @param str 包含Emoji Unicode字符的字符串

View File

@ -296,15 +296,13 @@ public class JschUtil {
* *
* @param session 需要解除端口映射的SSH会话 * @param session 需要解除端口映射的SSH会话
* @param localPort 需要解除的本地端口 * @param localPort 需要解除的本地端口
* @return 解除成功与否
*/ */
public static boolean unBindPort(final Session session, final int localPort) { public static void unBindPort(final Session session, final int localPort) {
try { try {
session.delPortForwardingL(localPort); session.delPortForwardingL(localPort);
} catch (final JSchException e) { } catch (final JSchException e) {
throw new JschRuntimeException(e); throw new JschRuntimeException(e);
} }
return true;
} }
/** /**

View File

@ -34,8 +34,10 @@ public class OshiTest {
@Test @Test
@Ignore @Ignore
public void getUsedTest() { public void getUsedTest() {
while (true) { int i = 0;
while (i < 1000) {
Console.log(OshiUtil.getCpuInfo().getUsed()); Console.log(OshiUtil.getCpuInfo().getUsed());
i++;
} }
} }
} }

View File

@ -1,8 +1,9 @@
package cn.hutool.http; package cn.hutool.http;
import cn.hutool.core.text.escape.EscapeUtil;
import cn.hutool.core.regex.ReUtil; import cn.hutool.core.regex.ReUtil;
import cn.hutool.core.text.StrUtil; import cn.hutool.core.text.StrUtil;
import cn.hutool.core.text.escape.EscapeUtil;
import cn.hutool.core.util.XmlUtil;
/** /**
* HTML工具类 * HTML工具类
@ -16,14 +17,7 @@ import cn.hutool.core.text.StrUtil;
*/ */
public class HtmlUtil { public class HtmlUtil {
public static final String NBSP = StrUtil.HTML_NBSP; public static final String RE_HTML_MARK = "(<[^<]*?>)|(<\\s*?/[^<]*?>)|(<[^<]*?/\\s*?>)";
public static final String AMP = StrUtil.HTML_AMP;
public static final String QUOTE = StrUtil.HTML_QUOTE;
public static final String APOS = StrUtil.HTML_APOS;
public static final String LT = StrUtil.HTML_LT;
public static final String GT = StrUtil.HTML_GT;
public static final String RE_HTML_MARK = "(<[^<]*?>)|(<[\\s]*?/[^<]*?>)|(<[^<]*?/[\\s]*?>)";
public static final String RE_SCRIPT = "<[\\s]*?script[^>]*?>.*?<[\\s]*?\\/[\\s]*?script[\\s]*?>"; public static final String RE_SCRIPT = "<[\\s]*?script[^>]*?>.*?<[\\s]*?\\/[\\s]*?script[\\s]*?>";
private static final char[][] TEXT = new char[64][]; private static final char[][] TEXT = new char[64][];
@ -35,10 +29,10 @@ public class HtmlUtil {
// special HTML characters // special HTML characters
TEXT['\''] = "&#039;".toCharArray(); // 单引号 ('&apos;' doesn't work - it is not by the w3 specs) TEXT['\''] = "&#039;".toCharArray(); // 单引号 ('&apos;' doesn't work - it is not by the w3 specs)
TEXT['"'] = QUOTE.toCharArray(); // 单引号 TEXT['"'] = XmlUtil.QUOTE.toCharArray(); // 单引号
TEXT['&'] = AMP.toCharArray(); // & TEXT['&'] = XmlUtil.AMP.toCharArray(); // &
TEXT['<'] = LT.toCharArray(); // 小于号 TEXT['<'] = XmlUtil.LT.toCharArray(); // 小于号
TEXT['>'] = GT.toCharArray(); // 大于号 TEXT['>'] = XmlUtil.GT.toCharArray(); // 大于号
} }
/** /**

View File

@ -43,7 +43,7 @@ public class Engine extends UserAgentInfo {
*/ */
public Engine(final String name, final String regex) { public Engine(final String name, final String regex) {
super(name, regex); super(name, regex);
this.versionPattern = Pattern.compile(name + "[/\\- ]([\\d\\w.\\-]+)", Pattern.CASE_INSENSITIVE); this.versionPattern = Pattern.compile(name + "[/\\- ]([\\w.\\-]+)", Pattern.CASE_INSENSITIVE);
} }
/** /**

View File

@ -432,7 +432,7 @@ public final class InternalJSONUtil {
case '\r': case '\r':
return "\\r"; return "\\r";
default: default:
if (c < StrUtil.C_SPACE || // if (c < CharUtil.SPACE || //
(c >= '\u0080' && c <= '\u00a0') || // (c >= '\u0080' && c <= '\u00a0') || //
(c >= '\u2000' && c <= '\u2010') || // (c >= '\u2000' && c <= '\u2010') || //
(c >= '\u2028' && c <= '\u202F') || // (c >= '\u2028' && c <= '\u202F') || //

View File

@ -19,7 +19,7 @@ public class JSONStrFormatter {
/** /**
* 换行符 * 换行符
*/ */
private static final char NEW_LINE = StrUtil.C_LF; private static final char NEW_LINE = CharUtil.LF;
/** /**
* 返回格式化JSON字符串 * 返回格式化JSON字符串

View File

@ -1,14 +1,15 @@
package cn.hutool.poi.excel.cell.values; package cn.hutool.poi.excel.cell.values;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.StrUtil; import cn.hutool.core.util.CharUtil;
import cn.hutool.poi.excel.ExcelDateUtil; import cn.hutool.poi.excel.ExcelDateUtil;
import cn.hutool.poi.excel.cell.CellValue; import cn.hutool.poi.excel.cell.CellValue;
import java.util.Date;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.util.NumberToTextConverter; import org.apache.poi.ss.util.NumberToTextConverter;
import java.util.Date;
/** /**
* 数字类型单元格值<br> * 数字类型单元格值<br>
* 单元格值可能为LongDoubleDate * 单元格值可能为LongDoubleDate
@ -48,7 +49,7 @@ public class NumericCellValue implements CellValue<Object> {
final String format = style.getDataFormatString(); final String format = style.getDataFormatString();
// 普通数字 // 普通数字
if (null != format && format.indexOf(StrUtil.C_DOT) < 0) { if (null != format && format.indexOf(CharUtil.DOT) < 0) {
final long longPart = (long) value; final long longPart = (long) value;
if (((double) longPart) == value) { if (((double) longPart) == value) {
// 对于无小数部分的数字类型转为Long // 对于无小数部分的数字类型转为Long

View File

@ -4,7 +4,6 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.setting.dialect.Props; import cn.hutool.setting.dialect.Props;
import lombok.Data; import lombok.Data;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -21,11 +20,6 @@ import java.util.Objects;
*/ */
public class PropsTest { public class PropsTest {
@Before
public void init() {
//LogFactory.setCurrentLogFactory(ConsoleLogFactory.class);
}
@Test @Test
public void propTest() { public void propTest() {
//noinspection MismatchedQueryAndUpdateOfCollection //noinspection MismatchedQueryAndUpdateOfCollection

View File

@ -1,4 +1,4 @@
package cn.hutool.core.img; package cn.hutool.swing.img;
import java.awt.Image; import java.awt.Image;
@ -10,15 +10,25 @@ import java.awt.Image;
*/ */
public enum ScaleType { public enum ScaleType {
/** 默认 */ /**
* 默认
*/
DEFAULT(Image.SCALE_DEFAULT), DEFAULT(Image.SCALE_DEFAULT),
/** 快速 */ /**
* 快速
*/
FAST(Image.SCALE_FAST), FAST(Image.SCALE_FAST),
/** 平滑 */ /**
* 平滑
*/
SMOOTH(Image.SCALE_SMOOTH), SMOOTH(Image.SCALE_SMOOTH),
/** 使用 ReplicateScaleFilter 类中包含的图像缩放算法 */ /**
* 使用 ReplicateScaleFilter 类中包含的图像缩放算法
*/
REPLICATE(Image.SCALE_REPLICATE), REPLICATE(Image.SCALE_REPLICATE),
/** Area Averaging算法 */ /**
* Area Averaging算法
*/
AREA_AVERAGING(Image.SCALE_AREA_AVERAGING); AREA_AVERAGING(Image.SCALE_AREA_AVERAGING);
/** /**
@ -37,6 +47,11 @@ public enum ScaleType {
private final int value; private final int value;
/**
* 获取值
*
* @return
*/
public int getValue() { public int getValue() {
return this.value; return this.value;
} }

View File

@ -296,6 +296,7 @@ public class AnimatedGifEncoder {
public boolean start(final String file) { public boolean start(final String file) {
boolean ok; boolean ok;
try { try {
//noinspection IOStreamConstructor
out = new BufferedOutputStream(new FileOutputStream(file)); out = new BufferedOutputStream(new FileOutputStream(file));
ok = start(out); ok = start(out);
closeStream = true; closeStream = true;
@ -305,6 +306,9 @@ public class AnimatedGifEncoder {
return started = ok; return started = ok;
} }
/**
* @return 是否开始
*/
public boolean isStarted() { public boolean isStarted() {
return started; return started;
} }
@ -339,7 +343,7 @@ public class AnimatedGifEncoder {
pixels = null; pixels = null;
colorDepth = 8; colorDepth = 8;
palSize = 7; palSize = 7;
// get closest match to transparent color if specified // get the closest match to transparent color if specified
if (transparent != null) { if (transparent != null) {
transIndex = transparentExactMatch ? findExact(transparent) : findClosest(transparent); transIndex = transparentExactMatch ? findExact(transparent) : findClosest(transparent);
} }
@ -377,7 +381,7 @@ public class AnimatedGifEncoder {
/** /**
* Returns true if the exact matching color is existing, and used in the color palette, otherwise, return false. * Returns true if the exact matching color is existing, and used in the color palette, otherwise, return false.
* This method has to be called before finishing the image, * This method has to be called before finishing the image,
* because after finished the palette is destroyed and it will always return false. * because after finished the palette is destroyed, and it will always return false.
* *
* @param c 颜色 * @param c 颜色
* @return 颜色是否存在 * @return 颜色是否存在