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

@@ -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;
}