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>
* eg: <br>
* 若存在元素<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>
@@ -32,7 +32,7 @@ import java.util.stream.Stream;
* <li>被保存的所有{@link AnnotatedElement}上直接声明的注解,及这些注解的元注解;</li>
* <li>若是类,则包括其所有父类和所有父接口上声明的注解和元注解;</li>
* <li>
* 若是方法,且不是静态/私有/被<code>final</code>修饰的方法时,
* 若是方法,且不是静态/私有/被{@code final}修饰的方法时,
* 则额外获取包括其声明类的所有父类和所有父接口中,与该方法具有相同方法签名的方法上的注解和元注解;
* </li>
* </ol>
@@ -69,9 +69,9 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
/**
* 创建一个分层注解元素
*
* @param element 被包装的元素,若元素已是{@link HierarchicalAnnotatedElements},则返回其本身
* @return {@link HierarchicalAnnotatedElements}实例,
* 当{@code element}也是一个{@link HierarchicalAnnotatedElements}时,返回{@code element}本身
* @param element 被包装的元素,若元素已是{@code HierarchicalAnnotatedElements},则返回其本身
* @return {@code HierarchicalAnnotatedElements}实例,
* 当{@code element}也是一个{@code HierarchicalAnnotatedElements}时,返回{@code element}本身
*/
public static HierarchicalAnnotatedElements create(final AnnotatedElement element) {
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}时将忽略该元素
* @return {@link HierarchicalAnnotatedElements}实例,
* 当{@code element}也是一个{@link HierarchicalAnnotatedElements}时,返回{@code element}本身
* @return {@code HierarchicalAnnotatedElements}实例,
* 当{@code element}也是一个{@code HierarchicalAnnotatedElements}时,返回{@code element}本身
*/
public static HierarchicalAnnotatedElements create(
final AnnotatedElement element,
@@ -156,8 +156,6 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
* @param <A> 注解类型
* @return 注解对象
*/
@SuppressWarnings("unchecked")
@Override
public <A extends Annotation> A[] getAnnotationsByType(final Class<A> annotationType) {
return getElementMappings().stream()
.map(e -> e.getAnnotationsByType(annotationType))
@@ -239,14 +237,14 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
* @return 是否
*/
@Override
public boolean equals(Object o) {
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
HierarchicalAnnotatedElements that = (HierarchicalAnnotatedElements)o;
final HierarchicalAnnotatedElements that = (HierarchicalAnnotatedElements)o;
return elementFactory.equals(that.elementFactory) && source.equals(that.source);
}
@@ -294,8 +292,8 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
/**
* 将元素转为{@link MetaAnnotatedElement}后添加至{@code mappings}
*/
private void collectElement(Set<AnnotatedElement> elements, final AnnotatedElement element) {
AnnotatedElement target = elementFactory.apply(elements, element);
private void collectElement(final Set<AnnotatedElement> elements, final AnnotatedElement element) {
final AnnotatedElement target = elementFactory.apply(elements, element);
if (Objects.nonNull(target)) {
elements.add(target);
}
@@ -309,7 +307,7 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
if (Objects.isNull(elementMappings)) {
synchronized (this) {
if (Objects.isNull(elementMappings)) {
Set<AnnotatedElement> mappings = initElementMappings();
final Set<AnnotatedElement> mappings = initElementMappings();
elementMappings = Collections.unmodifiableSet(mappings);
}
}
@@ -320,7 +318,7 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
* 遍历层级结构,获取层级结构中所有关联的{@link AnnotatedElement},并添加到{@link #elementMappings}
*/
private Set<AnnotatedElement> initElementMappings() {
Set<AnnotatedElement> mappings = new LinkedHashSet<>();
final Set<AnnotatedElement> mappings = new LinkedHashSet<>();
// 原始元素是类
if (source instanceof Class) {
scanHierarchy(mappings, (Class<?>)source, false, source);
@@ -344,8 +342,8 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
* 按广度优先,遍历{@code type}的父类以及父接口,并从类上/类中指定方法上获得所需的注解
*/
private void scanHierarchy(
Set<AnnotatedElement> mappings, Class<?> type, final boolean isMethod, final AnnotatedElement source) {
Method methodSource = isMethod ? (Method)source : null;
final Set<AnnotatedElement> mappings, Class<?> type, final boolean isMethod, final AnnotatedElement source) {
final Method methodSource = isMethod ? (Method)source : null;
final Deque<Class<?>> deque = new LinkedList<>();
deque.addLast(type);
final Set<Class<?>> accessed = new HashSet<>();
@@ -379,7 +377,7 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
* <li>该类不为{@link Object}</li>
* </ul>
*/
private boolean isNeedMapping(Class<?> type, Set<Class<?>> accessedTypes) {
private boolean isNeedMapping(final Class<?> type, final Set<Class<?>> accessedTypes) {
return Objects.nonNull(type)
&& !accessedTypes.contains(type)
&& !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.text.CharPool;
import cn.hutool.core.text.StrUtil;
import cn.hutool.core.util.CharUtil;
import java.io.File;
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>
* <li>如需对null友好操作如下</li>
* <li><code>Comparator.nullsLast(CompareUtil.natural())</code></li>
* <li><code>Comparator.nullsFirst(CompareUtil.natural())</code></li>
* <li>{@code Comparator.nullsLast(CompareUtil.natural())}</li>
* <li>{@code Comparator.nullsFirst(CompareUtil.natural())}</li>
* </ul>
*
* @param <E> 排序节点类型
@@ -115,8 +115,8 @@ public class CompareUtil {
*
* <ul>
* <li>如需对null友好操作如下</li>
* <li><code>Comparator.nullsLast(CompareUtil.naturalReverse())</code></li>
* <li><code>Comparator.nullsFirst(CompareUtil.naturalReverse())</code></li>
* <li>{@code Comparator.nullsLast(CompareUtil.naturalReverse())}</li>
* <li>{@code Comparator.nullsFirst(CompareUtil.naturalReverse())}</li>
* </ul>
*
* @param <E> 排序节点类型
@@ -314,7 +314,7 @@ public class CompareUtil {
*
* @param keyExtractor 从对象中提取排序键的函数(参与比较的内容)
* @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 <U> 数组对象类型
* @return 索引比较器

View File

@@ -16,6 +16,7 @@ import cn.hutool.core.math.NumberUtil;
import cn.hutool.core.regex.PatternPool;
import cn.hutool.core.regex.ReUtil;
import cn.hutool.core.text.StrUtil;
import cn.hutool.core.util.CharUtil;
import javax.xml.datatype.XMLGregorianCalendar;
import java.text.DateFormat;
@@ -1624,7 +1625,7 @@ public class DateUtil extends CalendarUtil {
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;
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.text.StrUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.CharUtil;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
@@ -201,9 +202,9 @@ public class ExceptionUtil {
*/
public static String stacktraceToOneLineString(final Throwable throwable, final int limit) {
final Map<Character, String> replaceCharToStrMap = new HashMap<>();
replaceCharToStrMap.put(StrUtil.C_CR, StrUtil.SPACE);
replaceCharToStrMap.put(StrUtil.C_LF, StrUtil.SPACE);
replaceCharToStrMap.put(StrUtil.C_TAB, StrUtil.SPACE);
replaceCharToStrMap.put(CharUtil.CR, StrUtil.SPACE);
replaceCharToStrMap.put(CharUtil.LF, StrUtil.SPACE);
replaceCharToStrMap.put(CharUtil.TAB, StrUtil.SPACE);
return stacktraceToString(throwable, limit, replaceCharToStrMap);
}

View File

@@ -1,5 +1,6 @@
package cn.hutool.core.io;
import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.text.StrUtil;
@@ -166,9 +167,9 @@ public class BufferUtil {
while (buffer.hasRemaining()) {
b = buffer.get();
charIndex++;
if (b == StrUtil.C_CR) {
if (b == CharUtil.CR) {
canEnd = true;
} else if (b == StrUtil.C_LF) {
} else if (b == CharUtil.LF) {
return canEnd ? charIndex - 2 : charIndex - 1;
} else {
// 只有\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) {
// 可能Windows风格路径
prefix = pathToUse.substring(0, prefixIndex + 1);
if (StrUtil.startWith(prefix, StrUtil.C_SLASH)) {
if (StrUtil.startWith(prefix, CharUtil.SLASH)) {
// 去除类似于/C:这类路径开头的斜杠
prefix = prefix.substring(1);
}
@@ -1616,7 +1616,7 @@ public class FileUtil extends PathUtil {
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<>();
int tops = 0;
@@ -1887,6 +1887,7 @@ public class FileUtil extends PathUtil {
*/
public static BOMInputStream getBOMInputStream(final File file) throws IORuntimeException {
try {
//noinspection IOStreamConstructor
return new BOMInputStream(new FileInputStream(file));
} catch (final IOException e) {
throw new IORuntimeException(e);
@@ -2431,6 +2432,7 @@ public class FileUtil extends PathUtil {
public static BufferedOutputStream getOutputStream(final File file) throws IORuntimeException {
final OutputStream out;
try {
//noinspection IOStreamConstructor
out = new FileOutputStream(touch(file));
} catch (final IOException 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();
/**
* 什么也不做,写出到<code>/dev/null</code>.
* 什么也不做,写出到{@code /dev/null}.
*
* @param b 写出的数据
* @param off 开始位置
@@ -30,7 +30,7 @@ public class NullOutputStream extends OutputStream {
}
/**
* 什么也不做,写出到 <code>/dev/null</code>.
* 什么也不做,写出到 {@code /dev/null}.
*
* @param b 写出的数据
*/
@@ -40,7 +40,7 @@ public class NullOutputStream extends OutputStream {
}
/**
* 什么也不做,写出到 <code>/dev/null</code>.
* 什么也不做,写出到 {@code /dev/null}.
*
* @param b 写出的数据
* @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.text.StrUtil;
import cn.hutool.core.net.URLUtil;
import cn.hutool.core.util.CharUtil;
import java.io.File;
import java.io.IOException;
@@ -322,7 +323,7 @@ public class WatchMonitor extends WatchServer {
if (null != lastPathEle) {
final String lastPathEleStr = lastPathEle.toString();
//带有点表示有扩展名按照未创建的文件对待。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.path = this.filePath.getParent();
}

View File

@@ -30,7 +30,7 @@ public class Ansi8BitColor implements AnsiElement {
* @param code 颜色代码(0-255)
* @return 前景色ANSI颜色实例
*/
public static Ansi8BitColor foreground(int code) {
public static Ansi8BitColor foreground(final int code) {
return new Ansi8BitColor(PREFIX_FORE, code);
}
@@ -40,7 +40,7 @@ public class Ansi8BitColor implements AnsiElement {
* @param code 颜色代码(0-255)
* @return 背景色ANSI颜色实例
*/
public static Ansi8BitColor background(int code) {
public static Ansi8BitColor background(final int code) {
return new Ansi8BitColor(PREFIX_BACK, code);
}
@@ -52,9 +52,9 @@ public class Ansi8BitColor implements AnsiElement {
*
* @param prefix 前缀
* @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");
this.prefix = prefix;
this.code = code;
@@ -95,14 +95,14 @@ public class Ansi8BitColor implements AnsiElement {
}
@Override
public boolean equals(Object obj) {
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
Ansi8BitColor other = (Ansi8BitColor) obj;
final Ansi8BitColor other = (Ansi8BitColor) obj;
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 {
/**
* 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
* <code>run</code> method to be called in that separately executing
* {@code run} method to be called in that separately executing
* thread.
* <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.
*
* @throws Exception wrapped checked exceptions
@@ -30,12 +30,12 @@ public interface SerRunnable extends Runnable, Serializable {
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
* <code>run</code> method to be called in that separately executing
* {@code run} method to be called in that separately executing
* thread.
* <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.
*
* @see Thread#run()

View File

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

View File

@@ -544,7 +544,7 @@ public class ClassUtil {
* @return 包名
*/
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> {
/**
* 原始流实例
* 原始流实例
*/
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.ObjUtil;
import java.util.List;
import java.util.Objects;
import java.util.Spliterator;
import java.util.function.*;

View File

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

View File

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

View File

@@ -1,7 +1,5 @@
package cn.hutool.core.text;
import cn.hutool.core.util.XmlUtil;
/**
* 常用字符串常量定义
* @see CharPool
@@ -10,82 +8,6 @@ import cn.hutool.core.util.XmlUtil;
* @since 5.6.3
*/
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"}
*/
@@ -174,37 +96,6 @@ public interface StrPool {
*/
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 "{}"}
*/

View File

@@ -3,6 +3,7 @@ package cn.hutool.core.text.dfa;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.text.StrUtil;
import cn.hutool.core.util.CharUtil;
import java.util.Collection;
import java.util.HashMap;
@@ -17,7 +18,7 @@ import java.util.function.Predicate;
*/
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();
/**

View File

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

View File

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

View File

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

View File

@@ -6,7 +6,6 @@ import lombok.SneakyThrows;
import org.junit.Test;
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.assertFalse(ObjUtil.contains(null, 1));
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(2, 2);
Assert.assertTrue(ObjUtil.contains(map, 1));
Assert.assertTrue(ObjUtil.contains(Arrays.asList(1, 2, 3).iterator(), 2));
}
@SuppressWarnings("ConstantConditions")
@Test
public void isNullTest() {
Assert.assertTrue(ObjUtil.isNull(null));
}
@SuppressWarnings("ConstantConditions")
@Test
public void isNotNullTest() {
Assert.assertFalse(ObjUtil.isNotNull(null));
@@ -124,12 +126,12 @@ public class ObjUtilTest {
Assert.assertSame(val1, ObjUtil.defaultIfNull(val1, Function.identity(), val2));
Assert.assertSame(val2, ObjUtil.defaultIfNull(null, Function.identity(), val2));
SerializableBean obj = new SerializableBean(null);
SerializableBean objNull = null;
String result3 = ObjUtil.defaultIfNull(obj, Object::toString, "fail");
final SerializableBean obj = new SerializableBean(null);
final SerializableBean objNull = null;
final String result3 = ObjUtil.defaultIfNull(obj, Object::toString, "fail");
Assert.assertNotNull(result3);
String result4 = ObjUtil.defaultIfNull(objNull, Object::toString, () -> "fail");
final String result4 = ObjUtil.defaultIfNull(objNull, Object::toString, () -> "fail");
Assert.assertNotNull(result4);
}
@@ -242,6 +244,7 @@ public class ObjUtilTest {
@RequiredArgsConstructor
@EqualsAndHashCode
private static class SerializableBean implements Serializable {
private static final long serialVersionUID = -7759522980793544334L;
private final Integer id;
}
@@ -251,6 +254,7 @@ public class ObjUtilTest {
private final Integer id;
}
@SuppressWarnings("unused")
private interface TypeArgument<A, B> {};
}