This commit is contained in:
Looly
2019-09-28 03:13:27 +08:00
parent daf85caf9e
commit 596a4f1e57
110 changed files with 535 additions and 617 deletions

View File

@@ -1,10 +1,9 @@
package cn.hutool.aop.aspects;
import java.lang.reflect.Method;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.StrUtil;
import java.lang.reflect.Method;
/**
* 通过日志打印方法的执行时间的切面

View File

@@ -1,15 +1,14 @@
package cn.hutool.aop.interceptor;
import cn.hutool.aop.aspects.Aspect;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ReflectUtil;
import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import cn.hutool.aop.aspects.Aspect;
import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ReflectUtil;
/**
* JDK实现的动态代理切面
*

View File

@@ -16,7 +16,7 @@ public interface BloomFilter extends Serializable{
* @param str 字符串
* @return 判断一个字符串是否bitMap中存在
*/
public boolean contains(String str);
boolean contains(String str);
/**
* 在boolean的bitMap中增加一个字符串<br>
@@ -25,5 +25,5 @@ public interface BloomFilter extends Serializable{
* @param str 字符串
* @return 是否加入成功,如果存在就返回<code>false</code> .如果不存在返回<code>true</code>
*/
public boolean add(String str);
boolean add(String str);
}

View File

@@ -8,22 +8,22 @@ package cn.hutool.bloomfilter.bitMap;
*/
public interface BitMap{
public final int MACHINE32 = 32;
public final int MACHINE64 = 64;
int MACHINE32 = 32;
int MACHINE64 = 64;
/**
* 加入值
*
* @param i 值
*/
public void add(long i);
void add(long i);
/**
* 检查是否包含值
*
* @param i 值
*/
public boolean contains(long i);
boolean contains(long i);
/**
* 移除值

View File

@@ -30,7 +30,7 @@ public enum GlobalPruneTimer {
/**
* 构造
*/
private GlobalPruneTimer() {
GlobalPruneTimer() {
create();
}

View File

@@ -44,10 +44,8 @@ public class CacheObj<K, V> implements Serializable{
boolean isExpired() {
if(this.ttl > 0) {
final long expiredTime = this.lastAccess + this.ttl;
if(expiredTime > 0 && expiredTime < System.currentTimeMillis()) {
// expiredTime > 0 杜绝Long类型溢出变负数问题当当前时间超过过期时间表示过期
return true;
}
// expiredTime > 0 杜绝Long类型溢出变负数问题当当前时间超过过期时间表示过期
return expiredTime > 0 && expiredTime < System.currentTimeMillis();
}
return false;
}

View File

@@ -155,7 +155,7 @@ public class ShearCaptcha extends AbstractCaptcha {
* 干扰线
*
* @param g {@link Graphics}
* @param x1x1
* @param x1 x1
* @param y1 y1
* @param x2 x2
* @param y2 y2
@@ -183,8 +183,8 @@ public class ShearCaptcha extends AbstractCaptcha {
int dy = (int) ddy;
// Now we can compute the corner points...
int xPoints[] = new int[4];
int yPoints[] = new int[4];
int[] xPoints = new int[4];
int[] yPoints = new int[4];
xPoints[0] = x1 + dx;
yPoints[0] = y1 + dy;

View File

@@ -14,7 +14,7 @@ public interface CodeGenerator extends Serializable{
*
* @return 验证码
*/
public String generate();
String generate();
/**
* 验证用户输入的字符串是否与生成的验证码匹配<br>
@@ -24,5 +24,5 @@ public interface CodeGenerator extends Serializable{
* @param userInputCode 用户输入的验证码
* @return 是否验证通过
*/
public boolean verify(String code, String userInputCode);
boolean verify(String code, String userInputCode);
}

View File

@@ -23,7 +23,7 @@ public interface ValueProvider<T>{
* @param valueType 被注入的值得类型
* @return 对应参数名的值
*/
public Object value(T key, Type valueType);
Object value(T key, Type valueType);
/**
* 是否包含指定KEY如果不包含则忽略注入<br>
@@ -32,5 +32,5 @@ public interface ValueProvider<T>{
* @param key Bean对象中参数名
* @return 是否包含指定KEY
*/
public boolean containsKey(T key);
boolean containsKey(T key);
}

View File

@@ -12,7 +12,7 @@ import cn.hutool.core.util.ArrayUtil;
/**
* <p>{@link Object#equals(Object)} 方法的构建器</p>
*
*
* <p>两个对象equals必须保证hashCode值相等hashCode值相等不能保证一定equals</p>
*
* <p>使用方法如下:</p>
@@ -152,19 +152,9 @@ public class EqualsBuilder implements Builder<Boolean> {
}
}
/**
* If the fields tested are equals.
* The default value is <code>true</code>.
*/
/** 是否equals此值随着构建会变更默认true */
private boolean isEquals = true;
/**
* <p>Constructor for EqualsBuilder.</p>
*
* <p>Starts off assuming that equals is <code>true</code>.</p>
* @see Object#equals(Object)
*/
/**
* 构造初始状态值为true
*/
@@ -205,7 +195,7 @@ public class EqualsBuilder implements Builder<Boolean> {
* <p>It uses <code>AccessibleObject.setAccessible</code> to gain access to private
* fields. This means that it will throw a security exception if run under
* a security manager, if the permissions are not set up correctly. It is also
* not as efficient as testing explicitly. Non-primitive fields are compared using
* not as efficient as testing explicitly. Non-primitive fields are compared using
* <code>equals()</code>.</p>
*
* <p>If the TestTransients parameter is set to <code>true</code>, transient
@@ -230,7 +220,7 @@ public class EqualsBuilder implements Builder<Boolean> {
* <p>It uses <code>AccessibleObject.setAccessible</code> to gain access to private
* fields. This means that it will throw a security exception if run under
* a security manager, if the permissions are not set up correctly. It is also
* not as efficient as testing explicitly. Non-primitive fields are compared using
* not as efficient as testing explicitly. Non-primitive fields are compared using
* <code>equals()</code>.</p>
*
* <p>If the testTransients parameter is set to <code>true</code>, transient

View File

@@ -21,11 +21,12 @@ public class BCD {
asc = "0" + asc;
len = asc.length();
}
byte abt[] = new byte[len];
byte[] abt;
if (len >= 2) {
len >>= 1;
}
byte bbt[] = new byte[len];
byte[] bbt;
bbt = new byte[len];
abt = asc.getBytes();
int j;
int k;
@@ -82,7 +83,8 @@ public class BCD {
* @return ASCII字符串
*/
public static String bcdToStr(byte[] bytes) {
char temp[] = new char[bytes.length * 2], val;
char[] temp = new char[bytes.length * 2];
char val;
for (int i = 0; i < bytes.length; i++) {
val = (char) (((bytes[i] & 0xf0) >> 4) & 0x0f);

View File

@@ -129,7 +129,7 @@ public class Base62Codec implements Serializable{
* @return 计算结果
*/
private byte[] convert(byte[] message, int sourceBase, int targetBase) {
/** 计算结果长度算法来自http://codegolf.stackexchange.com/a/21672 */
// 计算结果长度算法来自http://codegolf.stackexchange.com/a/21672
final int estimatedLength = estimateOutputLength(message.length, sourceBase, targetBase);
final ByteArrayOutputStream out = new ByteArrayOutputStream(estimatedLength);

View File

@@ -2,7 +2,6 @@ package cn.hutool.core.collection;
import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/**

View File

@@ -17,6 +17,6 @@ public interface Converter<T> {
* @return 转换后的值
* @throws IllegalArgumentException 无法确定目标类型,且默认值为{@code null},无法确定类型
*/
public T convert(Object value, T defaultValue) throws IllegalArgumentException;
T convert(Object value, T defaultValue) throws IllegalArgumentException;
}

View File

@@ -75,7 +75,7 @@ public class BetweenFormater implements Serializable{
}
if(isLevelCountValid(levelCount) && 0 != millisecond && level >= Level.MILLSECOND.ordinal()){
sb.append(millisecond).append(Level.MILLSECOND.name);
levelCount++;
// levelCount++;
}
}
@@ -123,7 +123,7 @@ public class BetweenFormater implements Serializable{
*
* @author Looly
*/
public static enum Level {
public enum Level {
/** 天 */
DAY(""),
@@ -143,7 +143,7 @@ public class BetweenFormater implements Serializable{
* 构造
* @param name 级别名称
*/
private Level(String name) {
Level(String name) {
this.name = name;
}

View File

@@ -105,7 +105,7 @@ public enum DateField {
// ---------------------------------------------------------------
private int value;
private DateField(int value) {
DateField(int value) {
this.value = value;
}

View File

@@ -129,7 +129,7 @@ public class DateModifier {
* @author looly
*
*/
public static enum ModifyType {
public enum ModifyType {
/**
* 取指定日期短的起始值.
*/

View File

@@ -32,7 +32,7 @@ public class DateUtil {
/**
* java.util.Date EEE MMM zzz 缩写数组
*/
private final static String wtb[] = { //
private final static String[] wtb = { //
"sun", "mon", "tue", "wed", "thu", "fri", "sat", // 星期
"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec", //
"gmt", "ut", "utc", "est", "edt", "cst", "cdt", "mst", "mdt", "pst", "pdt"//
@@ -461,7 +461,7 @@ public class DateUtil {
*/
public static LinkedHashSet<String> yearAndQuarter(Date startDate, Date endDate) {
if (startDate == null || endDate == null) {
return new LinkedHashSet<String>(0);
return new LinkedHashSet<>(0);
}
return yearAndQuarter(startDate.getTime(), endDate.getTime());
}
@@ -608,9 +608,9 @@ public class DateUtil {
builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(1, 2)), false));
builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(2, 3)), false));
builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(3, 4)), false));
builder.append(format.substring(4, 5));
builder.append(format, 4, 5);
builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(5, 7)), false));
builder.append(format.substring(7, 8));
builder.append(format, 7, 8);
builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(8, 10)), false));
builder.append(format.substring(10));
format = builder.toString().replace('零', '');
@@ -1888,7 +1888,7 @@ public class DateUtil {
* @param cal 日期
*/
private static String yearAndQuarter(Calendar cal) {
return new StringBuilder().append(cal.get(Calendar.YEAR)).append(cal.get(Calendar.MONTH) / 3 + 1).toString();
return StrUtil.builder().append(cal.get(Calendar.YEAR)).append(cal.get(Calendar.MONTH) / 3 + 1).toString();
}
/**
@@ -1937,7 +1937,7 @@ public class DateUtil {
final StringBuilder builder = StrUtil.builder();
// 日期部分("\"、"/"、"."、"年"、"月"都替换为"-"
String datePart = dateAndTime.get(0).replaceAll("[\\/.年月]", "-");
String datePart = dateAndTime.get(0).replaceAll("[/.年月]", "-");
datePart = StrUtil.removeSuffix(datePart, "");
builder.append(datePart);

View File

@@ -55,7 +55,7 @@ public enum Month {
// ---------------------------------------------------------------
private int value;
private Month(int value) {
Month(int value) {
this.value = value;
}

View File

@@ -25,7 +25,7 @@ public enum Quarter {
// ---------------------------------------------------------------
private int value;
private Quarter(int value) {
Quarter(int value) {
this.value = value;
}

View File

@@ -26,7 +26,7 @@ public enum Season {
// ---------------------------------------------------------------
private int value;
private Season(int value) {
Season(int value) {
this.value = value;
}

View File

@@ -43,7 +43,7 @@ public enum Week {
*
* @param value 星期对应{@link Calendar} 中的Week值
*/
private Week(int value) {
Week(int value) {
this.value = value;
}

View File

@@ -140,7 +140,7 @@ public interface OptBasicTypeGetter<K> {
* @param defaultValue 默认值
* @return Enum类型的值无则返回Null
*/
public <E extends Enum<E>> E getEnum(Class<E> clazz, K key, E defaultValue);
<E extends Enum<E>> E getEnum(Class<E> clazz, K key, E defaultValue);
/**
* 获取Date类型值

View File

@@ -389,8 +389,8 @@ public class ImgUtil {
try {
if (srcWidth > destWidth && srcHeight > destHeight) {
int cols = 0; // 切片横向数量
int rows = 0; // 切片纵向数量
int cols; // 切片横向数量
int rows; // 切片纵向数量
// 计算切片的横向和纵向数量
if (srcWidth % destWidth == 0) {
cols = srcWidth / destWidth;
@@ -1772,7 +1772,7 @@ public class ImgUtil {
return Color.LIGHT_GRAY;
} else if ("GRAY".equals(colorName)) {
return Color.GRAY;
} else if ("DARK_GRAY".equals(colorName) || "DARK_GRAY".equals(colorName)) {
} else if ("DARKGRAY".equals(colorName) || "DARK_GRAY".equals(colorName)) {
return Color.DARK_GRAY;
} else if ("RED".equals(colorName)) {
return Color.RED;

View File

@@ -31,7 +31,7 @@ public enum ScaleType {
* @see Image#SCALE_REPLICATE
* @see Image#SCALE_AREA_AVERAGING
*/
private ScaleType(int value) {
ScaleType(int value) {
this.value = value;
}

View File

@@ -82,7 +82,7 @@ public class BOMInputStream extends InputStream {
return;
}
byte bom[] = new byte[BOM_SIZE];
byte[] bom = new byte[BOM_SIZE];
int n, unread;
n = in.read(bom, 0, bom.length);

View File

@@ -19,10 +19,7 @@ import cn.hutool.core.util.StrUtil;
* @author Looly
*
*/
public final class FileTypeUtil {
private FileTypeUtil() {
};
public class FileTypeUtil {
private static final Map<String, String> fileTypeMap;
@@ -42,7 +39,6 @@ public final class FileTypeUtil {
fileTypeMap.put("38425053000100000000", "psd"); // Photoshop (psd)
fileTypeMap.put("46726f6d3a203d3f6762", "eml"); // Email [Outlook Express 6] (eml)
fileTypeMap.put("d0cf11e0a1b11ae10000", "doc"); // MS Excel 注意word、msi 和 excel的文件头一样
fileTypeMap.put("d0cf11e0a1b11ae10000", "vsd"); // Visio 绘图
fileTypeMap.put("5374616E64617264204A", "mdb"); // MS Access (mdb)
fileTypeMap.put("252150532D41646F6265", "ps");
fileTypeMap.put("255044462d312e", "pdf"); // Adobe Acrobat (pdf)
@@ -70,7 +66,6 @@ public final class FileTypeUtil {
fileTypeMap.put("cafebabe0000002e0041", "class");// bat文件
fileTypeMap.put("49545346030000006000", "chm");// bat文件
fileTypeMap.put("04000000010000001300", "mxp");// bat文件
fileTypeMap.put("d0cf11e0a1b11ae10000", "wps");// WPS文字wps、表格et、演示dps都是一样的
fileTypeMap.put("6431303a637265617465", "torrent");
fileTypeMap.put("6D6F6F76", "mov"); // Quicktime (mov)
fileTypeMap.put("FF575043", "wpd"); // WordPerfect (wpd)

View File

@@ -31,6 +31,7 @@ import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.Objects;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import java.util.zip.Checksum;
@@ -170,7 +171,7 @@ public class IoUtil {
}
long size = 0;
try {
for (int readSize = -1; (readSize = in.read(buffer)) != EOF;) {
for (int readSize; (readSize = in.read(buffer)) != EOF;) {
out.write(buffer, 0, readSize);
size += readSize;
out.flush();
@@ -314,7 +315,7 @@ public class IoUtil {
return null;
}
InputStreamReader reader = null;
InputStreamReader reader;
if (null == charset) {
reader = new InputStreamReader(in);
} else {
@@ -605,7 +606,7 @@ public class IoUtil {
if (in == null) {
throw new IllegalArgumentException("The InputStream must not be null");
}
ObjectInputStream ois = null;
ObjectInputStream ois;
try {
ois = new ObjectInputStream(in);
@SuppressWarnings("unchecked") // may fail with CCE if serialised form is incorrect
@@ -717,7 +718,7 @@ public class IoUtil {
// 从返回的内容中读取所需内容
final BufferedReader bReader = getReader(reader);
String line = null;
String line;
try {
while ((line = bReader.readLine()) != null) {
lineHandler.handle(line);
@@ -1092,11 +1093,11 @@ public class IoUtil {
try {
String line1 = br1.readLine();
String line2 = br2.readLine();
while (line1 != null && line2 != null && line1.equals(line2)) {
while (line1 != null && line1.equals(line2)) {
line1 = br1.readLine();
line2 = br2.readLine();
}
return line1 == null ? line2 == null ? true : false : line1.equals(line2);
return Objects.equals(line1, line2);
} catch (IOException e) {
throw new IORuntimeException(e);
}

View File

@@ -10,16 +10,16 @@ public interface StreamProgress {
/**
* 开始
*/
public void start();
void start();
/**
* 进行中
* @param progressSize 已经进行的大小
*/
public void progress(long progressSize);
void progress(long progressSize);
/**
* 结束
*/
public void finish();
void finish();
}

View File

@@ -216,7 +216,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
throw new IORuntimeException(StrUtil.format("Src [{}] is a directory but dest [{}] is a file!", src.getPath(), dest.getPath()));
}
final String files[] = src.list();
final String[] files = src.list();
File srcFile;
File destFile;
for (String file : files) {

View File

@@ -14,6 +14,6 @@ public enum FileMode {
/** 打开以便读取和写入。相对于 "rw""rws" 还要求对“文件的内容”或“元数据”的每个更新都同步写入到基础存储设备。 */
rws,
/** 打开以便读取和写入,相对于 "rw""rwd" 还要求对“文件的内容”的每个更新都同步写入到基础存储设备。 */
rwd;
rwd
}

View File

@@ -209,7 +209,7 @@ public class FileReader extends FileWrapper {
*/
public <T> T read(ReaderHandler<T> readerHandler) throws IORuntimeException {
BufferedReader reader = null;
T result = null;
T result;
try {
reader = FileUtil.getReader(this.file, charset);
result = readerHandler.handle(reader);
@@ -274,7 +274,7 @@ public class FileReader extends FileWrapper {
* @param <T> Reader处理返回结果类型
*/
public interface ReaderHandler<T> {
public T handle(BufferedReader reader) throws IOException;
T handle(BufferedReader reader) throws IOException;
}
// -------------------------------------------------------------------------- Interface end

View File

@@ -25,7 +25,7 @@ public enum LineSeparator {
private String value;
private LineSeparator(String lineSeparator) {
LineSeparator(String lineSeparator) {
this.value = lineSeparator;
}

View File

@@ -41,7 +41,7 @@ public class NoResourceException extends IORuntimeException {
*/
public boolean causeInstanceOf(Class<? extends Throwable> clazz) {
Throwable cause = this.getCause();
if (null != cause && clazz.isInstance(cause)) {
if (clazz.isInstance(cause)) {
return true;
}
return false;

View File

@@ -13,7 +13,7 @@ public interface Watcher {
* @param event 事件
* @param currentPath 事件发生的当前Path路径
*/
public void onCreate(WatchEvent<?> event, Path currentPath);
void onCreate(WatchEvent<?> event, Path currentPath);
/**
* 文件修改时执行的方法<br>
@@ -21,19 +21,19 @@ public interface Watcher {
* @param event 事件
* @param currentPath 事件发生的当前Path路径
*/
public void onModify(WatchEvent<?> event, Path currentPath);
void onModify(WatchEvent<?> event, Path currentPath);
/**
* 文件删除时执行的方法
* @param event 事件
* @param currentPath 事件发生的当前Path路径
*/
public void onDelete(WatchEvent<?> event, Path currentPath);
void onDelete(WatchEvent<?> event, Path currentPath);
/**
* 事件丢失或出错时执行的方法
* @param event 事件
* @param currentPath 事件发生的当前Path路径
*/
public void onOverflow(WatchEvent<?> event, Path currentPath);
void onOverflow(WatchEvent<?> event, Path currentPath);
}

View File

@@ -108,6 +108,6 @@ public class ConsistentHash<T> implements Serializable{
*
*/
public interface HashFunc {
public Integer hash(Object key);
Integer hash(Object key);
}
}

View File

@@ -19,5 +19,5 @@ public interface Editor<T> {
* @param t 被过滤的对象
* @return 修改后的对象,如果被过滤返回<code>null</code>
*/
public T edit(T t);
T edit(T t);
}

View File

@@ -12,5 +12,5 @@ public interface Matcher<T>{
* @param t 对象
* @return 是否匹配
*/
public boolean match(T t);
boolean match(T t);
}

View File

@@ -196,7 +196,7 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
*
* @param <T> 需要增加步进的对象
*/
public static interface Steper<T> {
public interface Steper<T> {
/**
* 增加步进<br>
* 增加步进后的返回值如果为{@code null}则表示步进结束<br>

View File

@@ -17,5 +17,5 @@ public interface Replacer<T> {
* @param t 被替换的对象
* @return 替代后的对象
*/
public T replace(T t);
T replace(T t);
}

View File

@@ -55,16 +55,16 @@ public class NetUtil {
* @return IP V4 地址
*/
public static String longToIpv4(long longIP) {
final StringBuilder sb = new StringBuilder();
final StringBuilder sb = StrUtil.builder();
// 直接右移24位
sb.append(String.valueOf(longIP >>> 24));
sb.append((longIP >>> 24));
sb.append(".");
// 将高8位置0然后右移16位
sb.append(String.valueOf((longIP & 0x00FFFFFF) >>> 16));
sb.append(((longIP & 0x00FFFFFF) >>> 16));
sb.append(".");
sb.append(String.valueOf((longIP & 0x0000FFFF) >>> 8));
sb.append(((longIP & 0x0000FFFF) >>> 8));
sb.append(".");
sb.append(String.valueOf(longIP & 0x000000FF));
sb.append((longIP & 0x000000FF));
return sb.toString();
}
@@ -202,7 +202,7 @@ public class NetUtil {
* @return 是否为内网IP
*/
public static boolean isInnerIP(String ipAddress) {
boolean isInnerIp = false;
boolean isInnerIp;
long ipNum = NetUtil.ipv4ToLong(ipAddress);
long aBegin = NetUtil.ipv4ToLong("10.0.0.0");
@@ -241,7 +241,7 @@ public class NetUtil {
* @return 隐藏部分后的IP
*/
public static String hideIpPart(String ip) {
return new StringBuffer(ip.length()).append(ip.substring(0, ip.lastIndexOf(".") + 1)).append("*").toString();
return StrUtil.builder(ip.length()).append(ip, 0, ip.lastIndexOf(".") + 1).append("*").toString();
}
/**
@@ -268,8 +268,8 @@ public class NetUtil {
host = LOCAL_IP;
}
String destHost = null;
int port = 0;
String destHost;
int port;
int index = host.indexOf(":");
if (index != -1) {
// host:port形式
@@ -304,7 +304,7 @@ public class NetUtil {
* @since 3.0.1
*/
public static Collection<NetworkInterface> getNetworkInterfaces() {
Enumeration<NetworkInterface> networkInterfaces = null;
Enumeration<NetworkInterface> networkInterfaces;
try {
networkInterfaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) {
@@ -386,7 +386,7 @@ public class NetUtil {
* @since 4.5.17
*/
public static LinkedHashSet<InetAddress> localAddressList(Filter<InetAddress> addressFilter) {
Enumeration<NetworkInterface> networkInterfaces = null;
Enumeration<NetworkInterface> networkInterfaces;
try {
networkInterfaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) {
@@ -460,8 +460,7 @@ public class NetUtil {
});
if (CollUtil.isNotEmpty(localAddressList)) {
InetAddress address = CollUtil.get(localAddressList, 0);
return address;
return CollUtil.get(localAddressList, 0);
}
try {
@@ -568,7 +567,7 @@ public class NetUtil {
* @param host Server主机
* @param port Server端口
* @param data 数据
* @throws IOException IO异常
* @throws IORuntimeException IO异常
* @since 3.3.0
*/
public static void netCat(String host, int port, byte[] data) throws IORuntimeException {

View File

@@ -39,7 +39,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
/**
* 构造尝试获取剪贴板内容的次数为10第二次之后延迟100毫秒
*/
private ClipboardMonitor() {
ClipboardMonitor() {
this(DEFAULT_TRY_COUNT, DEFAULT_DELAY);
}
@@ -49,7 +49,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
* @param tryCount 尝试获取剪贴板内容的次数
* @param delay 响应延迟当从第二次开始延迟一定毫秒数等待剪贴板可以获取当tryCount小于2时无效
*/
private ClipboardMonitor(int tryCount, long delay) {
ClipboardMonitor(int tryCount, long delay) {
this(tryCount, delay, ClipboardUtil.getClipboard());
}
@@ -60,7 +60,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
* @param delay 响应延迟当从第二次开始延迟一定毫秒数等待剪贴板可以获取当tryCount小于2时无效
* @param clipboard 剪贴板对象
*/
private ClipboardMonitor(int tryCount, long delay, Clipboard clipboard) {
ClipboardMonitor(int tryCount, long delay, Clipboard clipboard) {
this.tryCount = tryCount;
this.delay = delay;
this.clipboard = clipboard;

View File

@@ -25,7 +25,7 @@ public enum RejectPolicy {
private RejectedExecutionHandler value;
private RejectPolicy(RejectedExecutionHandler handler) {
RejectPolicy(RejectedExecutionHandler handler) {
this.value = handler;
}

View File

@@ -77,9 +77,7 @@ public class BooleanUtil {
public static boolean toBoolean(String valueStr) {
if (StrUtil.isNotBlank(valueStr)) {
valueStr = valueStr.trim().toLowerCase();
if (ArrayUtil.contains(TRUE_ARRAY, valueStr)) {
return true;
}
return ArrayUtil.contains(TRUE_ARRAY, valueStr);
}
return false;
}

View File

@@ -27,15 +27,14 @@ import cn.hutool.core.lang.Singleton;
/**
* 类工具类 <br>
*
* @author xiaoleilu
*
* @author xiaoleilu
*/
public class ClassUtil {
/**
* {@code null}安全的获取对象类型
*
*
* @param <T> 对象类型
* @param obj 对象,如果为{@code null} 返回{@code null}
* @return 对象类型,提供对象如果为{@code null} 返回{@code null}
@@ -48,7 +47,7 @@ public class ClassUtil {
/**
* 获得外围类<br>
* 返回定义此类或匿名类所在的类,如果类本身是在包中定义的,返回{@code null}
*
*
* @param clazz 类
* @return 外围类
* @since 4.5.7
@@ -59,7 +58,7 @@ public class ClassUtil {
/**
* 是否为顶层类,既定义在包中的类,而非定义在类中的内部类
*
*
* @param clazz 类
* @return 是否为顶层类
* @since 4.5.7
@@ -73,8 +72,8 @@ public class ClassUtil {
/**
* 获取类名
*
* @param obj 获取类名对象
*
* @param obj 获取类名对象
* @param isSimple 是否简单类名如果为true返回不带包名的类名
* @return 类名
* @since 3.0.7
@@ -91,13 +90,13 @@ public class ClassUtil {
* 获取类名<br>
* 类名并不包含“.class”这个扩展名<br>
* 例如ClassUtil这个类<br>
*
*
* <pre>
* isSimple为false: "com.xiaoleilu.hutool.util.ClassUtil"
* isSimple为true: "ClassUtil"
* </pre>
*
* @param clazz 类
*
* @param clazz
* @param isSimple 是否简单类名如果为true返回不带包名的类名
* @return 类名
* @since 3.0.7
@@ -112,7 +111,7 @@ public class ClassUtil {
/**
* 获取完整类名的短格式如:<br>
* cn.hutool.core.util.StrUtil -》c.h.c.u.StrUtil
*
*
* @param className 类名
* @return 短格式类名
* @since 4.1.9
@@ -135,7 +134,7 @@ public class ClassUtil {
/**
* 获得对象数组的类数组
*
*
* @param objects 对象数组,如果数组中存在{@code null}元素则此元素被认为是Object类型
* @return 类数组
*/
@@ -151,9 +150,9 @@ public class ClassUtil {
/**
* 指定类是否与给定的类名相同
*
* @param clazz 类
* @param className 类名,可以是全类名(包含包名),也可以是简单类名(不包含包名)
*
* @param clazz
* @param className 类名,可以是全类名(包含包名),也可以是简单类名(不包含包名)
* @param ignoreCase 是否忽略大小写
* @return 指定类是否与给定的类名相同
* @since 3.0.7
@@ -170,10 +169,11 @@ public class ClassUtil {
}
// ----------------------------------------------------------------------------------------- Scan classes
/**
* 扫描指定包路径下所有包含指定注解的类
*
* @param packageName 包路径
*
* @param packageName 包路径
* @param annotationClass 注解类
* @return 类集合
* @see ClassScaner#scanPackageByAnnotation(String, Class)
@@ -184,9 +184,9 @@ public class ClassUtil {
/**
* 扫描指定包路径下所有指定类或接口的子类或实现类
*
*
* @param packageName 包路径
* @param superClass 父类或接口
* @param superClass 父类或接口
* @return 类集合
* @see ClassScaner#scanPackageBySuper(String, Class)
*/
@@ -196,7 +196,7 @@ public class ClassUtil {
/**
* 扫面该包路径下所有class文件
*
*
* @return 类集合
* @see ClassScaner#scanPackage()
*/
@@ -206,7 +206,7 @@ public class ClassUtil {
/**
* 扫面该包路径下所有class文件
*
*
* @param packageName 包路径 com | com. | com.abs | com.abs.
* @return 类集合
* @see ClassScaner#scanPackage(String)
@@ -219,7 +219,7 @@ public class ClassUtil {
* 扫面包路径下满足class过滤器条件的所有class文件<br>
* 如果包路径为 com.abs + A.class 但是输入 abs会产生classNotFoundException<br>
* 因为className 应该为 com.abs.A 现在却成为abs.A,此工具类对该异常进行忽略处理,有可能是一个不完善的地方,以后需要进行修改<br>
*
*
* @param packageName 包路径 com | com. | com.abs | com.abs.
* @param classFilter class过滤器过滤掉不需要的class
* @return 类集合
@@ -229,10 +229,11 @@ public class ClassUtil {
}
// ----------------------------------------------------------------------------------------- Method
/**
* 获得指定类中的Public方法名<br>
* 去重重载的方法
*
*
* @param clazz 类
* @return 方法名Set
*/
@@ -242,7 +243,7 @@ public class ClassUtil {
/**
* 获得本类及其父类所有Public方法
*
*
* @param clazz 查找方法的类
* @return 过滤后的方法列表
*/
@@ -252,8 +253,8 @@ public class ClassUtil {
/**
* 获得指定类过滤后的Public方法列表
*
* @param clazz 查找方法的类
*
* @param clazz 查找方法的类
* @param filter 过滤器
* @return 过滤后的方法列表
*/
@@ -263,8 +264,8 @@ public class ClassUtil {
/**
* 获得指定类过滤后的Public方法列表
*
* @param clazz 查找方法的类
*
* @param clazz 查找方法的类
* @param excludeMethods 不包括的方法
* @return 过滤后的方法列表
*/
@@ -274,19 +275,19 @@ public class ClassUtil {
/**
* 获得指定类过滤后的Public方法列表
*
* @param clazz 查找方法的类
*
* @param clazz 查找方法的类
* @param excludeMethodNames 不包括的方法名列表
* @return 过滤后的方法列表
*/
public static List<Method> getPublicMethods(Class<?> clazz, String... excludeMethodNames) {
return getPublicMethods(clazz, excludeMethodNames);
return ReflectUtil.getPublicMethods(clazz, excludeMethodNames);
}
/**
* 查找指定Public方法 如果找不到对应的方法或方法不为public的则返回<code>null</code>
*
* @param clazz 类
*
* @param clazz
* @param methodName 方法名
* @param paramTypes 参数类型
* @return 方法
@@ -299,7 +300,7 @@ public class ClassUtil {
/**
* 获得指定类中的Public方法名<br>
* 去重重载的方法
*
*
* @param clazz 类
* @return 方法名Set
*/
@@ -309,7 +310,7 @@ public class ClassUtil {
/**
* 获得声明的所有方法包括本类及其父类和接口的所有方法和Object类的方法
*
*
* @param clazz 类
* @return 方法数组
*/
@@ -319,10 +320,10 @@ public class ClassUtil {
/**
* 查找指定对象中的所有方法包括非public方法也包括父对象和Object类的方法
*
* @param obj 被查找的对象
*
* @param obj 被查找的对象
* @param methodName 方法名
* @param args 参数
* @param args 参数
* @return 方法
* @throws SecurityException 无访问权限抛出异常
*/
@@ -332,9 +333,9 @@ public class ClassUtil {
/**
* 查找指定类中的所有方法包括非public方法也包括父类和Object类的方法 找不到方法会返回<code>null</code>
*
* @param clazz 被查找的类
* @param methodName 方法名
*
* @param clazz 被查找的类
* @param methodName 方法名
* @param parameterTypes 参数类型
* @return 方法
* @throws SecurityException 无访问权限抛出异常
@@ -344,10 +345,11 @@ public class ClassUtil {
}
// ----------------------------------------------------------------------------------------- Field
/**
* 查找指定类中的所有字段包括非public字段 字段不存在则返回<code>null</code>
*
* @param clazz 被查找字段的类
*
* @param clazz 被查找字段的类
* @param fieldName 字段名
* @return 字段
* @throws SecurityException 安全异常
@@ -366,7 +368,7 @@ public class ClassUtil {
/**
* 查找指定类中的所有字段包括非public字段)
*
*
* @param clazz 被查找字段的类
* @return 字段
* @throws SecurityException 安全异常
@@ -379,9 +381,10 @@ public class ClassUtil {
}
// ----------------------------------------------------------------------------------------- Classpath
/**
* 获得ClassPath不解码路径中的特殊字符例如空格和中文
*
*
* @return ClassPath集合
*/
public static Set<String> getClassPathResources() {
@@ -390,7 +393,7 @@ public class ClassUtil {
/**
* 获得ClassPath
*
*
* @param isDecode 是否解码路径中的特殊字符(例如空格和中文)
* @return ClassPath集合
* @since 4.0.11
@@ -401,7 +404,7 @@ public class ClassUtil {
/**
* 获得ClassPath不解码路径中的特殊字符例如空格和中文
*
*
* @param packageName 包名称
* @return ClassPath路径字符串集合
*/
@@ -411,9 +414,9 @@ public class ClassUtil {
/**
* 获得ClassPath
*
*
* @param packageName 包名称
* @param isDecode 是否解码路径中的特殊字符(例如空格和中文)
* @param isDecode 是否解码路径中的特殊字符(例如空格和中文)
* @return ClassPath路径字符串集合
* @since 4.0.11
*/
@@ -425,7 +428,7 @@ public class ClassUtil {
} catch (IOException e) {
throw new UtilException(e, "Loading classPath [{}] error!", packagePath);
}
final Set<String> paths = new HashSet<String>();
final Set<String> paths = new HashSet<>();
String path;
while (resources.hasMoreElements()) {
path = resources.nextElement().getPath();
@@ -437,7 +440,7 @@ public class ClassUtil {
/**
* 获得ClassPath将编码后的中文路径解码为原字符<br>
* 这个ClassPath路径会文件路径被标准化处理
*
*
* @return ClassPath
*/
public static String getClassPath() {
@@ -446,7 +449,7 @@ public class ClassUtil {
/**
* 获得ClassPath这个ClassPath路径会文件路径被标准化处理
*
*
* @param isEncoded 是否编码路径中的中文
* @return ClassPath
* @since 3.2.1
@@ -459,7 +462,7 @@ public class ClassUtil {
/**
* 获得ClassPath URL
*
*
* @return ClassPath URL
*/
public static URL getClassPathURL() {
@@ -469,12 +472,12 @@ public class ClassUtil {
/**
* 获得资源的URL<br>
* 路径用/分隔,例如:
*
*
* <pre>
* config/a/db.config
* spring/xml/test.xml
* </pre>
*
*
* @param resource 资源相对Classpath的路径
* @return 资源URL
* @see ResourceUtil#getResource(String)
@@ -486,12 +489,12 @@ public class ClassUtil {
/**
* 获取指定路径下的资源列表<br>
* 路径格式必须为目录格式,用/分隔,例如:
*
*
* <pre>
* config/a
* spring/xml
* </pre>
*
*
* @param resource 资源路径
* @return 资源列表
* @see ResourceUtil#getResources(String)
@@ -502,8 +505,8 @@ public class ClassUtil {
/**
* 获得资源相对路径对应的URL
*
* @param resource 资源相对路径
*
* @param resource 资源相对路径
* @param baseClass 基准Class获得的相对路径相对于此Class所在路径如果为{@code null}则相对ClassPath
* @return {@link URL}
* @see ResourceUtil#getResource(String, Class)
@@ -521,7 +524,7 @@ public class ClassUtil {
/**
* 获取当前线程的{@link ClassLoader}
*
*
* @return 当前线程的class loader
* @see ClassLoaderUtil#getClassLoader()
*/
@@ -532,13 +535,13 @@ public class ClassUtil {
/**
* 获取{@link ClassLoader}<br>
* 获取顺序如下:<br>
*
*
* <pre>
* 1、获取当前线程的ContextClassLoader
* 2、获取{@link ClassUtil}类对应的ClassLoader
* 3、获取系统ClassLoader{@link ClassLoader#getSystemClassLoader()}
* </pre>
*
*
* @return 类加载器
*/
public static ClassLoader getClassLoader() {
@@ -547,7 +550,7 @@ public class ClassUtil {
/**
* 比较判断types1和types2两组类如果types1中所有的类都与types2对应位置的类相同或者是其父类或接口则返回<code>true</code>
*
*
* @param types1 类组1
* @param types2 类组2
* @return 是否相同、父类或接口
@@ -583,9 +586,9 @@ public class ClassUtil {
/**
* 加载类
*
* @param <T> 对象类型
* @param className 类名
*
* @param <T> 对象类型
* @param className 类名
* @param isInitialized 是否初始化
* @return 类
*/
@@ -596,8 +599,8 @@ public class ClassUtil {
/**
* 加载类并初始化
*
* @param <T> 对象类型
*
* @param <T> 对象类型
* @param className 类名
* @return 类
*/
@@ -606,15 +609,16 @@ public class ClassUtil {
}
// ---------------------------------------------------------------------------------------------------- Invoke start
/**
* 执行方法<br>
* 可执行Private方法也可执行static方法<br>
* 执行非static方法时必须满足对象有默认构造方法<br>
* 非单例模式,如果是非静态方法,每次创建一个新对象
*
* @param <T> 对象类型
*
* @param <T> 对象类型
* @param classNameWithMethodName 类名和方法名表达式,类名与方法名用<code>.</code>或<code>#</code>连接 例如com.xiaoleilu.hutool.StrUtil.isEmpty 或 com.xiaoleilu.hutool.StrUtil#isEmpty
* @param args 参数,必须严格对应指定方法的参数类型和数量
* @param args 参数,必须严格对应指定方法的参数类型和数量
* @return 返回结果
*/
public static <T> T invoke(String classNameWithMethodName, Object[] args) {
@@ -625,11 +629,11 @@ public class ClassUtil {
* 执行方法<br>
* 可执行Private方法也可执行static方法<br>
* 执行非static方法时必须满足对象有默认构造方法<br>
*
* @param <T> 对象类型
*
* @param <T> 对象类型
* @param classNameWithMethodName 类名和方法名表达式例如com.xiaoleilu.hutool.StrUtil#isEmpty或com.xiaoleilu.hutool.StrUtil.isEmpty
* @param isSingleton 是否为单例对象如果此参数为false每次执行方法时创建一个新对象
* @param args 参数,必须严格对应指定方法的参数类型和数量
* @param isSingleton 是否为单例对象如果此参数为false每次执行方法时创建一个新对象
* @param args 参数,必须严格对应指定方法的参数类型和数量
* @return 返回结果
*/
public static <T> T invoke(String classNameWithMethodName, boolean isSingleton, Object... args) {
@@ -656,11 +660,11 @@ public class ClassUtil {
* 可执行Private方法也可执行static方法<br>
* 执行非static方法时必须满足对象有默认构造方法<br>
* 非单例模式,如果是非静态方法,每次创建一个新对象
*
* @param <T> 对象类型
* @param className 类名,完整类路径
*
* @param <T> 对象类型
* @param className 类名,完整类路径
* @param methodName 方法名
* @param args 参数,必须严格对应指定方法的参数类型和数量
* @param args 参数,必须严格对应指定方法的参数类型和数量
* @return 返回结果
*/
public static <T> T invoke(String className, String methodName, Object[] args) {
@@ -671,12 +675,12 @@ public class ClassUtil {
* 执行方法<br>
* 可执行Private方法也可执行static方法<br>
* 执行非static方法时必须满足对象有默认构造方法<br>
*
* @param <T> 对象类型
* @param className 类名,完整类路径
* @param methodName 方法名
*
* @param <T> 对象类型
* @param className 类名,完整类路径
* @param methodName 方法名
* @param isSingleton 是否为单例对象如果此参数为false每次执行方法时创建一个新对象
* @param args 参数,必须严格对应指定方法的参数类型和数量
* @param args 参数,必须严格对应指定方法的参数类型和数量
* @return 返回结果
*/
public static <T> T invoke(String className, String methodName, boolean isSingleton, Object... args) {
@@ -700,7 +704,7 @@ public class ClassUtil {
/**
* 是否为包装类型
*
*
* @param clazz 类
* @return 是否为包装类型
*/
@@ -713,7 +717,7 @@ public class ClassUtil {
/**
* 是否为基本类型(包括包装类和原始类)
*
*
* @param clazz 类
* @return 是否为基本类型
*/
@@ -727,7 +731,7 @@ public class ClassUtil {
/**
* 是否简单值类型或简单值类型的数组<br>
* 包括:原始类型,、String、other CharSequence, a Number, a Date, a URI, a URL, a Locale or a Class及其数组
*
*
* @param clazz 属性类
* @return 是否简单值类型或简单值类型的数组
*/
@@ -741,7 +745,7 @@ public class ClassUtil {
/**
* 是否为简单值类型<br>
* 包括:原始类型,、String、other CharSequence, a Number, a Date, a URI, a URL, a Locale or a Class.
*
*
* @param clazz 类
* @return 是否为简单值类型
*/
@@ -763,7 +767,7 @@ public class ClassUtil {
* 1、原类是对象目标类型是原类型实现的接口<br>
* 2、目标类型是原类型的父类<br>
* 3、两者是原始类型或者包装类型相互转换
*
*
* @param targetType 目标类型
* @param sourceType 原类型
* @return 是否可转化
@@ -782,22 +786,17 @@ public class ClassUtil {
if (targetType.isPrimitive()) {
// 原始类型
Class<?> resolvedPrimitive = BasicType.wrapperPrimitiveMap.get(sourceType);
if (resolvedPrimitive != null && targetType.equals(resolvedPrimitive)) {
return true;
}
return targetType.equals(resolvedPrimitive);
} else {
// 包装类型
Class<?> resolvedWrapper = BasicType.primitiveWrapperMap.get(sourceType);
if (resolvedWrapper != null && targetType.isAssignableFrom(resolvedWrapper)) {
return true;
}
return resolvedWrapper != null && targetType.isAssignableFrom(resolvedWrapper);
}
return false;
}
/**
* 指定类是否为Public
*
*
* @param clazz 类
* @return 是否为public
*/
@@ -810,7 +809,7 @@ public class ClassUtil {
/**
* 指定方法是否为Public
*
*
* @param method 方法
* @return 是否为public
*/
@@ -821,7 +820,7 @@ public class ClassUtil {
/**
* 指定类是否为非public
*
*
* @param clazz 类
* @return 是否为非public
*/
@@ -831,7 +830,7 @@ public class ClassUtil {
/**
* 指定方法是否为非public
*
*
* @param method 方法
* @return 是否为非public
*/
@@ -841,7 +840,7 @@ public class ClassUtil {
/**
* 是否为静态方法
*
*
* @param method 方法
* @return 是否为静态方法
*/
@@ -852,7 +851,7 @@ public class ClassUtil {
/**
* 设置方法为可访问
*
*
* @param method 方法
* @return 方法
*/
@@ -865,7 +864,7 @@ public class ClassUtil {
/**
* 是否为抽象类
*
*
* @param clazz 类
* @return 是否为抽象类
*/
@@ -876,16 +875,16 @@ public class ClassUtil {
/**
* 是否为标准的类<br>
* 这个类必须:
*
*
* <pre>
* 1、非接口
* 2、非抽象类
* 3、非Enum枚举
* 4、非数组
* 5、非注解
* 1、非接口
* 2、非抽象类
* 3、非Enum枚举
* 4、非数组
* 5、非注解
* 6、非原始类型int, long等
* </pre>
*
*
* @param clazz 类
* @return 是否为标准类
*/
@@ -902,18 +901,18 @@ public class ClassUtil {
/**
* 判断类是否为枚举类型
*
*
* @param clazz 类
* @return 是否为枚举类型
* @since 3.2.0
*/
public static boolean isEnum(Class<?> clazz) {
return null == clazz ? false : clazz.isEnum();
return null != clazz && clazz.isEnum();
}
/**
* 获得给定类的第一个泛型参数
*
*
* @param clazz 被检查的类,必须是已经确定泛型类型的类
* @return {@link Class}
*/
@@ -923,14 +922,14 @@ public class ClassUtil {
/**
* 获得给定类的泛型参数
*
*
* @param clazz 被检查的类,必须是已经确定泛型类型的类
* @param index 泛型类型的索引号,既第几个泛型类型
* @return {@link Class}
*/
public static Class<?> getTypeArgument(Class<?> clazz, int index) {
final Type argumentType = TypeUtil.getTypeArgument(clazz, index);
if (null != argumentType && argumentType instanceof Class) {
if (argumentType instanceof Class) {
return (Class<?>) argumentType;
}
return null;
@@ -940,7 +939,7 @@ public class ClassUtil {
* 获得给定类所在包的名称<br>
* 例如:<br>
* com.xiaoleilu.hutool.util.ClassUtil =》 com.xiaoleilu.hutool.util
*
*
* @param clazz 类
* @return 包名
*/
@@ -960,7 +959,7 @@ public class ClassUtil {
* 获得给定类所在包的路径<br>
* 例如:<br>
* com.xiaoleilu.hutool.util.ClassUtil =》 com/xiaoleilu/hutool/util
*
*
* @param clazz 类
* @return 包名
*/
@@ -971,12 +970,12 @@ public class ClassUtil {
/**
* 获取指定类型分的默认值<br>
* 默认值规则为:
*
*
* <pre>
* 1、如果为原始类型返回0
* 2、非原始类型返回{@code null}
* </pre>
*
*
* @param clazz 类
* @return 默认值
* @since 3.0.8
@@ -1007,7 +1006,7 @@ public class ClassUtil {
/**
* 获得默认值列表
*
*
* @param classes 值类型
* @return 默认值列表
* @since 3.0.9
@@ -1022,25 +1021,24 @@ public class ClassUtil {
/**
* 是否为JDK中定义的类或接口判断依据
*
*
* <pre>
* 1、以java.、javax.开头的包名
* 2、ClassLoader为null
* </pre>
*
*
* @param clazz 被检查的类
* @return 是否为JDK中定义的类或接口
* @since 4.6.5
*/
public static boolean isJdkClass(Class<?> clazz) {
final Package objectPackage = clazz.getPackage();
if(null == objectPackage) {
if (null == objectPackage) {
return false;
}
final String objectPackageName = objectPackage.getName();
if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || clazz.getClassLoader() == null) {
return true;
}
return false;
return objectPackageName.startsWith("java.") //
|| objectPackageName.startsWith("javax.") //
|| clazz.getClassLoader() == null;
}
}

View File

@@ -19,7 +19,7 @@ public class ModifierUtil {
* @author looly
* @since 4.0.5
*/
public static enum ModifierType {
public enum ModifierType {
/** public修饰符所有类都能访问 */
PUBLIC(Modifier.PUBLIC),
/** private修饰符只能被自己访问和修改 */
@@ -51,7 +51,7 @@ public class ModifierUtil {
* 构造
* @param modifier 修饰符int表示见{@link Modifier}
*/
private ModifierType(int modifier) {
ModifierType(int modifier) {
this.value = modifier;
}

View File

@@ -60,7 +60,7 @@ public class ReferenceUtil {
* @author looly
*
*/
public static enum ReferenceType {
public enum ReferenceType {
/** 软引用在GC报告内存不足时会被GC回收 */
SOFT,
/** 弱引用在GC时发现弱引用会回收其对象 */
@@ -69,7 +69,7 @@ public class ReferenceUtil {
* 虚引用在GC时发现虚引用对象会将{@link PhantomReference}插入{@link ReferenceQueue}。 <br>
* 此时对象未被真正回收,要等到{@link ReferenceQueue}被真正处理后才会被回收。
*/
PHANTOM;
PHANTOM
}
}

View File

@@ -1,15 +1,11 @@
package cn.hutool.core.convert;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import cn.hutool.core.lang.Console;
import cn.hutool.core.date.DateUtil;
import org.junit.Assert;
import org.junit.Test;
import cn.hutool.core.date.DateUtil;
import java.util.ArrayList;
import java.util.Date;
/**
* 类型转换工具单元测试

View File

@@ -42,8 +42,8 @@ public class ConvertToBeanTest {
person.setSubName("sub名字");
Map<String, String> map = Convert.toMap(String.class, String.class, person);
Assert.assertEquals(map.get("name"), "测试A11");
Assert.assertEquals(map.get("age"), 14);
Assert.assertEquals("测试A11", map.get("name"));
Assert.assertEquals("14", map.get("age"));
Assert.assertEquals("11213232", map.get("openid"));
}

View File

@@ -5,7 +5,6 @@ import cn.hutool.core.date.BetweenFormater.Level;
import org.junit.Assert;
import org.junit.Test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

View File

@@ -1,13 +1,11 @@
package cn.hutool.core.util;
import java.util.Map;
import cn.hutool.core.lang.Console;
import org.junit.Assert;
import org.junit.Test;
import cn.hutool.core.lang.Editor;
import cn.hutool.core.lang.Filter;
import org.junit.Assert;
import org.junit.Test;
import java.util.Map;
/**
* {@link ArrayUtil} 数组工具单元测试

View File

@@ -52,10 +52,10 @@ public class EnumUtilTest {
Assert.assertEquals("type1", enumMap.get("TEST1"));
}
public static enum TestEnum{
public enum TestEnum{
TEST1("type1"), TEST2("type2"), TEST3("type3");
private TestEnum(String type) {
TestEnum(String type) {
this.type = type;
}

View File

@@ -13,14 +13,14 @@ public interface TaskListener {
* 定时任务启动时触发
* @param executor {@link TaskExecutor}
*/
public void onStart(TaskExecutor executor);
void onStart(TaskExecutor executor);
/**
* 任务成功结束时触发
*
* @param executor {@link TaskExecutor}
*/
public void onSucceeded(TaskExecutor executor);
void onSucceeded(TaskExecutor executor);
/**
* 任务启动失败时触发
@@ -28,5 +28,5 @@ public interface TaskListener {
* @param executor {@link TaskExecutor}
* @param exception 异常
*/
public void onFailed(TaskExecutor executor, Throwable exception);
void onFailed(TaskExecutor executor, Throwable exception);
}

View File

@@ -165,7 +165,7 @@ public class CronPattern {
boolean eval;
for (int i = 0; i < matcherSize; i++) {
eval = (isMatchSecond ? secondMatchers.get(i).match(second) : true) // 匹配秒非秒匹配模式下始终返回true
eval = ((false == isMatchSecond) || secondMatchers.get(i).match(second)) // 匹配秒非秒匹配模式下始终返回true
&& minuteMatchers.get(i).match(minute)// 匹配分
&& hourMatchers.get(i).match(hour)// 匹配时
&& isMatchDayOfMonth(dayOfMonthMatchers.get(i), dayOfMonth, month, calendar.isLeapYear(year))// 匹配日
@@ -211,7 +211,7 @@ public class CronPattern {
* @since 4.0.2
*/
private static boolean isMatch(List<ValueMatcher> matchers, int index, int value) {
return (matchers.size() > index) ? matchers.get(index).match(value) : true;
return (matchers.size() <= index) || matchers.get(index).match(value);
}
/**
@@ -253,7 +253,7 @@ public class CronPattern {
}
// 分
try {
this.minuteMatchers.add(ValueMatcherBuilder.build(parts[0 + offset], MINUTE_VALUE_PARSER));
this.minuteMatchers.add(ValueMatcherBuilder.build(parts[offset], MINUTE_VALUE_PARSER));
} catch (Exception e) {
throw new CronException(e, "Invalid pattern [{}], parsing 'minute' field error!", pattern);
}

View File

@@ -19,19 +19,19 @@ public interface ValueParser {
* @param value String值
* @return int
*/
public int parse(String value);
int parse(String value);
/**
* 返回最小值
*
* @return 最小值
*/
public int getMin();
int getMin();
/**
* 返回最大值
*
* @return 最大值
*/
public int getMax();
int getMax();
}

View File

@@ -61,7 +61,7 @@ public class InvokeTask implements Task{
@Override
public void execute() {
try {
ReflectUtil.invoke(this.obj, this.method, new Object[]{});
ReflectUtil.invoke(this.obj, this.method);
} catch (UtilException e) {
throw new CronException(e.getCause());
}

View File

@@ -18,5 +18,5 @@ public interface Task {
* 作业的具体实现需考虑异常情况,默认情况下任务异常在监听中统一监听处理,如果不加入监听,异常会被忽略<br>
* 因此最好自行捕获异常后处理
*/
public void execute();
void execute();
}

View File

@@ -13,7 +13,7 @@ public enum GlobalBouncyCastleProvider {
private Provider provider;
private static boolean useBouncyCastle = true;
private GlobalBouncyCastleProvider() {
GlobalBouncyCastleProvider() {
try {
this.provider = ProviderFactory.createBouncyCastleProvider();
} catch (NoClassDefFoundError e) {
@@ -33,7 +33,7 @@ public enum GlobalBouncyCastleProvider {
* 设置是否使用Bouncy Castle库<br>
* 如果设置为false表示强制关闭Bouncy Castle而使用JDK
*
* @param isUseBouncyCastle
* @param isUseBouncyCastle 是否使用BouncyCastle库
* @since 4.5.2
*/
public static void setUseBouncyCastle(boolean isUseBouncyCastle) {

View File

@@ -42,5 +42,5 @@ public enum Mode {
/**
* Propagating Cipher Block
*/
PCBC;
PCBC
}

View File

@@ -23,7 +23,7 @@ public enum AsymmetricAlgorithm {
* 构造
* @param value 算法字符表示,区分大小写
*/
private AsymmetricAlgorithm(String value) {
AsymmetricAlgorithm(String value) {
this.value = value;
}

View File

@@ -7,5 +7,5 @@ package cn.hutool.crypto.asymmetric;
*
*/
public enum KeyType {
PrivateKey, PublicKey;
PrivateKey, PublicKey
}

View File

@@ -40,7 +40,7 @@ public enum SignAlgorithm {
*
* @param value 算法字符表示,区分大小写
*/
private SignAlgorithm(String value) {
SignAlgorithm(String value) {
this.value = value;
}

View File

@@ -12,21 +12,21 @@ import cn.hutool.core.util.CharsetUtil;
* 使用方法如下:
* <p>
* <code>
* String pw_hash = BCrypt.hashpw(plain_password, BCrypt.gensalt()); <br />
* </code>
* String pw_hash = BCrypt.hashpw(plain_password, BCrypt.gensalt()); <br />
* </code>
* <p>
* 使用checkpw方法检查被加密的字符串是否与原始字符串匹配
* <p>
* <code>
* BCrypt.checkpw(candidate_password, stored_hash);
* </code>
* BCrypt.checkpw(candidate_password, stored_hash);
* </code>
* <p>
* gensalt方法提供了可选参数 (log_rounds) 来定义加盐多少,也决定了加密的复杂度:
* <p>
* <code>
* String strong_salt = BCrypt.gensalt(10)<br />
* String stronger_salt = BCrypt.gensalt(12)<br />
* </code>
* String strong_salt = BCrypt.gensalt(10)<br />
* String stronger_salt = BCrypt.gensalt(12)<br />
* </code>
*
* @author Damien Miller
* @since 4.1.1
@@ -40,9 +40,9 @@ public class BCrypt {
private static final int BLOWFISH_NUM_ROUNDS = 16;
// Initial contents of key schedule
private static final int P_orig[] = { 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7,
0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b };
private static final int S_orig[] = { 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8,
private static final int[] P_orig = {0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7,
0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b};
private static final int[] S_orig = {0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8,
0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, 0x55ca396a, 0x2aab10b6, 0xb4cc5c34,
0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, 0x3b8f4898, 0x6b4bb9af,
@@ -110,37 +110,37 @@ public class BCrypt {
0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, 0x53113ec0, 0x1640e3d3, 0x38abbd60,
0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0,
0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 };
0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6};
// bcrypt IV: "OrpheanBeholderScryDoubt". The C implementation calls
// this "ciphertext", but it is really plaintext or an IV. We keep
// the name to make code comparison easier.
static private final int bf_crypt_ciphertext[] = { 0x4f727068, 0x65616e42, 0x65686f6c, 0x64657253, 0x63727944, 0x6f756274 };
static private final int[] bf_crypt_ciphertext = {0x4f727068, 0x65616e42, 0x65686f6c, 0x64657253, 0x63727944, 0x6f756274};
// Table for Base64 encoding
static private final char base64_code[] = { '.', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
static private final char[] base64_code = {'.', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
// Table for Base64 decoding
static private final byte index_64[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
static private final byte[] index_64 = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 0, 1, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, -1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, -1, -1, -1, -1, -1, -1, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, -1, -1, -1, -1, -1 };
25, 26, 27, -1, -1, -1, -1, -1, -1, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, -1, -1, -1, -1, -1};
// Expanded Blowfish key
private int P[];
private int S[];
private int[] P;
private int[] S;
/**
* Encode a byte array using bcrypt's slightly-modified base64 encoding scheme. Note that this is *not* compatible with the standard MIME-base64 encoding.
*
* @param d the byte array to encode
* @param d the byte array to encode
* @param len the number of bytes to encode
* @return base64-encoded string
* @exception IllegalArgumentException if the length is invalid
* @throws IllegalArgumentException if the length is invalid
*/
private static String encode_base64(byte d[], int len) throws IllegalArgumentException {
private static String encode_base64(byte[] d, int len) throws IllegalArgumentException {
int off = 0;
StringBuffer rs = new StringBuffer();
StringBuilder rs = new StringBuilder();
int c1, c2;
if (len <= 0 || len > d.length)
@@ -172,7 +172,7 @@ public class BCrypt {
/**
* Look up the 3 bits base64-encoded by the specified character, range-checking againt conversion table
*
*
* @param x the base64-encoded value
* @return the decoded value of x
*/
@@ -183,17 +183,18 @@ public class BCrypt {
}
/**
* Decode a string encoded using bcrypt's base64 scheme to a byte array. Note that this is *not* compatible with the standard MIME-base64 encoding.
*
* @param s the string to decode
* Decode a string encoded using bcrypt's base64 scheme to a byte array.<br>
* Note that this is *not* compatible with the standard MIME-base64 encoding.
*
* @param s the string to decode
* @param maxolen the maximum number of bytes to decode
* @return an array containing the decoded bytes
* @throws IllegalArgumentException if maxolen is invalid
*/
private static byte[] decode_base64(String s, int maxolen) throws IllegalArgumentException {
private static byte[] decodeBase64(String s, int maxolen) throws IllegalArgumentException {
StringBuffer rs = new StringBuffer();
int off = 0, slen = s.length(), olen = 0;
byte ret[];
byte[] ret;
byte c1, c2, c3, c4, o;
if (maxolen <= 0)
@@ -232,15 +233,15 @@ public class BCrypt {
/**
* Blowfish encipher a single 64-bit block encoded as two 32-bit halves
*
* @param lr an array containing the two 32-bit half blocks
*
* @param lr an array containing the two 32-bit half blocks
* @param off the position in the array of the blocks
*/
private final void encipher(int lr[], int off) {
private void encipher(int[] lr, int off) {
int i, n, l = lr[off], r = lr[off + 1];
l ^= P[0];
for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2;) {
for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2; ) {
// Feistel substitution on left word
n = S[(l >> 24) & 0xff];
n += S[0x100 | ((l >> 16) & 0xff)];
@@ -261,12 +262,12 @@ public class BCrypt {
/**
* Cycically extract a word of key material
*
*
* @param data the string to extract the data from
* @param offp a "pointer" (as a one-entry array) to the current offset into data
* @return the next word of material from data
*/
private static int streamtoword(byte data[], int offp[]) {
private static int streamToWord(byte[] data, int[] offp) {
int i;
int word = 0;
int off = offp[0];
@@ -290,17 +291,17 @@ public class BCrypt {
/**
* Key the Blowfish cipher
*
*
* @param key an array containing the key
*/
private void key(byte key[]) {
private void key(byte[] key) {
int i;
int koffp[] = { 0 };
int lr[] = { 0, 0 };
int[] koffp = {0};
int[] lr = {0, 0};
int plen = P.length, slen = S.length;
for (i = 0; i < plen; i++)
P[i] = P[i] ^ streamtoword(key, koffp);
P[i] = P[i] ^ streamToWord(key, koffp);
for (i = 0; i < plen; i += 2) {
encipher(lr, 0);
@@ -317,30 +318,31 @@ public class BCrypt {
/**
* Perform the "enhanced key schedule" step described by Provos and Mazieres in "A Future-Adaptable Password Scheme" http://www.openbsd.org/papers/bcrypt-paper.ps
*
*
* @param data salt information
* @param key password information
* @param key password information
*/
private void ekskey(byte data[], byte key[]) {
private void ekskey(byte[] data, byte[] key) {
int i;
int koffp[] = { 0 }, doffp[] = { 0 };
int lr[] = { 0, 0 };
int[] koffp = {0};
int[] doffp = {0};
int[] lr = {0, 0};
int plen = P.length, slen = S.length;
for (i = 0; i < plen; i++)
P[i] = P[i] ^ streamtoword(key, koffp);
P[i] = P[i] ^ streamToWord(key, koffp);
for (i = 0; i < plen; i += 2) {
lr[0] ^= streamtoword(data, doffp);
lr[1] ^= streamtoword(data, doffp);
lr[0] ^= streamToWord(data, doffp);
lr[1] ^= streamToWord(data, doffp);
encipher(lr, 0);
P[i] = lr[0];
P[i + 1] = lr[1];
}
for (i = 0; i < slen; i += 2) {
lr[0] ^= streamtoword(data, doffp);
lr[1] ^= streamtoword(data, doffp);
lr[0] ^= streamToWord(data, doffp);
lr[1] ^= streamToWord(data, doffp);
encipher(lr, 0);
S[i] = lr[0];
S[i + 1] = lr[1];
@@ -349,17 +351,17 @@ public class BCrypt {
/**
* 加密密文
*
* @param password 明文密码
* @param salt 加盐
*
* @param password 明文密码
* @param salt 加盐
* @param log_rounds hash中叠加的对数
* @param cdata 加密数据
* @param cdata 加密数据
* @return 加密后的密文
*/
public byte[] crypt(byte password[], byte salt[], int log_rounds, int cdata[]) {
public byte[] crypt(byte[] password, byte[] salt, int log_rounds, int[] cdata) {
int rounds, i, j;
int clen = cdata.length;
byte ret[];
byte[] ret;
if (log_rounds < 4 || log_rounds > 30)
throw new IllegalArgumentException("Bad number of rounds");
@@ -391,7 +393,7 @@ public class BCrypt {
/**
* 生成密文使用长度为10的加盐方式
*
*
* @param password 需要加密的明文
* @return 密文
*/
@@ -401,17 +403,18 @@ public class BCrypt {
/**
* 生成密文
*
*
* @param password 需要加密的明文
* @param salt 盐,使用{@link #gensalt()} 生成
* @param salt 盐,使用{@link #gensalt()} 生成
* @return 密文
*/
public static String hashpw(String password, String salt) {
BCrypt bcrypt;
String real_salt;
byte saltb[], hashed[];
byte[] saltb;
byte[] hashed;
char minor = (char) 0;
int rounds, off = 0;
int rounds, off;
StringBuilder rs = new StringBuilder();
if (salt.charAt(0) != '$' || salt.charAt(1) != '2')
@@ -432,7 +435,7 @@ public class BCrypt {
real_salt = salt.substring(off + 3, off + 25);
byte[] passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes(CharsetUtil.CHARSET_UTF_8);
saltb = decode_base64(real_salt, BCRYPT_SALT_LEN);
saltb = decodeBase64(real_salt, BCRYPT_SALT_LEN);
bcrypt = new BCrypt();
hashed = bcrypt.crypt(passwordb, saltb, rounds, (int[]) bf_crypt_ciphertext.clone());
@@ -446,7 +449,7 @@ public class BCrypt {
if (rounds > 30) {
throw new IllegalArgumentException("rounds exceeds maximum (30)");
}
rs.append(Integer.toString(rounds));
rs.append(rounds);
rs.append("$");
rs.append(encode_base64(saltb, saltb.length));
rs.append(encode_base64(hashed, bf_crypt_ciphertext.length * 4 - 1));
@@ -455,14 +458,14 @@ public class BCrypt {
/**
* 生成盐
*
*
* @param log_rounds hash中叠加的2的对数 - the work factor therefore increases as 2**log_rounds.
* @param random {@link SecureRandom}
* @param random {@link SecureRandom}
* @return an encoded salt value
*/
public static String gensalt(int log_rounds, SecureRandom random) {
final StringBuilder rs = new StringBuilder();
byte rnd[] = new byte[BCRYPT_SALT_LEN];
byte[] rnd = new byte[BCRYPT_SALT_LEN];
random.nextBytes(rnd);
@@ -472,7 +475,7 @@ public class BCrypt {
if (log_rounds > 30) {
throw new IllegalArgumentException("log_rounds exceeds maximum (30)");
}
rs.append(Integer.toString(log_rounds));
rs.append(log_rounds);
rs.append("$");
rs.append(encode_base64(rnd, rnd.length));
return rs.toString();
@@ -480,7 +483,7 @@ public class BCrypt {
/**
* 生成盐
*
*
* @param log_rounds the log2 of the number of rounds of hashing to apply - the work factor therefore increases as 2**log_rounds.
* @return 盐
*/
@@ -490,7 +493,7 @@ public class BCrypt {
/**
* 生成盐
*
*
* @return 盐
*/
public static String gensalt() {
@@ -499,14 +502,14 @@ public class BCrypt {
/**
* 检查明文密码文本是否匹配加密后的文本
*
*
* @param plaintext 需要验证的明文密码
* @param hashed 密文
* @param hashed 密文
* @return 是否匹配
*/
public static boolean checkpw(String plaintext, String hashed) {
byte hashed_bytes[];
byte try_bytes[];
byte[] hashed_bytes;
byte[] try_bytes;
String try_pw = hashpw(plaintext, hashed);
hashed_bytes = hashed.getBytes(CharsetUtil.CHARSET_UTF_8);
try_bytes = try_pw.getBytes(CharsetUtil.CHARSET_UTF_8);

View File

@@ -21,7 +21,7 @@ public enum DigestAlgorithm {
*
* @param value 算法字符串表示
*/
private DigestAlgorithm(String value) {
DigestAlgorithm(String value) {
this.value = value;
}

View File

@@ -28,7 +28,7 @@ public enum SymmetricAlgorithm {
* 构造
* @param value 算法的字符串表示,区分大小写
*/
private SymmetricAlgorithm(String value) {
SymmetricAlgorithm(String value) {
this.value = value;
}

View File

@@ -1,8 +1,5 @@
package cn.hutool.crypto.test;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.KeyUtil;
import cn.hutool.crypto.Mode;

View File

@@ -1,23 +1,15 @@
package cn.hutool.crypto.test;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
import org.junit.Test;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.KeyUtil;
import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import cn.hutool.crypto.symmetric.DES;
import cn.hutool.crypto.symmetric.DESede;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import cn.hutool.crypto.symmetric.Vigenere;
import cn.hutool.crypto.symmetric.*;
import org.junit.Assert;
import org.junit.Test;
/**
* 对称加密算法单元测试

View File

@@ -1,12 +1,5 @@
package cn.hutool.db.dialect.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ArrayUtil;
@@ -17,11 +10,11 @@ import cn.hutool.db.Page;
import cn.hutool.db.StatementUtil;
import cn.hutool.db.dialect.Dialect;
import cn.hutool.db.dialect.DialectName;
import cn.hutool.db.sql.Condition;
import cn.hutool.db.sql.LogicalOperator;
import cn.hutool.db.sql.Query;
import cn.hutool.db.sql.SqlBuilder;
import cn.hutool.db.sql.Wrapper;
import cn.hutool.db.sql.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
* ANSI SQL 方言

View File

@@ -193,12 +193,9 @@ public abstract class AbstractDSFactory extends DSFactory {
return false;
}
if (setting == null) {
if (other.setting != null) {
return false;
}
} else if (!setting.equals(other.setting)) {
return false;
return other.setting == null;
} else {
return setting.equals(other.setting);
}
return true;
}
}

View File

@@ -14,7 +14,7 @@ public class GlobalDSFactory {
private static volatile DSFactory factory;
private static Object lock = new Object();
/**
/*
* 设置在JVM关闭时关闭所有数据库连接
*/
static {

View File

@@ -28,5 +28,5 @@ public interface RsHandler<T> extends Serializable{
* @return 处理后生成的对象
* @throws SQLException SQL异常
*/
public T handle(ResultSet rs) throws SQLException;
T handle(ResultSet rs) throws SQLException;
}

View File

@@ -10,12 +10,12 @@ import java.util.StringTokenizer;
* @author looly
*/
public class SqlFormatter {
private static final Set<String> BEGIN_CLAUSES = new HashSet<String>();
private static final Set<String> END_CLAUSES = new HashSet<String>();
private static final Set<String> LOGICAL = new HashSet<String>();
private static final Set<String> QUANTIFIERS = new HashSet<String>();
private static final Set<String> DML = new HashSet<String>();
private static final Set<String> MISC = new HashSet<String>();
private static final Set<String> BEGIN_CLAUSES = new HashSet<>();
private static final Set<String> END_CLAUSES = new HashSet<>();
private static final Set<String> LOGICAL = new HashSet<>();
private static final Set<String> QUANTIFIERS = new HashSet<>();
private static final Set<String> DML = new HashSet<>();
private static final Set<String> MISC = new HashSet<>();
static {
BEGIN_CLAUSES.add("left");
@@ -31,7 +31,6 @@ public class SqlFormatter {
END_CLAUSES.add("join");
END_CLAUSES.add("from");
END_CLAUSES.add("by");
END_CLAUSES.add("join");
END_CLAUSES.add("into");
END_CLAUSES.add("union");
@@ -55,8 +54,8 @@ public class SqlFormatter {
MISC.add("on");
}
private static String indentString = " ";
private static String initial = "\n ";
private static final String indentString = " ";
private static final String initial = "\n ";
public static String format(String source) {
return new FormatProcess(source).perform().trim();
@@ -74,8 +73,8 @@ public class SqlFormatter {
boolean afterInsert = false;
int inFunction = 0;
int parensSinceSelect = 0;
private LinkedList<Integer> parenCounts = new LinkedList<Integer>();
private LinkedList<Boolean> afterByOrFromOrSelects = new LinkedList<Boolean>();
private LinkedList<Integer> parenCounts = new LinkedList<>();
private LinkedList<Boolean> afterByOrFromOrSelects = new LinkedList<>();
int indent = 1;
@@ -141,7 +140,7 @@ public class SqlFormatter {
misc();
}
if (!isWhitespace(this.token)) {
if (false == isWhitespace(this.token)) {
this.lastToken = this.lcToken;
}
}
@@ -313,7 +312,7 @@ public class SqlFormatter {
}
private static boolean isWhitespace(String token) {
return " \n\r\f\t".indexOf(token) >= 0;
return " \n\r\f\t".contains(token);
}
private void newline() {

View File

@@ -60,7 +60,7 @@ public enum TransactionLevel {
/** 事务级别对应Connection中的常量值 */
private int level;
private TransactionLevel(int level) {
TransactionLevel(int level) {
this.level = level;
}

View File

@@ -13,5 +13,5 @@ public enum FtpMode {
/** 主动模式 */
Active,
/** 被动模式 */
Passive;
Passive
}

View File

@@ -16,7 +16,7 @@ public enum GlobalMailAccount {
/**
* 构造
*/
private GlobalMailAccount() {
GlobalMailAccount() {
mailAccount = createDefaultAccount();
}

View File

@@ -1,14 +1,13 @@
package cn.hutool.extra.mail;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.Setting;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.Properties;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.Setting;
/**
* 邮件账户对象
*

View File

@@ -68,7 +68,7 @@ public class UploadFile {
* 写入后原临时文件会被删除
* @param destPath 目标文件路径
* @return 目标文件
* @throws IOException
* @throws IOException IO异常
*/
public File write(String destPath) throws IOException {
if(data != null || tempFile != null) {
@@ -100,12 +100,9 @@ public class UploadFile {
return destination;
}
/**
* Returns the content of file upload item.
*/
/**
* @return 获得文件字节流
* @throws IOException
* @throws IOException IO异常
*/
public byte[] getFileContent() throws IOException {
assertValid();
@@ -121,7 +118,7 @@ public class UploadFile {
/**
* @return 获得文件流
* @throws IOException
* @throws IOException IO异常
*/
public InputStream getFileInputStream() throws IOException {
assertValid();
@@ -179,7 +176,7 @@ public class UploadFile {
* 处理上传表单流,提取出文件
*
* @param input 上传表单的流
* @throws IOException
* @throws IOException IO异常
*/
protected boolean processStream(MultipartRequestInputStream input) throws IOException {
if (!isAllowedExtension()) {
@@ -260,7 +257,7 @@ public class UploadFile {
/**
* 断言是否文件流可用
* @throws IOException
* @throws IOException IO异常
*/
private void assertValid() throws IOException {
if(! isUploaded()) {

View File

@@ -34,7 +34,7 @@ public enum ChannelType {
*
* @param value 类型值
*/
private ChannelType(String value) {
ChannelType(String value) {
this.value = value;
}

View File

@@ -429,12 +429,12 @@ public class Sftp extends AbstractFtp {
* @author looly
*
*/
public static enum Mode {
public enum Mode {
/** 完全覆盖模式这是JSch的默认文件传输模式即如果目标文件已经存在传输的文件将完全覆盖目标文件产生新的文件。 */
OVERWRITE,
/** 恢复模式,如果文件已经传输一部分,这时由于网络或其他任何原因导致文件传输中断,如果下一次传输相同的文件,则会从上一次中断的地方续传。 */
RESUME,
/** 追加模式,如果目标文件已存在,传输的文件将在目标文件后追加。 */
APPEND;
APPEND
}
}

View File

@@ -132,7 +132,7 @@ public class TemplateConfig implements Serializable {
*
* @author looly
*/
public static enum ResourceMode {
public enum ResourceMode {
/** 从ClassPath加载模板 */
CLASSPATH,
/** 从File目录加载模板 */
@@ -142,7 +142,7 @@ public class TemplateConfig implements Serializable {
/** 从模板文本加载模板 */
STRING,
/** 复合加载模板分别从File、ClassPath、Web-root、String方式尝试查找模板 */
COMPOSITE;
COMPOSITE
}
@Override
@@ -185,5 +185,5 @@ public class TemplateConfig implements Serializable {
return false;
}
return true;
};
}
}

View File

@@ -24,7 +24,7 @@ public enum ContentType {
TEXT_XML("text/xml");
private String value;
private ContentType(String value) {
ContentType(String value) {
this.value = value;
}

View File

@@ -26,7 +26,7 @@ public enum GlobalHeaders {
/**
* 构造
*/
private GlobalHeaders() {
GlobalHeaders() {
putDefault(false);
}
@@ -110,7 +110,7 @@ public enum GlobalHeaders {
if (null != name && null != value) {
final List<String> values = headers.get(name.trim());
if (isOverride || CollectionUtil.isEmpty(values)) {
final ArrayList<String> valueList = new ArrayList<String>();
final ArrayList<String> valueList = new ArrayList<>();
valueList.add(value);
headers.put(name.trim(), valueList);
} else {

View File

@@ -64,7 +64,7 @@ public enum Header {
LOCATION("Location");
private String value;
private Header(String value) {
Header(String value) {
this.value = value;
}

View File

@@ -21,6 +21,7 @@ import javax.net.ssl.SSLSocketFactory;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.resource.BytesResource;
import cn.hutool.core.io.resource.FileResource;
@@ -811,11 +812,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* @since 3.3.0
*/
public HttpRequest setMaxRedirectCount(int maxRedirectCount) {
if (maxRedirectCount > 0) {
this.maxRedirectCount = maxRedirectCount;
} else {
this.maxRedirectCount = 0;
}
this.maxRedirectCount = Math.max(maxRedirectCount, 0);
return this;
}
@@ -993,7 +990,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
// 自定义Cookie
.setCookie(this.cookie)
// 定义转发
.setInstanceFollowRedirects(this.maxRedirectCount > 0 ? true : false)
.setInstanceFollowRedirects(this.maxRedirectCount > 0)
// 流方式上传数据
.setChunkedStreamingMode(this.blockSize)
// 覆盖默认Header
@@ -1060,9 +1057,9 @@ public class HttpRequest extends HttpBase<HttpRequest> {
/**
* 发送数据流
*
* @throws IOException
* @throws IORuntimeException IO异常
*/
private void send() throws HttpException {
private void send() throws IORuntimeException {
try {
if (Method.POST.equals(this.method) || Method.PUT.equals(this.method) || Method.DELETE.equals(this.method) || this.isRest) {
if (CollectionUtil.isEmpty(this.fileForm)) {
@@ -1076,7 +1073,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
} catch (IOException e) {
// 异常时关闭连接
this.httpConnection.disconnectQuietly();
throw new HttpException(e);
throw new IORuntimeException(e);
}
}
@@ -1084,7 +1081,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* 发送普通表单<br>
* 发送数据后自动关闭输出流
*
* @throws IOException
* @throws IOException IO异常
*/
private void sendFormUrlEncoded() throws IOException {
if (StrUtil.isBlank(this.header(Header.CONTENT_TYPE))) {
@@ -1105,7 +1102,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* 发送多组件请求(例如包含文件的表单)<br>
* 发送数据后自动关闭输出流
*
* @throws IOException
* @throws IOException IO异常
*/
private void sendMultipart() throws IOException {
setMultipart();// 设置表单类型为Multipart
@@ -1114,8 +1111,6 @@ public class HttpRequest extends HttpBase<HttpRequest> {
writeFileForm(out);
writeForm(out);
formEnd(out);
} catch (IOException e) {
throw e;
}
}
@@ -1125,9 +1120,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* 发送普通表单内容
*
* @param out 输出流
* @throws IOException
*/
private void writeForm(OutputStream out) throws IOException {
private void writeForm(OutputStream out) {
if (CollectionUtil.isNotEmpty(this.form)) {
StringBuilder builder = StrUtil.builder();
for (Entry<String, Object> entry : this.form.entrySet()) {
@@ -1143,9 +1137,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* 发送文件对象表单
*
* @param out 输出流
* @throws IOException
*/
private void writeFileForm(OutputStream out) throws IOException {
private void writeFileForm(OutputStream out) {
for (Entry<String, Resource> entry : this.fileForm.entrySet()) {
appendPart(entry.getKey(), entry.getValue(), out);
}
@@ -1191,7 +1184,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* 上传表单结束
*
* @param out 输出流
* @throws IOException
* @throws IOException IO异常
*/
private void formEnd(OutputStream out) throws IOException {
out.write(BOUNDARY_END);
@@ -1201,7 +1194,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
/**
* 设置表单类型为Multipart文件上传
*
* @return HttpConnection
* @return HttpConnection HTTP连接对象
*/
private void setMultipart() {
this.httpConnection.header(Header.CONTENT_TYPE, CONTENT_TYPE_MULTIPART_PREFIX + BOUNDARY, true);
@@ -1215,10 +1208,10 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* @since 3.1.2
*/
private boolean isIgnoreResponseBody() {
if (Method.HEAD == this.method || Method.CONNECT == this.method || Method.OPTIONS == this.method || Method.TRACE == this.method) {
return true;
}
return false;
return Method.HEAD == this.method //
|| Method.CONNECT == this.method //
|| Method.OPTIONS == this.method //
|| Method.TRACE == this.method;
}
// ---------------------------------------------------------------- Private method end

View File

@@ -6,5 +6,5 @@ package cn.hutool.http;
*
*/
public enum Method {
GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE, CONNECT, PATCH;
GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE, CONNECT, PATCH
}

View File

@@ -5,185 +5,185 @@ package cn.hutool.http;
* @author Looly
*
*/
public interface Status {
interface Status {
/**
* HTTP Status-Code 200: OK.
*/
public static final int HTTP_OK = 200;
int HTTP_OK = 200;
/**
* HTTP Status-Code 201: Created.
*/
public static final int HTTP_CREATED = 201;
int HTTP_CREATED = 201;
/**
* HTTP Status-Code 202: Accepted.
*/
public static final int HTTP_ACCEPTED = 202;
int HTTP_ACCEPTED = 202;
/**
* HTTP Status-Code 203: Non-Authoritative Information.
*/
public static final int HTTP_NOT_AUTHORITATIVE = 203;
int HTTP_NOT_AUTHORITATIVE = 203;
/**
* HTTP Status-Code 204: No Content.
*/
public static final int HTTP_NO_CONTENT = 204;
int HTTP_NO_CONTENT = 204;
/**
* HTTP Status-Code 205: Reset Content.
*/
public static final int HTTP_RESET = 205;
int HTTP_RESET = 205;
/**
* HTTP Status-Code 206: Partial Content.
*/
public static final int HTTP_PARTIAL = 206;
int HTTP_PARTIAL = 206;
/* 3XX: relocation/redirect */
/**
* HTTP Status-Code 300: Multiple Choices.
*/
public static final int HTTP_MULT_CHOICE = 300;
int HTTP_MULT_CHOICE = 300;
/**
* HTTP Status-Code 301: Moved Permanently.
*/
public static final int HTTP_MOVED_PERM = 301;
int HTTP_MOVED_PERM = 301;
/**
* HTTP Status-Code 302: Temporary Redirect.
*/
public static final int HTTP_MOVED_TEMP = 302;
int HTTP_MOVED_TEMP = 302;
/**
* HTTP Status-Code 303: See Other.
*/
public static final int HTTP_SEE_OTHER = 303;
int HTTP_SEE_OTHER = 303;
/**
* HTTP Status-Code 304: Not Modified.
*/
public static final int HTTP_NOT_MODIFIED = 304;
int HTTP_NOT_MODIFIED = 304;
/**
* HTTP Status-Code 305: Use Proxy.
*/
public static final int HTTP_USE_PROXY = 305;
int HTTP_USE_PROXY = 305;
/* 4XX: client error */
/**
* HTTP Status-Code 400: Bad Request.
*/
public static final int HTTP_BAD_REQUEST = 400;
int HTTP_BAD_REQUEST = 400;
/**
* HTTP Status-Code 401: Unauthorized.
*/
public static final int HTTP_UNAUTHORIZED = 401;
int HTTP_UNAUTHORIZED = 401;
/**
* HTTP Status-Code 402: Payment Required.
*/
public static final int HTTP_PAYMENT_REQUIRED = 402;
int HTTP_PAYMENT_REQUIRED = 402;
/**
* HTTP Status-Code 403: Forbidden.
*/
public static final int HTTP_FORBIDDEN = 403;
int HTTP_FORBIDDEN = 403;
/**
* HTTP Status-Code 404: Not Found.
*/
public static final int HTTP_NOT_FOUND = 404;
int HTTP_NOT_FOUND = 404;
/**
* HTTP Status-Code 405: Method Not Allowed.
*/
public static final int HTTP_BAD_METHOD = 405;
int HTTP_BAD_METHOD = 405;
/**
* HTTP Status-Code 406: Not Acceptable.
*/
public static final int HTTP_NOT_ACCEPTABLE = 406;
int HTTP_NOT_ACCEPTABLE = 406;
/**
* HTTP Status-Code 407: Proxy Authentication Required.
*/
public static final int HTTP_PROXY_AUTH = 407;
int HTTP_PROXY_AUTH = 407;
/**
* HTTP Status-Code 408: Request Time-Out.
*/
public static final int HTTP_CLIENT_TIMEOUT = 408;
int HTTP_CLIENT_TIMEOUT = 408;
/**
* HTTP Status-Code 409: Conflict.
*/
public static final int HTTP_CONFLICT = 409;
int HTTP_CONFLICT = 409;
/**
* HTTP Status-Code 410: Gone.
*/
public static final int HTTP_GONE = 410;
int HTTP_GONE = 410;
/**
* HTTP Status-Code 411: Length Required.
*/
public static final int HTTP_LENGTH_REQUIRED = 411;
int HTTP_LENGTH_REQUIRED = 411;
/**
* HTTP Status-Code 412: Precondition Failed.
*/
public static final int HTTP_PRECON_FAILED = 412;
int HTTP_PRECON_FAILED = 412;
/**
* HTTP Status-Code 413: Request Entity Too Large.
*/
public static final int HTTP_ENTITY_TOO_LARGE = 413;
int HTTP_ENTITY_TOO_LARGE = 413;
/**
* HTTP Status-Code 414: Request-URI Too Large.
*/
public static final int HTTP_REQ_TOO_LONG = 414;
int HTTP_REQ_TOO_LONG = 414;
/**
* HTTP Status-Code 415: Unsupported Media Type.
*/
public static final int HTTP_UNSUPPORTED_TYPE = 415;
int HTTP_UNSUPPORTED_TYPE = 415;
/* 5XX: server error */
/**
* HTTP Status-Code 500: Internal Server Error.
*/
public static final int HTTP_INTERNAL_ERROR = 500;
int HTTP_INTERNAL_ERROR = 500;
/**
* HTTP Status-Code 501: Not Implemented.
*/
public static final int HTTP_NOT_IMPLEMENTED = 501;
int HTTP_NOT_IMPLEMENTED = 501;
/**
* HTTP Status-Code 502: Bad Gateway.
*/
public static final int HTTP_BAD_GATEWAY = 502;
int HTTP_BAD_GATEWAY = 502;
/**
* HTTP Status-Code 503: Service Unavailable.
*/
public static final int HTTP_UNAVAILABLE = 503;
int HTTP_UNAVAILABLE = 503;
/**
* HTTP Status-Code 504: Gateway Timeout.
*/
public static final int HTTP_GATEWAY_TIMEOUT = 504;
int HTTP_GATEWAY_TIMEOUT = 504;
/**
* HTTP Status-Code 505: HTTP Version Not Supported.
*/
public static final int HTTP_VERSION = 505;
int HTTP_VERSION = 505;
}

View File

@@ -19,7 +19,7 @@ public enum SoapProtocol {
*
* @param value {@link SOAPConstants} 中的协议版本值
*/
private SoapProtocol(String value) {
SoapProtocol(String value) {
this.value = value;
}

View File

@@ -17,9 +17,8 @@ import cn.hutool.core.util.StrUtil;
/**
* 内部JSON工具类仅用于JSON内部使用
*
* @author Looly
*
* @author Looly
*/
final class InternalJSONUtil {
@@ -28,17 +27,17 @@ final class InternalJSONUtil {
/**
* 写入值到Writer
*
* @param writer Writer
* @param value 值
*
* @param writer Writer
* @param value
* @param indentFactor 每一级别的缩进量
* @param indent 缩进空格数
* @param config 配置项
* @param indent 缩进空格数
* @param config 配置项
* @return Writer
* @throws JSONException
* @throws IOException
* @throws JSONException JSON异常
* @throws IOException IO异常
*/
protected static final Writer writeValue(Writer writer, Object value, int indentFactor, int indent, JSONConfig config) throws JSONException, IOException {
protected static Writer writeValue(Writer writer, Object value, int indentFactor, int indent, JSONConfig config) throws JSONException, IOException {
if (value == null || value instanceof JSONNull) {
writer.write(JSONNull.NULL.toString());
} else if (value instanceof JSON) {
@@ -67,15 +66,15 @@ final class InternalJSONUtil {
}
return writer;
}
/**
* 缩进,使用空格符
*
* @param writer
* @param indent
* @throws IOException
*
* @param writer writer
* @param indent 随进空格数
* @throws IOException IO异常
*/
protected static final void indent(Writer writer, int indent) throws IOException {
protected static void indent(Writer writer, int indent) throws IOException {
for (int i = 0; i < indent; i += 1) {
writer.write(CharUtil.SPACE);
}
@@ -83,7 +82,7 @@ final class InternalJSONUtil {
/**
* 如果对象是Number 且是 NaN or infinite将抛出异常
*
*
* @param obj 被检查的对象
* @throws JSONException If o is a non-finite number.
*/
@@ -182,10 +181,10 @@ final class InternalJSONUtil {
/**
* 将Property的键转化为JSON形式<br>
* 用于识别类似于com.luxiaolei.package.hutool这类用点隔开的键
*
*
* @param jsonObject JSONObject
* @param key 键
* @param value 值
* @param key
* @param value
* @return JSONObject
*/
protected static JSONObject propertyPut(JSONObject jsonObject, Object key, Object value) {
@@ -205,37 +204,36 @@ final class InternalJSONUtil {
target.put(path[last], value);
return jsonObject;
}
/**
* 默认情况下是否忽略null值的策略选择<br>
* JavaBean默认忽略null值其它对象不忽略
*
*
* @param obj 需要检查的对象
* @return 是否忽略null值
* @since 4.3.1
*/
protected static boolean defaultIgnoreNullValue(Object obj) {
if(obj instanceof CharSequence || obj instanceof JSONTokener || obj instanceof Map) {
return false;
}
return true;
return (false == (obj instanceof CharSequence))//
&& (false == (obj instanceof JSONTokener))//
&& (false == (obj instanceof Map));
}
/**
* 按照给定格式格式化日期,格式为空时返回时间戳字符串
*
*
* @param dateObj Date或者Calendar对象
* @param format 格式
* @param format 格式
* @return 日期字符串
*/
private static String formatDate(Object dateObj, String format) {
if (StrUtil.isNotBlank(format)) {
final Date date = (dateObj instanceof Date) ? (Date)dateObj : ((Calendar)dateObj).getTime();
final Date date = (dateObj instanceof Date) ? (Date) dateObj : ((Calendar) dateObj).getTime();
//用户定义了日期格式
return JSONUtil.quote(DateUtil.format(date, format));
}
//默认使用时间戳
return String.valueOf((dateObj instanceof Date) ? ((Date)dateObj).getTime() : ((Calendar)dateObj).getTimeInMillis());
return String.valueOf((dateObj instanceof Date) ? ((Date) dateObj).getTime() : ((Calendar) dateObj).getTimeInMillis());
}
}

View File

@@ -34,7 +34,7 @@ public interface JSON extends Cloneable, Serializable{
* @see BeanPath#get(Object)
* @since 4.0.6
*/
public Object getByPath(String expression);
Object getByPath(String expression);
/**
* 设置表达式指定位置或filed对应的值<br>
@@ -84,7 +84,7 @@ public interface JSON extends Cloneable, Serializable{
* @see BeanPath#get(Object)
* @since 4.0.6
*/
public <T> T getByPath(String expression, Class<T> resultType);
<T> T getByPath(String expression, Class<T> resultType);
/**
* 将JSON内容写入Writer无缩进<br>
@@ -94,7 +94,7 @@ public interface JSON extends Cloneable, Serializable{
* @return Writer
* @throws JSONException JSON相关异常
*/
public Writer write(Writer writer) throws JSONException;
Writer write(Writer writer) throws JSONException;
/**
* 将JSON内容写入Writer<br>
@@ -106,7 +106,7 @@ public interface JSON extends Cloneable, Serializable{
* @return Writer
* @throws JSONException JSON相关异常
*/
public Writer write(Writer writer, int indentFactor, int indent) throws JSONException;
Writer write(Writer writer, int indentFactor, int indent) throws JSONException;
/**
* 转换为JSON字符串
@@ -115,7 +115,7 @@ public interface JSON extends Cloneable, Serializable{
* @return JSON字符串
* @throws JSONException JSON相关异常
*/
public String toJSONString(int indentFactor) throws JSONException;
String toJSONString(int indentFactor) throws JSONException;
/**
* 格式化打印JSON缩进为4个空格
@@ -124,5 +124,5 @@ public interface JSON extends Cloneable, Serializable{
* @throws JSONException 包含非法数抛出此异常
* @since 3.0.9
*/
public String toStringPretty() throws JSONException;
String toStringPretty() throws JSONException;
}

View File

@@ -82,7 +82,7 @@ public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>
* @since 4.1.19
*/
public JSONArray(int initialCapacity, JSONConfig config) {
this.rawList = new ArrayList<Object>(initialCapacity);
this.rawList = new ArrayList<>(initialCapacity);
this.config = config;
}
@@ -107,9 +107,7 @@ public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>
*/
public JSONArray(Collection<Object> list) {
this(list.size());
for (Object o : list) {
this.add(o);
}
this.addAll(list);
}
/**
@@ -311,13 +309,10 @@ public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>
}
final JSONArray other = (JSONArray) obj;
if (rawList == null) {
if (other.rawList != null) {
return false;
}
} else if (!rawList.equals(other.rawList)) {
return false;
return other.rawList == null;
} else {
return rawList.equals(other.rawList);
}
return true;
}
@Override
@@ -382,7 +377,7 @@ public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>
}
@Override
public boolean addAll(Collection<? extends Object> c) {
public boolean addAll(Collection<?> c) {
if (CollUtil.isEmpty(c)) {
return false;
}
@@ -393,7 +388,7 @@ public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>
}
@Override
public boolean addAll(int index, Collection<? extends Object> c) {
public boolean addAll(int index, Collection<?> c) {
if (CollUtil.isEmpty(c)) {
return false;
}

View File

@@ -441,8 +441,8 @@ public class JSONObject extends JSONGetter<String> implements JSON, Map<String,
}
@Override
public void putAll(Map<? extends String, ? extends Object> m) {
for (Entry<? extends String, ? extends Object> entry : m.entrySet()) {
public void putAll(Map<? extends String, ?> m) {
for (Entry<? extends String, ?> entry : m.entrySet()) {
this.put(entry.getKey(), entry.getValue());
}
}
@@ -565,13 +565,10 @@ public class JSONObject extends JSONGetter<String> implements JSON, Map<String,
}
final JSONObject other = (JSONObject) obj;
if (rawHashMap == null) {
if (other.rawHashMap != null) {
return false;
}
} else if (!rawHashMap.equals(other.rawHashMap)) {
return false;
return other.rawHashMap == null;
} else {
return rawHashMap.equals(other.rawHashMap);
}
return true;
}
/**
@@ -660,7 +657,7 @@ public class JSONObject extends JSONGetter<String> implements JSON, Map<String,
}
InternalJSONUtil.indent(writer, newIndent);
writer.write(JSONUtil.quote(entry.getKey().toString()));
writer.write(JSONUtil.quote(entry.getKey()));
writer.write(CharUtil.COLON);
if (indentFactor > 0) {
// 冒号后的空格
@@ -682,7 +679,6 @@ public class JSONObject extends JSONGetter<String> implements JSON, Map<String,
* Bean对象转Map
*
* @param bean Bean对象
* @param ignoreNullValue 是否忽略空值
*/
private void populateMap(Object bean) {
final Collection<PropDesc> props = BeanUtil.getBeanDesc(bean.getClass()).getProps();
@@ -735,7 +731,7 @@ public class JSONObject extends JSONGetter<String> implements JSON, Map<String,
}
final JSONSerializer serializer = GlobalSerializeMapping.getSerializer(source.getClass());
if(null != serializer && serializer instanceof JSONObjectSerializer) {
if(serializer instanceof JSONObjectSerializer) {
// 自定义序列化
serializer.serialize(this, source);
} else if (source instanceof Map) {

View File

@@ -12,9 +12,9 @@ import cn.hutool.core.util.StrUtil;
public class JSONStrFormater {
/** 单位缩进字符串。*/
private static String SPACE = " ";
private static final String SPACE = " ";
/** 换行符*/
private static char NEW_LINE = StrUtil.C_LF;
private static final char NEW_LINE = StrUtil.C_LF;
/**
* 返回格式化JSON字符串。
@@ -23,13 +23,13 @@ public class JSONStrFormater {
* @return 格式化的JSON字符串。
*/
public static String format(String json) {
final StringBuffer result = new StringBuffer();
final StringBuilder result = new StringBuilder();
Character wrapChar = null;
boolean isEscapeMode = false;
int length = json.length();
int number = 0;
char key = 0;
char key;
for (int i = 0; i < length; i++) {
key = json.charAt(i);

View File

@@ -14,5 +14,5 @@ public interface JSONString {
*
* @return JSON字符串
*/
public String toJSONString();
String toJSONString();
}

View File

@@ -150,7 +150,7 @@ public final class JSONUtil {
return null;
}
JSON json = null;
JSON json;
if (obj instanceof JSON) {
json = (JSON) obj;
} else if (obj instanceof String) {
@@ -648,9 +648,6 @@ public final class JSONUtil {
if (object instanceof Date || object instanceof Calendar) {
return object;
}
if (object instanceof Calendar) {
return ((Calendar) object).getTimeInMillis();
}
// 枚举类保存其字符串形式4.0.2新增)
if (object instanceof Enum) {
return object.toString();

View File

@@ -79,7 +79,6 @@ public class JSONArrayTest {
List<Exam> list = array.toList(Exam.class);
Assert.assertFalse(list.isEmpty());
Assert.assertEquals(Exam.class, list.get(0).getClass());
;
}
@Test
@@ -123,7 +122,7 @@ public class JSONArrayTest {
JSONArray array = JSONUtil.parseArray(jsonStr);
Exam[] list = array.toArray(new Exam[0]);
Assert.assertFalse(0 == list.length);
Assert.assertNotEquals(0, list.length);
Assert.assertEquals(Exam.class, list[0].getClass());
}
@@ -136,7 +135,7 @@ public class JSONArrayTest {
JSONArray ja = JSONUtil.parseArray(json);
List<KeyBean> list = ja.toList(KeyBean.class);
Assert.assertTrue(null == list.get(0));
Assert.assertNull(list.get(0));
Assert.assertEquals("avalue", list.get(1).getAkey());
Assert.assertEquals("bvalue", list.get(1).getBkey());
}
@@ -175,7 +174,7 @@ public class JSONArrayTest {
return map;
}
class User {
static class User {
private Integer id;
private String name;

View File

@@ -354,7 +354,7 @@ public class JSONObjectTest {
Assert.assertEquals("defaultBBB", bbb);
}
public static enum TestEnum {
public enum TestEnum {
TYPE_A, TYPE_B
}

View File

@@ -17,7 +17,7 @@ public class EnvSettingInfo {
private String hubRemoteUrl;
private String reportFolder = "/report";
private String screenshotFolder = "/screenshot";;
private String screenshotFolder = "/screenshot";
private String elementFolder = "/config/element/";
private String suiteFolder = "/config/suite/";

View File

@@ -18,7 +18,7 @@ public interface Log extends TraceLog, DebugLog, InfoLog, WarnLog, ErrorLog {
/**
* @return 日志对象的Name
*/
public String getName();
String getName();
/**
* 是否开启指定日志

View File

@@ -10,43 +10,45 @@ import cn.hutool.log.level.Level;
/**
* 利用System.out.println()打印日志
* @author Looly
*
* @author Looly
*/
public class ConsoleLog extends AbstractLog {
private static final long serialVersionUID = -6843151523380063975L;
private static String logFormat = "[{date}] [{level}] {name}: {msg}";
private static final String logFormat = "[{date}] [{level}] {name}: {msg}";
private static Level currentLevel = Level.DEBUG;
private String name;
//------------------------------------------------------------------------- Constructor
/**
* 构造
*
*
* @param clazz 类
*/
public ConsoleLog(Class<?> clazz) {
this.name = (null == clazz) ? StrUtil.NULL : clazz.getName();
}
/**
* 构造
*
*
* @param name 类名
*/
public ConsoleLog(String name) {
this.name = name;
}
@Override
public String getName() {
return this.name;
}
/**
* 设置自定义的日志显示级别
*
* @param customLevel 自定义级别
* @since 4.1.10
*/
@@ -65,6 +67,7 @@ public class ConsoleLog extends AbstractLog {
public void trace(String fqcn, Throwable t, String format, Object... arguments) {
log(fqcn, Level.TRACE, t, format, arguments);
}
//------------------------------------------------------------------------- Debug
@Override
public boolean isDebugEnabled() {
@@ -108,31 +111,31 @@ public class ConsoleLog extends AbstractLog {
public void error(String fqcn, Throwable t, String format, Object... arguments) {
log(fqcn, Level.ERROR, t, format, arguments);
}
//------------------------------------------------------------------------- Log
@Override
public void log(String fqcn, Level level, Throwable t, String format, Object... arguments) {
// fqcn 无效
if(false == isEnabled(level)){
if (false == isEnabled(level)) {
return;
}
final Dict dict = Dict.create()
.set("date", DateUtil.now())
.set("level", level.toString())
.set("name", this.name)
.set("msg", StrUtil.format(format, arguments));
final String logMsg = StrUtil.format(logFormat, dict);
//WARN以上级别打印至System.err
if(level.ordinal() >= Level.WARN.ordinal()){
if (level.ordinal() >= Level.WARN.ordinal()) {
Console.error(t, logMsg);
}else{
} else {
Console.log(t, logMsg);
}
}
@Override
public boolean isEnabled(Level level) {
return currentLevel.compareTo(level) <= 0;

View File

@@ -14,5 +14,5 @@ public interface CellEditor {
* @param value 单元格值
* @return 编辑后的对象
*/
public Object edit(Cell cell, Object value);
Object edit(Cell cell, Object value);
}

Some files were not shown because too many files have changed in this diff Show More