This commit is contained in:
Looly
2019-10-29 19:05:23 +08:00
parent 3cef7fa9a7
commit bf03aebcef
107 changed files with 283 additions and 456 deletions

View File

@@ -16,8 +16,8 @@ import java.lang.reflect.Method;
public class CglibInterceptor implements MethodInterceptor, Serializable { public class CglibInterceptor implements MethodInterceptor, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Object target; private final Object target;
private Aspect aspect; private final Aspect aspect;
/** /**
* 构造 * 构造

View File

@@ -83,14 +83,6 @@ public interface Cache<K, V> extends Iterable<V>, Serializable {
*/ */
V get(K key, boolean isUpdateLastAccess); V get(K key, boolean isUpdateLastAccess);
/**
* 返回缓存迭代器
*
* @return 缓存迭代器
*/
@Override
Iterator<V> iterator();
/** /**
* 返回包含键和值得迭代器 * 返回包含键和值得迭代器
* *

View File

@@ -45,8 +45,8 @@ public class LFUFileCache extends AbstractFileCache{
@Override @Override
protected Cache<File, byte[]> initCache() { protected Cache<File, byte[]> initCache() {
Cache<File, byte[]> cache = new LFUCache<File, byte[]>(this.capacity, this.timeout) { return new LFUCache<File, byte[]>(LFUFileCache.this.capacity, LFUFileCache.this.timeout) {
private static final long serialVersionUID = 1L; private static final long serialVersionUID1 = 1L;
@Override @Override
public boolean isFull() { public boolean isFull() {
@@ -58,7 +58,6 @@ public class LFUFileCache extends AbstractFileCache{
usedSize -= cachedObject.length; usedSize -= cachedObject.length;
} }
}; };
return cache;
} }
} }

View File

@@ -45,8 +45,8 @@ public class LRUFileCache extends AbstractFileCache{
@Override @Override
protected Cache<File, byte[]> initCache() { protected Cache<File, byte[]> initCache() {
Cache<File, byte[]> cache = new LRUCache<File, byte[]>(this.capacity, super.timeout) { return new LRUCache<File, byte[]>(LRUFileCache.this.capacity, super.timeout) {
private static final long serialVersionUID = 1L; private static final long serialVersionUID1 = 1L;
@Override @Override
public boolean isFull() { public boolean isFull() {
@@ -58,7 +58,6 @@ public class LRUFileCache extends AbstractFileCache{
usedSize -= cachedObject.length; usedSize -= cachedObject.length;
} }
}; };
return cache;
} }
} }

View File

@@ -20,7 +20,7 @@ public class CacheObj<K, V> implements Serializable{
/** 访问次数 */ /** 访问次数 */
protected long accessCount; protected long accessCount;
/** 对象存活时长0表示永久存活*/ /** 对象存活时长0表示永久存活*/
private long ttl; private final long ttl;
/** /**
* 构造 * 构造

View File

@@ -23,7 +23,6 @@ public class CacheObjIterator<K, V> implements Iterator<CacheObj<K, V>>, Seriali
* 构造 * 构造
* *
* @param iterator 原{@link Iterator} * @param iterator 原{@link Iterator}
* @param readLock 读锁
*/ */
CacheObjIterator(Iterator<CacheObj<K, V>> iterator) { CacheObjIterator(Iterator<CacheObj<K, V>> iterator) {
this.iterator = iterator; this.iterator = iterator;

View File

@@ -17,7 +17,6 @@ public class CacheValuesIterator<V> implements Iterator<V>, Serializable {
/** /**
* 构造 * 构造
* @param iterator 原{@link CacheObjIterator} * @param iterator 原{@link CacheObjIterator}
* @param readLock 读锁
*/ */
CacheValuesIterator(CacheObjIterator<?, V> iterator) { CacheValuesIterator(CacheObjIterator<?, V> iterator) {
this.cacheObjIter = iterator; this.cacheObjIter = iterator;

View File

@@ -1,14 +1,12 @@
package cn.hutool.cache.test; package cn.hutool.cache.test;
import org.junit.Assert;
import org.junit.Test;
import cn.hutool.cache.Cache; import cn.hutool.cache.Cache;
import cn.hutool.cache.CacheUtil; import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache; import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUnit;
import cn.hutool.core.lang.func.Func0;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import org.junit.Assert;
import org.junit.Test;
/** /**
* 缓存测试用例 * 缓存测试用例
@@ -27,7 +25,7 @@ public class CacheTest {
//由于缓存容量只有3当加入第四个元素的时候根据FIFO规则最先放入的对象将被移除 //由于缓存容量只有3当加入第四个元素的时候根据FIFO规则最先放入的对象将被移除
String value1 = fifoCache.get("key1"); String value1 = fifoCache.get("key1");
Assert.assertTrue(null == value1); Assert.assertNull(value1);
} }
@Test @Test
@@ -44,9 +42,9 @@ public class CacheTest {
String value1 = lfuCache.get("key1"); String value1 = lfuCache.get("key1");
String value2 = lfuCache.get("key2"); String value2 = lfuCache.get("key2");
String value3 = lfuCache.get("key3"); String value3 = lfuCache.get("key3");
Assert.assertTrue(null != value1); Assert.assertNotNull(value1);
Assert.assertTrue(null == value2); Assert.assertNull(value2);
Assert.assertTrue(null == value3); Assert.assertNull(value3);
} }
@Test @Test
@@ -84,21 +82,15 @@ public class CacheTest {
//5毫秒后由于value2设置了5毫秒过期因此只有value2被保留下来 //5毫秒后由于value2设置了5毫秒过期因此只有value2被保留下来
String value1 = timedCache.get("key1"); String value1 = timedCache.get("key1");
Assert.assertTrue(null == value1); Assert.assertNull(value1);
String value2 = timedCache.get("key2"); String value2 = timedCache.get("key2");
Assert.assertEquals("value2", value2); Assert.assertEquals("value2", value2);
//5毫秒后由于设置了默认过期key3只被保留4毫秒因此为null //5毫秒后由于设置了默认过期key3只被保留4毫秒因此为null
String value3 = timedCache.get("key3"); String value3 = timedCache.get("key3");
Assert.assertTrue(null == value3); Assert.assertNull(value3);
String value3Supplier = timedCache.get("key3", new Func0<String>() { String value3Supplier = timedCache.get("key3", () -> "Default supplier");
@Override
public String call() throws Exception {
return "Default supplier";
}
});
Assert.assertEquals("Default supplier", value3Supplier); Assert.assertEquals("Default supplier", value3Supplier);
// 永不过期 // 永不过期

View File

@@ -13,9 +13,9 @@ public abstract class AbstractGenerator implements CodeGenerator {
private static final long serialVersionUID = 8685744597154953479L; private static final long serialVersionUID = 8685744597154953479L;
/** 基础字符集合,用于随机获取字符串的字符集合 */ /** 基础字符集合,用于随机获取字符串的字符集合 */
protected String baseStr; protected final String baseStr;
/** 验证码长度 */ /** 验证码长度 */
protected int length; protected final int length;
/** /**
* 构造,使用字母+数字做为基础 * 构造,使用字母+数字做为基础

View File

@@ -42,12 +42,11 @@ public class MathGenerator implements CodeGenerator {
number1 = StrUtil.padAfter(number1, this.numberLength, CharUtil.SPACE); number1 = StrUtil.padAfter(number1, this.numberLength, CharUtil.SPACE);
number2 = StrUtil.padAfter(number2, this.numberLength, CharUtil.SPACE); number2 = StrUtil.padAfter(number2, this.numberLength, CharUtil.SPACE);
final String code = StrUtil.builder()// return StrUtil.builder()//
.append(number1)// .append(number1)//
.append(RandomUtil.randomChar(operators))// .append(RandomUtil.randomChar(operators))//
.append(number2)// .append(number2)//
.append('=').toString(); .append('=').toString();
return code;
} }
@Override @Override

View File

@@ -35,9 +35,9 @@ public class BeanDesc implements Serializable{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** Bean类 */ /** Bean类 */
private Class<?> beanClass; private final Class<?> beanClass;
/** 属性Map */ /** 属性Map */
private Map<String, PropDesc> propMap = new LinkedHashMap<>(); private final Map<String, PropDesc> propMap = new LinkedHashMap<>();
/** /**
* 构造 * 构造
@@ -300,11 +300,11 @@ public class BeanDesc implements Serializable{
public static class PropDesc { public static class PropDesc {
/** 字段 */ /** 字段 */
private Field field; private final Field field;
/** Getter方法 */ /** Getter方法 */
private Method getter; private final Method getter;
/** Setter方法 */ /** Setter方法 */
private Method setter; private final Method setter;
/** /**
* 构造<br> * 构造<br>

View File

@@ -11,7 +11,7 @@ import cn.hutool.core.lang.SimpleCache;
public enum BeanDescCache { public enum BeanDescCache {
INSTANCE; INSTANCE;
private SimpleCache<Class<?>, BeanDesc> bdCache = new SimpleCache<>(); private final SimpleCache<Class<?>, BeanDesc> bdCache = new SimpleCache<>();
/** /**
* 获得属性名和{@link BeanDesc}Map映射 * 获得属性名和{@link BeanDesc}Map映射

View File

@@ -14,8 +14,8 @@ import cn.hutool.core.lang.SimpleCache;
public enum BeanInfoCache { public enum BeanInfoCache {
INSTANCE; INSTANCE;
private SimpleCache<Class<?>, Map<String, PropertyDescriptor>> pdCache = new SimpleCache<>(); private final SimpleCache<Class<?>, Map<String, PropertyDescriptor>> pdCache = new SimpleCache<>();
private SimpleCache<Class<?>, Map<String, PropertyDescriptor>> ignoreCasePdCache = new SimpleCache<>(); private final SimpleCache<Class<?>, Map<String, PropertyDescriptor>> ignoreCasePdCache = new SimpleCache<>();
/** /**
* 获得属性名和{@link PropertyDescriptor}Map映射 * 获得属性名和{@link PropertyDescriptor}Map映射

View File

@@ -114,7 +114,6 @@ public class DynaBean extends CloneSupport<DynaBean> implements Serializable{
public void set(String fieldName, Object value) throws BeanException{ public void set(String fieldName, Object value) throws BeanException{
if(Map.class.isAssignableFrom(beanClass)){ if(Map.class.isAssignableFrom(beanClass)){
((Map)bean).put(fieldName, value); ((Map)bean).put(fieldName, value);
return;
}else{ }else{
try { try {
final Method setter = BeanUtil.getBeanDesc(beanClass).getSetter(fieldName); final Method setter = BeanUtil.getBeanDesc(beanClass).getSetter(fieldName);
@@ -179,13 +178,8 @@ public class DynaBean extends CloneSupport<DynaBean> implements Serializable{
} }
final DynaBean other = (DynaBean) obj; final DynaBean other = (DynaBean) obj;
if (bean == null) { if (bean == null) {
if (other.bean != null) { return other.bean == null;
return false; } else return bean.equals(other.bean);
}
} else if (!bean.equals(other.bean)) {
return false;
}
return true;
} }
@Override @Override

View File

@@ -36,13 +36,13 @@ public class BeanCopier<T> implements Copier<T>, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 源对象 */ /** 源对象 */
private Object source; private final Object source;
/** 目标对象 */ /** 目标对象 */
private T dest; private final T dest;
/** 目标的类型(用于泛型类注入) */ /** 目标的类型(用于泛型类注入) */
private Type destType; private final Type destType;
/** 拷贝选项 */ /** 拷贝选项 */
private CopyOptions copyOptions; private final CopyOptions copyOptions;
/** /**
* 创建BeanCopier * 创建BeanCopier

View File

@@ -18,8 +18,8 @@ import cn.hutool.core.util.StrUtil;
*/ */
public class BeanValueProvider implements ValueProvider<String> { public class BeanValueProvider implements ValueProvider<String> {
private Object source; private final Object source;
private boolean ignoreError; private final boolean ignoreError;
final Map<String, PropDesc> sourcePdMap; final Map<String, PropDesc> sourcePdMap;
/** /**

View File

@@ -47,13 +47,12 @@ public class MapValueProvider implements ValueProvider<String> {
@Override @Override
public boolean containsKey(String key) { public boolean containsKey(String key) {
//检查下划线模式
if(map.containsKey(key)) { if(map.containsKey(key)) {
return true; return true;
}else if(map.containsKey(StrUtil.toUnderlineCase(key))) { }else {
//检查下划线模式 return map.containsKey(StrUtil.toUnderlineCase(key));
return true;
} }
return false;
} }
} }

View File

@@ -9,7 +9,7 @@ package cn.hutool.core.codec;
public class Caesar { public class Caesar {
// 26个字母表 // 26个字母表
public static String table = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"; public static final String table = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
/** /**
* 传入明文,加密得到密文 * 传入明文,加密得到密文

View File

@@ -16,7 +16,7 @@ public class ArrayIter<E> implements Iterator<E>, Iterable<E>, Serializable{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 数组 */ /** 数组 */
private Object array; private final Object array;
/** 起始位置 */ /** 起始位置 */
private int startIndex; private int startIndex;
/** 结束位置 */ /** 结束位置 */

View File

@@ -18,8 +18,8 @@ public class BoundedPriorityQueue<E> extends PriorityQueue<E>{
private static final long serialVersionUID = 3794348988671694820L; private static final long serialVersionUID = 3794348988671694820L;
//容量 //容量
private int capacity; private final int capacity;
private Comparator<? super E> comparator; private final Comparator<? super E> comparator;
public BoundedPriorityQueue(int capacity) { public BoundedPriorityQueue(int capacity) {
this(capacity, null); this(capacity, null);
@@ -31,10 +31,7 @@ public class BoundedPriorityQueue<E> extends PriorityQueue<E>{
* @param comparator 比较器 * @param comparator 比较器
*/ */
public BoundedPriorityQueue(int capacity, final Comparator<? super E> comparator) { public BoundedPriorityQueue(int capacity, final Comparator<? super E> comparator) {
super(capacity, new Comparator<E>(){ super(capacity, (o1, o2) -> {
@Override
public int compare(E o1, E o2) {
int cResult; int cResult;
if(comparator != null) { if(comparator != null) {
cResult = comparator.compare(o1, o2); cResult = comparator.compare(o1, o2);
@@ -45,8 +42,6 @@ public class BoundedPriorityQueue<E> extends PriorityQueue<E>{
} }
return - cResult; return - cResult;
}
}); });
this.capacity = capacity; this.capacity = capacity;
this.comparator = comparator; this.comparator = comparator;
@@ -84,7 +79,7 @@ public class BoundedPriorityQueue<E> extends PriorityQueue<E>{
* @return 返回排序后的列表 * @return 返回排序后的列表
*/ */
public ArrayList<E> toList() { public ArrayList<E> toList() {
final ArrayList<E> list = new ArrayList<E>(this); final ArrayList<E> list = new ArrayList<>(this);
Collections.sort(list, comparator); Collections.sort(list, comparator);
return list; return list;
} }

View File

@@ -2366,7 +2366,7 @@ public class CollUtil {
*/ */
public static <T> List<List<T>> groupByField(Collection<T> collection, final String fieldName) { public static <T> List<List<T>> groupByField(Collection<T> collection, final String fieldName) {
return group(collection, new Hash<T>() { return group(collection, new Hash<T>() {
private List<Object> fieldNameList = new ArrayList<>(); private final List<Object> fieldNameList = new ArrayList<>();
@Override @Override
public int hash(T t) { public int hash(T t) {

View File

@@ -19,7 +19,7 @@ public class CompareUtil {
* @see java.util.Comparator#compare(Object, Object) * @see java.util.Comparator#compare(Object, Object)
* @since 4.6.9 * @since 4.6.9
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings({"rawtypes", "unchecked"})
public static <T> int compare(T c1, T c2, Comparator<T> comparator) { public static <T> int compare(T c1, T c2, Comparator<T> comparator) {
if (null == comparator) { if (null == comparator) {
return compare((Comparable)c1, (Comparable)c2); return compare((Comparable)c1, (Comparable)c2);

View File

@@ -62,7 +62,7 @@ public class PropertyComparator<T> implements Comparator<T>, Serializable {
return compare(o1, o2, v1, v2); return compare(o1, o2, v1, v2);
} }
@SuppressWarnings({ "rawtypes"}) @SuppressWarnings({"rawtypes", "unchecked"})
private int compare(T o1, T o2, Comparable fieldValue1, Comparable fieldValue2) { private int compare(T o1, T o2, Comparable fieldValue1, Comparable fieldValue2) {
int result = ObjectUtil.compare(fieldValue1, fieldValue2, isNullGreater); int result = ObjectUtil.compare(fieldValue1, fieldValue2, isNullGreater);
if(0 == result) { if(0 == result) {

View File

@@ -1,14 +1,13 @@
package cn.hutool.core.convert; package cn.hutool.core.convert;
import java.io.Serializable;
import java.util.Map;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.CharUtil; import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.ClassUtil; import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import java.io.Serializable;
import java.util.Map;
/** /**
* 抽象转换器提供通用的转换逻辑同时通过convertInternal实现对应类型的专属逻辑<br> * 抽象转换器提供通用的转换逻辑同时通过convertInternal实现对应类型的专属逻辑<br>
* 转换器不会抛出转换异常,转换失败时会返回{@code null} * 转换器不会抛出转换异常,转换失败时会返回{@code null}

View File

@@ -27,9 +27,9 @@ import cn.hutool.core.util.TypeUtil;
public class BeanConverter<T> extends AbstractConverter<T> { public class BeanConverter<T> extends AbstractConverter<T> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Type beanType; private final Type beanType;
private Class<T> beanClass; private final Class<T> beanClass;
private CopyOptions copyOptions; private final CopyOptions copyOptions;
/** /**
* 构造,默认转换选项,注入失败的字段忽略 * 构造,默认转换选项,注入失败的字段忽略

View File

@@ -1,14 +1,13 @@
package cn.hutool.core.convert.impl; package cn.hutool.core.convert.impl;
import java.time.temporal.TemporalAccessor;
import java.util.Calendar;
import cn.hutool.core.convert.AbstractConverter; import cn.hutool.core.convert.AbstractConverter;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import java.time.temporal.TemporalAccessor;
import java.util.Calendar;
/** /**
* 日期转换器 * 日期转换器
* *

View File

@@ -3,7 +3,6 @@ package cn.hutool.core.convert.impl;
import cn.hutool.core.convert.AbstractConverter; import cn.hutool.core.convert.AbstractConverter;
import java.time.Duration; import java.time.Duration;
import java.time.Period;
import java.time.temporal.TemporalAmount; import java.time.temporal.TemporalAmount;
/** /**

View File

@@ -2,7 +2,6 @@ package cn.hutool.core.convert.impl;
import cn.hutool.core.convert.AbstractConverter; import cn.hutool.core.convert.AbstractConverter;
import java.time.Period;
import java.util.Optional; import java.util.Optional;
/** /**

View File

@@ -4,7 +4,6 @@ import cn.hutool.core.convert.AbstractConverter;
import java.time.Period; import java.time.Period;
import java.time.temporal.TemporalAmount; import java.time.temporal.TemporalAmount;
import java.util.Optional;
/** /**
* *

View File

@@ -17,7 +17,7 @@ public class BetweenFormater implements Serializable{
/** 格式化级别 */ /** 格式化级别 */
private Level level; private Level level;
/** 格式化级别的最大个数 */ /** 格式化级别的最大个数 */
private int levelMaxCount; private final int levelMaxCount;
/** /**
* 构造 * 构造
@@ -137,7 +137,7 @@ public class BetweenFormater implements Serializable{
MILLSECOND("毫秒"); MILLSECOND("毫秒");
/** 级别名称 */ /** 级别名称 */
private String name; private final String name;
/** /**
* 构造 * 构造

View File

@@ -44,12 +44,7 @@ class FastDateParser extends AbstractDateBasic implements DateParser {
// comparator used to sort regex alternatives // comparator used to sort regex alternatives
// alternatives should be ordered longer first, and shorter last. ('february' before 'feb') // alternatives should be ordered longer first, and shorter last. ('february' before 'feb')
// all entries must be lowercase by locale. // all entries must be lowercase by locale.
private static final Comparator<String> LONGER_FIRST_LOWERCASE = new Comparator<String>(){ private static final Comparator<String> LONGER_FIRST_LOWERCASE = (left, right) -> right.compareTo(left);
@Override
public int compare(final String left, final String right) {
return right.compareTo(left);
}
};
/** /**
* <p> * <p>
@@ -389,7 +384,8 @@ class FastDateParser extends AbstractDateBasic implements DateParser {
/** /**
* Obtain a Strategy given a field from a SimpleDateFormat pattern * Obtain a Strategy given a field from a SimpleDateFormat pattern
* *
* @param formatField A sub-sequence of the SimpleDateFormat pattern * @param f 格式
* @param width 长度
* @param definingCalendar The calendar to obtain the short and long values * @param definingCalendar The calendar to obtain the short and long values
* @return The Strategy that will handle parsing for the field * @return The Strategy that will handle parsing for the field
*/ */

View File

@@ -223,10 +223,7 @@ abstract class FormatCache<F extends Format> {
return false; return false;
} }
final MultipartKey other = (MultipartKey) obj; final MultipartKey other = (MultipartKey) obj;
if (false == Arrays.equals(keys, other.keys)) { return false != Arrays.equals(keys, other.keys);
return false;
}
return true;
} }

View File

@@ -14,9 +14,6 @@ import cn.hutool.core.convert.Convert;
*/ */
public abstract class OptNullBasicTypeFromObjectGetter<K> extends OptNullBasicTypeGetter<K>{ public abstract class OptNullBasicTypeFromObjectGetter<K> extends OptNullBasicTypeGetter<K>{
@Override
public abstract Object getObj(K key, Object defaultValue);
@Override @Override
public String getStr(K key, String defaultValue) { public String getStr(K key, String defaultValue) {
final Object obj = getObj(key); final Object obj = getObj(key);

View File

@@ -14,9 +14,6 @@ import cn.hutool.core.convert.Convert;
*/ */
public abstract class OptNullBasicTypeFromStringGetter<K> extends OptNullBasicTypeGetter<K> { public abstract class OptNullBasicTypeFromStringGetter<K> extends OptNullBasicTypeGetter<K> {
@Override
public abstract String getStr(K key, String defaultValue);
@Override @Override
public Object getObj(K key, Object defaultValue) { public Object getObj(K key, Object defaultValue) {
return getStr(key, null == defaultValue ? null : defaultValue.toString()); return getStr(key, null == defaultValue ? null : defaultValue.toString());

View File

@@ -27,10 +27,11 @@ import cn.hutool.core.util.CharsetUtil;
* 参考: http://akini.mbnet.fi/java/unicodereader/UnicodeInputStream.java.txt * 参考: http://akini.mbnet.fi/java/unicodereader/UnicodeInputStream.java.txt
*/ */
public class BOMInputStream extends InputStream { public class BOMInputStream extends InputStream {
PushbackInputStream in;
boolean isInited = false; private final PushbackInputStream in;
String defaultCharset; private boolean isInited = false;
String charset; private final String defaultCharset;
private String charset;
private static final int BOM_SIZE = 4; private static final int BOM_SIZE = 4;

View File

@@ -38,10 +38,7 @@ public class IORuntimeException extends RuntimeException {
* @return 是否为指定类型异常 * @return 是否为指定类型异常
*/ */
public boolean causeInstanceOf(Class<? extends Throwable> clazz) { public boolean causeInstanceOf(Class<? extends Throwable> clazz) {
Throwable cause = this.getCause(); final Throwable cause = this.getCause();
if (null != cause && clazz.isInstance(cause)) { return null != clazz && clazz.isInstance(cause);
return true;
}
return false;
} }
} }

View File

@@ -22,8 +22,8 @@ import cn.hutool.core.util.StrUtil;
public class BytesResource implements Resource, Serializable { public class BytesResource implements Resource, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private byte[] bytes; private final byte[] bytes;
private String name; private final String name;
/** /**
* 构造 * 构造

View File

@@ -20,9 +20,9 @@ import cn.hutool.core.util.URLUtil;
public class ClassPathResource extends UrlResource { public class ClassPathResource extends UrlResource {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String path; private final String path;
private ClassLoader classLoader; private final ClassLoader classLoader;
private Class<?> clazz; private final Class<?> clazz;
// -------------------------------------------------------------------------------------- Constructor start // -------------------------------------------------------------------------------------- Constructor start
/** /**

View File

@@ -40,10 +40,7 @@ public class NoResourceException extends IORuntimeException {
* @return 是否为指定类型异常 * @return 是否为指定类型异常
*/ */
public boolean causeInstanceOf(Class<? extends Throwable> clazz) { public boolean causeInstanceOf(Class<? extends Throwable> clazz) {
Throwable cause = this.getCause(); final Throwable cause = this.getCause();
if (clazz.isInstance(cause)) { return clazz.isInstance(cause);
return true;
}
return false;
} }
} }

View File

@@ -31,27 +31,27 @@ public class ClassScanner implements Serializable {
/** /**
* 包名 * 包名
*/ */
private String packageName; private final String packageName;
/** /**
* 包名,最后跟一个点,表示包名,避免在检查前缀时的歧义 * 包名,最后跟一个点,表示包名,避免在检查前缀时的歧义
*/ */
private String packageNameWithDot; private final String packageNameWithDot;
/** /**
* 包路径,用于文件中对路径操作 * 包路径,用于文件中对路径操作
*/ */
private String packageDirName; private final String packageDirName;
/** /**
* 包路径用于jar中对路径操作在Linux下与packageDirName一致 * 包路径用于jar中对路径操作在Linux下与packageDirName一致
*/ */
private String packagePath; private final String packagePath;
/** /**
* 过滤器 * 过滤器
*/ */
private Filter<Class<?>> classFilter; private final Filter<Class<?>> classFilter;
/** /**
* 编码 * 编码
*/ */
private Charset charset; private final Charset charset;
/** /**
* 类加载器 * 类加载器
*/ */
@@ -60,8 +60,10 @@ public class ClassScanner implements Serializable {
* 是否初始化类 * 是否初始化类
*/ */
private boolean initialize; private boolean initialize;
/**
private Set<Class<?>> classes = new HashSet<>(); * 扫描结果集
*/
private final Set<Class<?>> classes = new HashSet<>();
/** /**
* 扫描指定包路径下所有包含指定注解的类 * 扫描指定包路径下所有包含指定注解的类
@@ -71,12 +73,7 @@ public class ClassScanner implements Serializable {
* @return 类集合 * @return 类集合
*/ */
public static Set<Class<?>> scanPackageByAnnotation(String packageName, final Class<? extends Annotation> annotationClass) { public static Set<Class<?>> scanPackageByAnnotation(String packageName, final Class<? extends Annotation> annotationClass) {
return scanPackage(packageName, new Filter<Class<?>>() { return scanPackage(packageName, clazz -> clazz.isAnnotationPresent(annotationClass));
@Override
public boolean accept(Class<?> clazz) {
return clazz.isAnnotationPresent(annotationClass);
}
});
} }
/** /**
@@ -87,12 +84,7 @@ public class ClassScanner implements Serializable {
* @return 类集合 * @return 类集合
*/ */
public static Set<Class<?>> scanPackageBySuper(String packageName, final Class<?> superClass) { public static Set<Class<?>> scanPackageBySuper(String packageName, final Class<?> superClass) {
return scanPackage(packageName, new Filter<Class<?>>() { return scanPackage(packageName, clazz -> superClass.isAssignableFrom(clazz) && !superClass.equals(clazz));
@Override
public boolean accept(Class<?> clazz) {
return superClass.isAssignableFrom(clazz) && !superClass.equals(clazz);
}
});
} }
/** /**

View File

@@ -54,7 +54,6 @@ public class ParameterizedTypeImpl implements ParameterizedType, Serializable {
final Type useOwner = this.ownerType; final Type useOwner = this.ownerType;
final Class<?> raw = (Class<?>) this.rawType; final Class<?> raw = (Class<?>) this.rawType;
final Type[] typeArguments = this.actualTypeArguments;
if (useOwner == null) { if (useOwner == null) {
buf.append(raw.getName()); buf.append(raw.getName());
} else { } else {
@@ -66,7 +65,7 @@ public class ParameterizedTypeImpl implements ParameterizedType, Serializable {
buf.append('.').append(raw.getSimpleName()); buf.append('.').append(raw.getSimpleName());
} }
appendAllTo(buf.append('<'), ", ", typeArguments).append('>'); appendAllTo(buf.append('<'), ", ", this.actualTypeArguments).append('>');
return buf.toString(); return buf.toString();
} }

View File

@@ -27,20 +27,20 @@ public class PatternPool {
/** IP v4 */ /** IP v4 */
public final static Pattern IPV4 = Pattern.compile("\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b"); public final static Pattern IPV4 = Pattern.compile("\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b");
/** IP v6 */ /** IP v6 */
public final static Pattern IPV6 = Pattern.compile("(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))"); public final static Pattern IPV6 = Pattern.compile("(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9]))");
/** 货币 */ /** 货币 */
public final static Pattern MONEY = Pattern.compile("^(\\d+(?:\\.\\d+)?)$"); public final static Pattern MONEY = Pattern.compile("^(\\d+(?:\\.\\d+)?)$");
/** 邮件符合RFC 5322规范正则来自http://emailregex.com/ */ /** 邮件符合RFC 5322规范正则来自http://emailregex.com/ */
// public final static Pattern EMAIL = Pattern.compile("(\\w|.)+@\\w+(\\.\\w+){1,2}"); // public final static Pattern EMAIL = Pattern.compile("(\\w|.)+@\\w+(\\.\\w+){1,2}");
public final static Pattern EMAIL = Pattern.compile("(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])", Pattern.CASE_INSENSITIVE); public final static Pattern EMAIL = Pattern.compile("(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)])", Pattern.CASE_INSENSITIVE);
/** 移动电话 */ /** 移动电话 */
public final static Pattern MOBILE = Pattern.compile("(?:0|86|\\+86)?1[3456789]\\d{9}"); public final static Pattern MOBILE = Pattern.compile("(?:0|86|\\+86)?1[3456789]\\d{9}");
/** 18位身份证号码 */ /** 18位身份证号码 */
public final static Pattern CITIZEN_ID = Pattern.compile("[1-9]\\d{5}[1-2]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}(\\d|X|x)"); public final static Pattern CITIZEN_ID = Pattern.compile("[1-9]\\d{5}[1-2]\\d{3}((0\\d)|(1[0-2]))(([012]\\d)|3[0-1])\\d{3}(\\d|X|x)");
/** 邮编 */ /** 邮编 */
public final static Pattern ZIP_CODE = Pattern.compile("[1-9]\\d{5}(?!\\d)"); public final static Pattern ZIP_CODE = Pattern.compile("[1-9]\\d{5}(?!\\d)");
/** 生日 */ /** 生日 */
public final static Pattern BIRTHDAY = Pattern.compile("^(\\d{2,4})([/\\-\\.年]?)(\\d{1,2})([/\\-\\.月]?)(\\d{1,2})日?$"); public final static Pattern BIRTHDAY = Pattern.compile("^(\\d{2,4})([/\\-.年]?)(\\d{1,2})([/\\-.月]?)(\\d{1,2})日?$");
/** URL */ /** URL */
public final static Pattern URL = Pattern.compile("[a-zA-z]+://[^\\s]*"); public final static Pattern URL = Pattern.compile("[a-zA-z]+://[^\\s]*");
/** Http URL */ /** Http URL */
@@ -157,13 +157,10 @@ public class PatternPool {
return false; return false;
} }
if (regex == null) { if (regex == null) {
if (other.regex != null) { return other.regex == null;
return false; } else {
return regex.equals(other.regex);
} }
} else if (!regex.equals(other.regex)) {
return false;
}
return true;
} }
} }

View File

@@ -66,10 +66,7 @@ public class Tuple extends CloneSupport<Tuple> implements Iterable<Object>, Seri
return false; return false;
} }
Tuple other = (Tuple) obj; Tuple other = (Tuple) obj;
if (false == Arrays.deepEquals(members, other.members)) { return false != Arrays.deepEquals(members, other.members);
return false;
}
return true;
} }
@Override @Override

View File

@@ -18,7 +18,7 @@ import cn.hutool.core.util.NumberUtil;
public class Arrangement implements Serializable { public class Arrangement implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String[] datas; private final String[] datas;
/** /**
* 构造 * 构造
@@ -106,7 +106,6 @@ public class Arrangement implements Serializable {
* 排列方式为先从数据数组中取出一个元素,再把剩余的元素作为新的基数,依次列推,直到选择到足够的元素 * 排列方式为先从数据数组中取出一个元素,再把剩余的元素作为新的基数,依次列推,直到选择到足够的元素
* *
* @param datas 选择的基数 * @param datas 选择的基数
* @param dataList 待选列表
* @param resultList 前面resultIndex-1个的排列结果 * @param resultList 前面resultIndex-1个的排列结果
* @param resultIndex 选择索引从0开始 * @param resultIndex 选择索引从0开始
* @param result 最终结果 * @param result 最终结果

View File

@@ -14,10 +14,10 @@ import cn.hutool.core.util.NumberUtil;
* @author looly * @author looly
* @since 4.0.6 * @since 4.0.6
*/ */
public class Combination implements Serializable{ public class Combination implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String[] datas; private final String[] datas;
/** /**
* 组合即C(n, m)<br> * 组合即C(n, m)<br>
@@ -37,10 +37,10 @@ public class Combination implements Serializable{
* @return 组合数 * @return 组合数
*/ */
public static long count(int n, int m) { public static long count(int n, int m) {
if(0 == m) { if (0 == m) {
return 1; return 1;
} }
if(n == m) { if (n == m) {
return NumberUtil.factorial(n) / NumberUtil.factorial(m); return NumberUtil.factorial(n) / NumberUtil.factorial(m);
} }
return (n > m) ? NumberUtil.factorial(n, n - m) / NumberUtil.factorial(m) : 0; return (n > m) ? NumberUtil.factorial(n, n - m) / NumberUtil.factorial(m) : 0;
@@ -54,7 +54,7 @@ public class Combination implements Serializable{
*/ */
public static long countAll(int n) { public static long countAll(int n) {
long total = 0; long total = 0;
for(int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) {
total += count(n, i); total += count(n, i);
} }
return total; return total;
@@ -77,9 +77,9 @@ public class Combination implements Serializable{
* *
* @return 全排列结果 * @return 全排列结果
*/ */
public List<String[]> selectAll(){ public List<String[]> selectAll() {
final List<String[]> result = new ArrayList<>((int)countAll(this.datas.length)); final List<String[]> result = new ArrayList<>((int) countAll(this.datas.length));
for(int i = 1; i <= this.datas.length; i++) { for (int i = 1; i <= this.datas.length; i++) {
result.addAll(select(i)); result.addAll(select(i));
} }
return result; return result;
@@ -88,10 +88,10 @@ public class Combination implements Serializable{
/** /**
* 组合选择 * 组合选择
* *
* @param dataList 待选列表
* @param dataIndex 待选开始索引 * @param dataIndex 待选开始索引
* @param resultList 前面resultIndex-1个的组合结果 * @param resultList 前面resultIndex-1个的组合结果
* @param resultIndex 选择索引从0开始 * @param resultIndex 选择索引从0开始
* @param result 结果集
*/ */
private void select(int dataIndex, String[] resultList, int resultIndex, List<String[]> result) { private void select(int dataIndex, String[] resultList, int resultIndex, List<String[]> result) {
int resultLen = resultList.length; int resultLen = resultList.length;

View File

@@ -29,9 +29,9 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
/** 重试等待 */ /** 重试等待 */
private long delay; private long delay;
/** 系统剪贴板对象 */ /** 系统剪贴板对象 */
private Clipboard clipboard; private final Clipboard clipboard;
/** 监听事件处理 */ /** 监听事件处理 */
private Set<ClipboardListener> listenerSet = new LinkedHashSet<>(); private final Set<ClipboardListener> listenerSet = new LinkedHashSet<>();
/** 是否正在监听 */ /** 是否正在监听 */
private boolean isRunning; private boolean isRunning;

View File

@@ -65,7 +65,7 @@ public class BooleanUtil {
* @return 相反的Boolean值 * @return 相反的Boolean值
*/ */
public static boolean negate(boolean bool) { public static boolean negate(boolean bool) {
return bool ? false : true; return !bool;
} }
/** /**

View File

@@ -33,11 +33,11 @@ public class ClassLoaderUtil {
private static final char INNER_CLASS_SEPARATOR = '$'; private static final char INNER_CLASS_SEPARATOR = '$';
/** 原始类型名和其class对应表例如int =》 int.class */ /** 原始类型名和其class对应表例如int =》 int.class */
private static final Map<String, Class<?>> primitiveTypeNameMap = new ConcurrentHashMap<String, Class<?>>(32); private static final Map<String, Class<?>> primitiveTypeNameMap = new ConcurrentHashMap<>(32);
private static SimpleCache<String, Class<?>> classCache = new SimpleCache<>(); private static final SimpleCache<String, Class<?>> classCache = new SimpleCache<>();
static { static {
List<Class<?>> primitiveTypes = new ArrayList<Class<?>>(32); List<Class<?>> primitiveTypes = new ArrayList<>(32);
// 加入原始类型 // 加入原始类型
primitiveTypes.addAll(BasicType.primitiveWrapperMap.keySet()); primitiveTypes.addAll(BasicType.primitiveWrapperMap.keySet());
// 加入原始类型数组类型 // 加入原始类型数组类型

View File

@@ -1,5 +1,13 @@
package cn.hutool.core.util; package cn.hutool.core.util;
import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.net.URLEncoder;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -15,15 +23,6 @@ import java.net.URLStreamHandler;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Console;
import cn.hutool.core.net.URLEncoder;
/** /**
* 统一资源定位符相关工具类 * 统一资源定位符相关工具类
* *

View File

@@ -3,10 +3,6 @@ package cn.hutool.core.clone;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import cn.hutool.core.clone.CloneRuntimeException;
import cn.hutool.core.clone.CloneSupport;
import cn.hutool.core.clone.Cloneable;
/** /**
* 克隆单元测试 * 克隆单元测试
* @author Looly * @author Looly
@@ -72,13 +68,8 @@ public class CloneTest {
return false; return false;
} }
if (name == null) { if (name == null) {
if (other.name != null) { return other.name == null;
return false; } else return name.equals(other.name);
}
} else if (!name.equals(other.name)) {
return false;
}
return true;
} }
} }
@@ -116,13 +107,8 @@ public class CloneTest {
return false; return false;
} }
if (name == null) { if (name == null) {
if (other.name != null) { return other.name == null;
return false; } else return name.equals(other.name);
}
} else if (!name.equals(other.name)) {
return false;
}
return true;
} }
} }
} }

View File

@@ -1,5 +1,13 @@
package cn.hutool.core.collection; package cn.hutool.core.collection;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.lang.Editor;
import cn.hutool.core.lang.Filter;
import cn.hutool.core.map.MapUtil;
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
@@ -12,19 +20,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import cn.hutool.core.collection.CollUtil.Hash;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.lang.Editor;
import cn.hutool.core.lang.Filter;
import cn.hutool.core.lang.Matcher;
import cn.hutool.core.map.MapUtil;
/** /**
* 集合工具类单元测试 * 集合工具类单元测试
* *
@@ -63,14 +58,7 @@ public class CollUtilTest {
Collection<String> union = CollectionUtil.union(list1, list2); Collection<String> union = CollectionUtil.union(list1, list2);
Assert.assertEquals(3, CollectionUtil.count(union, new Matcher<String>() { Assert.assertEquals(3, CollectionUtil.count(union, t -> t.equals("b")));
@Override
public boolean match(String t) {
return t.equals("b");
}
}));
} }
@Test @Test
@@ -79,14 +67,7 @@ public class CollUtilTest {
ArrayList<String> list2 = CollectionUtil.newArrayList("a", "b", "b", "b", "c", "d"); ArrayList<String> list2 = CollectionUtil.newArrayList("a", "b", "b", "b", "c", "d");
Collection<String> union = CollectionUtil.intersection(list1, list2); Collection<String> union = CollectionUtil.intersection(list1, list2);
Assert.assertEquals(2, CollectionUtil.count(union, new Matcher<String>() { Assert.assertEquals(2, CollectionUtil.count(union, t -> t.equals("b")));
@Override
public boolean match(String t) {
return t.equals("b");
}
}));
} }
@Test @Test
@@ -188,13 +169,10 @@ public class CollUtilTest {
map.put("c", "3"); map.put("c", "3");
final String[] result = new String[1]; final String[] result = new String[1];
CollectionUtil.forEach(map, new CollUtil.KVConsumer<String, String>() { CollectionUtil.forEach(map, (key, value, index) -> {
@Override
public void accept(String key, String value, int index) {
if (key.equals("a")) { if (key.equals("a")) {
result[0] = value; result[0] = value;
} }
}
}); });
Assert.assertEquals("1", result[0]); Assert.assertEquals("1", result[0]);
} }
@@ -203,12 +181,7 @@ public class CollUtilTest {
public void filterTest() { public void filterTest() {
ArrayList<String> list = CollUtil.newArrayList("a", "b", "c"); ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
Collection<String> filtered = CollUtil.filter(list, new Editor<String>() { Collection<String> filtered = CollUtil.filter(list, (Editor<String>) t -> t + 1);
@Override
public String edit(String t) {
return t + 1;
}
});
Assert.assertEquals(CollUtil.newArrayList("a1", "b1", "c1"), filtered); Assert.assertEquals(CollUtil.newArrayList("a1", "b1", "c1"), filtered);
} }
@@ -217,16 +190,10 @@ public class CollUtilTest {
public void filterTest2() { public void filterTest2() {
ArrayList<String> list = CollUtil.newArrayList("a", "b", "c"); ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
ArrayList<String> filtered = CollUtil.filter(list, new Filter<String>() { ArrayList<String> filtered = CollUtil.filter(list, (Filter<String>) t -> false == "a".equals(t));
@Override
public boolean accept(String t) {
return false == "a".equals(t);
}
});
// 原地过滤 // 原地过滤
Assert.assertTrue(list == filtered); Assert.assertSame(list, filtered);
Assert.assertEquals(CollUtil.newArrayList("b", "c"), filtered); Assert.assertEquals(CollUtil.newArrayList("b", "c"), filtered);
} }
@@ -237,7 +204,7 @@ public class CollUtilTest {
ArrayList<String> filtered = CollUtil.removeNull(list); ArrayList<String> filtered = CollUtil.removeNull(list);
// 原地过滤 // 原地过滤
Assert.assertTrue(list == filtered); Assert.assertSame(list, filtered);
Assert.assertEquals(CollUtil.newArrayList("a", "b", "c", "", " "), filtered); Assert.assertEquals(CollUtil.newArrayList("a", "b", "c", "", " "), filtered);
} }
@@ -248,7 +215,7 @@ public class CollUtilTest {
ArrayList<String> filtered = CollUtil.removeEmpty(list); ArrayList<String> filtered = CollUtil.removeEmpty(list);
// 原地过滤 // 原地过滤
Assert.assertTrue(list == filtered); Assert.assertSame(list, filtered);
Assert.assertEquals(CollUtil.newArrayList("a", "b", "c", " "), filtered); Assert.assertEquals(CollUtil.newArrayList("a", "b", "c", " "), filtered);
} }
@@ -259,7 +226,7 @@ public class CollUtilTest {
ArrayList<String> filtered = CollUtil.removeBlank(list); ArrayList<String> filtered = CollUtil.removeBlank(list);
// 原地过滤 // 原地过滤
Assert.assertTrue(list == filtered); Assert.assertSame(list, filtered);
Assert.assertEquals(CollUtil.newArrayList("a", "b", "c"), filtered); Assert.assertEquals(CollUtil.newArrayList("a", "b", "c"), filtered);
} }
@@ -269,13 +236,9 @@ public class CollUtilTest {
List<List<String>> group = CollectionUtil.group(list, null); List<List<String>> group = CollectionUtil.group(list, null);
Assert.assertTrue(group.size() > 0); Assert.assertTrue(group.size() > 0);
List<List<String>> group2 = CollectionUtil.group(list, new Hash<String>() { List<List<String>> group2 = CollectionUtil.group(list, t -> {
@Override
public int hash(String t) {
// 按照奇数偶数分类 // 按照奇数偶数分类
return Integer.parseInt(t) % 2; return Integer.parseInt(t) % 2;
}
}); });
Assert.assertEquals(CollUtil.newArrayList("2", "4", "6"), group2.get(0)); Assert.assertEquals(CollUtil.newArrayList("2", "4", "6"), group2.get(0));
Assert.assertEquals(CollUtil.newArrayList("1", "3", "5"), group2.get(1)); Assert.assertEquals(CollUtil.newArrayList("1", "3", "5"), group2.get(1));
@@ -497,10 +460,7 @@ public class CollUtilTest {
Assert.assertEquals(arrayList, retval); Assert.assertEquals(arrayList, retval);
} }
@Rule @Test(expected = IndexOutOfBoundsException.class)
public ExpectedException thrown = ExpectedException.none();
@Test
public void subInput1PositiveNegativePositiveOutputArrayIndexOutOfBoundsException() { public void subInput1PositiveNegativePositiveOutputArrayIndexOutOfBoundsException() {
// Arrange // Arrange
final List<Integer> list = new ArrayList<>(); final List<Integer> list = new ArrayList<>();
@@ -510,7 +470,6 @@ public class CollUtilTest {
final int step = 2; final int step = 2;
// Act // Act
thrown.expect(ArrayIndexOutOfBoundsException.class);
CollUtil.sub(list, start, end, step); CollUtil.sub(list, start, end, step);
// Method is not expected to return due to exception thrown // Method is not expected to return due to exception thrown
} }
@@ -588,13 +547,7 @@ public class CollUtilTest {
@Test @Test
public void sortPageAllTest() { public void sortPageAllTest() {
ArrayList<Integer> list = CollUtil.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9); ArrayList<Integer> list = CollUtil.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9);
List<Integer> sortPageAll = CollUtil.sortPageAll(2, 5, new Comparator<Integer>() { List<Integer> sortPageAll = CollUtil.sortPageAll(2, 5, Comparator.reverseOrder(), list);
@Override
public int compare(Integer o1, Integer o2) {
// 反序
return o2.compareTo(o1);
}
}, list);
Assert.assertEquals(CollUtil.newArrayList(4, 3, 2, 1), sortPageAll); Assert.assertEquals(CollUtil.newArrayList(4, 3, 2, 1), sortPageAll);
} }

View File

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

View File

@@ -1,7 +1,6 @@
package cn.hutool.core.convert; package cn.hutool.core.convert;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Console;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;

View File

@@ -52,7 +52,7 @@ public class ArrangementTest {
Assert.assertEquals(Arrangement.countAll(4), selectAll.size()); Assert.assertEquals(Arrangement.countAll(4), selectAll.size());
List<String[]> list2 = arrangement.select(0); List<String[]> list2 = arrangement.select(0);
Assert.assertTrue(1 == list2.size()); Assert.assertEquals(1, list2.size());
} }
@Test @Test

View File

@@ -61,7 +61,7 @@ public class ClassUtilTest {
} }
@Test @Test
public void getDeclaredMethod() throws Exception { public void getDeclaredMethod() {
Method noMethod = ClassUtil.getDeclaredMethod(TestSubClass.class, "noMethod"); Method noMethod = ClassUtil.getDeclaredMethod(TestSubClass.class, "noMethod");
Assert.assertNull(noMethod); Assert.assertNull(noMethod);

View File

@@ -1,6 +1,5 @@
package cn.hutool.core.util; package cn.hutool.core.util;
import cn.hutool.core.lang.Console;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;

View File

@@ -21,10 +21,6 @@ import cn.hutool.core.map.MapUtil;
*/ */
public class XmlUtilTest { public class XmlUtilTest {
@Test
public void buildTest() {
}
@Test @Test
public void parseTest() { public void parseTest() {
String result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"// String result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"//

View File

@@ -16,12 +16,10 @@ public class SimpleTaskListener implements TaskListener{
@Override @Override
public void onSucceeded(TaskExecutor executor) { public void onSucceeded(TaskExecutor executor) {
} }
@Override @Override
public void onFailed(TaskExecutor executor, Throwable exception) { public void onFailed(TaskExecutor executor, Throwable exception) {
} }
} }

View File

@@ -12,7 +12,7 @@ import cn.hutool.core.util.StrUtil;
*/ */
public class BoolArrayValueMatcher implements ValueMatcher{ public class BoolArrayValueMatcher implements ValueMatcher{
boolean[] bValues; private final boolean[] bValues;
public BoolArrayValueMatcher(List<Integer> intValueList) { public BoolArrayValueMatcher(List<Integer> intValueList) {
bValues = new boolean[Collections.max(intValueList) + 1]; bValues = new boolean[Collections.max(intValueList) + 1];

View File

@@ -19,7 +19,6 @@ import cn.hutool.cron.CronException;
*/ */
public class InvokeTask implements Task{ public class InvokeTask implements Task{
private Class<?> clazz;
private Object obj; private Object obj;
private Method method; private Method method;
@@ -41,18 +40,18 @@ public class InvokeTask implements Task{
if(StrUtil.isBlank(className)) { if(StrUtil.isBlank(className)) {
throw new IllegalArgumentException("Class name is blank !"); throw new IllegalArgumentException("Class name is blank !");
} }
this.clazz = ClassLoaderUtil.loadClass(className); final Class<?> clazz = ClassLoaderUtil.loadClass(className);
if(null == this.clazz) { if(null == clazz) {
throw new IllegalArgumentException("Load class with name of [" + className + "] fail !"); throw new IllegalArgumentException("Load class with name of [" + className + "] fail !");
} }
this.obj = ReflectUtil.newInstanceIfPossible(this.clazz); this.obj = ReflectUtil.newInstanceIfPossible(clazz);
//方法 //方法
final String methodName = classNameWithMethodName.substring(splitIndex + 1); final String methodName = classNameWithMethodName.substring(splitIndex + 1);
if(StrUtil.isBlank(methodName)) { if(StrUtil.isBlank(methodName)) {
throw new IllegalArgumentException("Method name is blank !"); throw new IllegalArgumentException("Method name is blank !");
} }
this.method = ClassUtil.getPublicMethod(this.clazz, methodName); this.method = ClassUtil.getPublicMethod(clazz, methodName);
if(null == this.method) { if(null == this.method) {
throw new IllegalArgumentException("No method with name of [" + methodName + "] !"); throw new IllegalArgumentException("No method with name of [" + methodName + "] !");
} }

View File

@@ -26,6 +26,7 @@ public class TestJob {
/** /**
* 执行循环定时任务测试在定时任务结束时作为deamon线程是否能正常结束 * 执行循环定时任务测试在定时任务结束时作为deamon线程是否能正常结束
*/ */
@SuppressWarnings("InfiniteLoopStatement")
public void doWhileTest() { public void doWhileTest() {
String name = Thread.currentThread().getName(); String name = Thread.currentThread().getName();
while (true) { while (true) {

View File

@@ -1,30 +1,9 @@
package cn.hutool.crypto; package cn.hutool.crypto;
import java.io.File;
import java.io.InputStream;
import java.security.KeyPair;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
import java.security.Security;
import java.security.Signature;
import java.security.cert.Certificate;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.KeySpec;
import java.util.Map;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import cn.hutool.core.codec.Base64; import cn.hutool.core.codec.Base64;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Validator; import cn.hutool.core.lang.Validator;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.HexUtil; import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
@@ -43,6 +22,25 @@ import cn.hutool.crypto.symmetric.DESede;
import cn.hutool.crypto.symmetric.RC4; import cn.hutool.crypto.symmetric.RC4;
import cn.hutool.crypto.symmetric.SymmetricCrypto; import cn.hutool.crypto.symmetric.SymmetricCrypto;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import java.io.File;
import java.io.InputStream;
import java.security.KeyPair;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
import java.security.Security;
import java.security.Signature;
import java.security.cert.Certificate;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.KeySpec;
import java.util.Map;
/** /**
* 安全相关工具类<br> * 安全相关工具类<br>
* 加密分为三种:<br> * 加密分为三种:<br>

View File

@@ -17,7 +17,7 @@ public enum AsymmetricAlgorithm {
/** ECElliptic Curve算法 */ /** ECElliptic Curve算法 */
EC("EC"); EC("EC");
private String value; private final String value;
/** /**
* 构造 * 构造

View File

@@ -26,7 +26,7 @@ public class BaseAsymmetric<T extends BaseAsymmetric<T>>{
/** 私钥 */ /** 私钥 */
protected PrivateKey privateKey; protected PrivateKey privateKey;
/** 锁 */ /** 锁 */
protected Lock lock = new ReentrantLock(); protected final Lock lock = new ReentrantLock();
// ------------------------------------------------------------------ Constructor start // ------------------------------------------------------------------ Constructor start
/** /**

View File

@@ -1,25 +1,21 @@
package cn.hutool.crypto.test; package cn.hutool.crypto.test;
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import cn.hutool.core.codec.Base64; import cn.hutool.core.codec.Base64;
import cn.hutool.core.lang.Console; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.*; import cn.hutool.core.util.CharsetUtil;
import org.junit.Assert; import cn.hutool.core.util.HexUtil;
import org.junit.Test; import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.KeyUtil; import cn.hutool.crypto.KeyUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.KeyType; import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA; import cn.hutool.crypto.asymmetric.RSA;
import org.junit.Assert;
import org.junit.Test;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException; import java.security.KeyPair;
import javax.crypto.NoSuchPaddingException; import java.security.PublicKey;
/** /**
* RSA算法单元测试 * RSA算法单元测试

View File

@@ -33,7 +33,7 @@ import cn.hutool.db.sql.Wrapper;
public abstract class AbstractDb implements Serializable { public abstract class AbstractDb implements Serializable {
private static final long serialVersionUID = 3858951941916349062L; private static final long serialVersionUID = 3858951941916349062L;
protected DataSource ds; protected final DataSource ds;
/** /**
* 是否支持事务 * 是否支持事务
*/ */

View File

@@ -15,7 +15,7 @@ import cn.hutool.core.map.MapUtil;
public class ActiveEntity extends Entity { public class ActiveEntity extends Entity {
private static final long serialVersionUID = 6112321379601134750L; private static final long serialVersionUID = 6112321379601134750L;
private Db db; private final Db db;
// --------------------------------------------------------------- Static method start // --------------------------------------------------------------- Static method start
/** /**

View File

@@ -44,7 +44,6 @@ public class HikariDSFactory extends AbstractDSFactory {
config.put("password", pass); config.put("password", pass);
} }
final HikariDataSource ds = new HikariDataSource(new HikariConfig(config)); return new HikariDataSource(new HikariConfig(config));
return ds;
} }
} }

View File

@@ -14,7 +14,7 @@ import java.sql.SQLException;
public class BeanHandler<E> implements RsHandler<E>{ public class BeanHandler<E> implements RsHandler<E>{
private static final long serialVersionUID = -5491214744966544475L; private static final long serialVersionUID = -5491214744966544475L;
private Class<E> elementBeanType; private final Class<E> elementBeanType;
/** /**
* 创建一个 BeanHandler对象 * 创建一个 BeanHandler对象
@@ -24,7 +24,7 @@ public class BeanHandler<E> implements RsHandler<E>{
* @return BeanHandler对象 * @return BeanHandler对象
*/ */
public static <E> BeanHandler<E> create(Class<E> beanType) { public static <E> BeanHandler<E> create(Class<E> beanType) {
return new BeanHandler<E>(beanType); return new BeanHandler<>(beanType);
} }
public BeanHandler(Class<E> beanType) { public BeanHandler(Class<E> beanType) {

View File

@@ -15,7 +15,7 @@ import java.util.List;
public class BeanListHandler<E> implements RsHandler<List<E>> { public class BeanListHandler<E> implements RsHandler<List<E>> {
private static final long serialVersionUID = 4510569754766197707L; private static final long serialVersionUID = 4510569754766197707L;
private Class<E> elementBeanType; private final Class<E> elementBeanType;
/** /**
* 创建一个 BeanListHandler对象 * 创建一个 BeanListHandler对象
@@ -25,7 +25,7 @@ public class BeanListHandler<E> implements RsHandler<List<E>> {
* @return BeanListHandler对象 * @return BeanListHandler对象
*/ */
public static <E> BeanListHandler<E> create(Class<E> beanType) { public static <E> BeanListHandler<E> create(Class<E> beanType) {
return new BeanListHandler<E>(beanType); return new BeanListHandler<>(beanType);
} }
/** /**
@@ -38,6 +38,6 @@ public class BeanListHandler<E> implements RsHandler<List<E>> {
@Override @Override
public List<E> handle(ResultSet rs) throws SQLException { public List<E> handle(ResultSet rs) throws SQLException {
return HandleHelper.handleRsToBeanList(rs, new ArrayList<E>(), elementBeanType); return HandleHelper.handleRsToBeanList(rs, new ArrayList<>(), elementBeanType);
} }
} }

View File

@@ -222,13 +222,11 @@ public class Ftp extends AbstractFtp {
return false; return false;
} }
boolean flag = true;
try { try {
flag = client.changeWorkingDirectory(directory); return client.changeWorkingDirectory(directory);
} catch (IOException e) { } catch (IOException e) {
throw new FtpException(e); throw new FtpException(e);
} }
return flag;
} }
/** /**
@@ -285,13 +283,11 @@ public class Ftp extends AbstractFtp {
@Override @Override
public boolean mkdir(String dir) { public boolean mkdir(String dir) {
boolean flag = true;
try { try {
flag = this.client.makeDirectory(dir); return this.client.makeDirectory(dir);
} catch (IOException e) { } catch (IOException e) {
throw new FtpException(e); throw new FtpException(e);
} }
return flag;
} }
/** /**
@@ -307,10 +303,7 @@ public class Ftp extends AbstractFtp {
} catch (IOException e) { } catch (IOException e) {
throw new FtpException(e); throw new FtpException(e);
} }
if (ArrayUtil.isNotEmpty(ftpFileArr)) { return ArrayUtil.isNotEmpty(ftpFileArr);
return true;
}
return false;
} }
@Override @Override

View File

@@ -1,12 +1,11 @@
package cn.hutool.extra.servlet.multipart; package cn.hutool.extra.servlet.multipart;
import java.net.URL;
import cn.hutool.core.util.URLUtil; import cn.hutool.core.util.URLUtil;
import cn.hutool.log.Log; import cn.hutool.log.Log;
import cn.hutool.log.StaticLog;
import cn.hutool.setting.Setting; import cn.hutool.setting.Setting;
import java.net.URL;
/** /**
* 上传文件设定文件 * 上传文件设定文件
* *

View File

@@ -27,7 +27,7 @@ public enum ChannelType {
SUBSYSTEM("subsystem"); SUBSYSTEM("subsystem");
/** channel值 */ /** channel值 */
private String value; private final String value;
/** /**
* 构造 * 构造

View File

@@ -221,10 +221,10 @@ public class JschUtil {
public static boolean unBindPort(Session session, int localPort) { public static boolean unBindPort(Session session, int localPort) {
try { try {
session.delPortForwardingL(localPort); session.delPortForwardingL(localPort);
return true;
} catch (JSchException e) { } catch (JSchException e) {
throw new JschRuntimeException(e); throw new JschRuntimeException(e);
} }
return true;
} }
/** /**

View File

@@ -181,9 +181,6 @@ public class TemplateConfig implements Serializable {
} else if (!path.equals(other.path)) { } else if (!path.equals(other.path)) {
return false; return false;
} }
if (resourceMode != other.resourceMode) { return resourceMode == other.resourceMode;
return false;
}
return true;
} }
} }

View File

@@ -23,7 +23,7 @@ import cn.hutool.extra.template.TemplateEngine;
*/ */
public class BeetlEngine implements TemplateEngine { public class BeetlEngine implements TemplateEngine {
private GroupTemplate engine; private final GroupTemplate engine;
// --------------------------------------------------------------------------------- Constructor start // --------------------------------------------------------------------------------- Constructor start
/** /**

View File

@@ -15,7 +15,7 @@ import cn.hutool.extra.template.AbstractTemplate;
public class BeetlTemplate extends AbstractTemplate implements Serializable{ public class BeetlTemplate extends AbstractTemplate implements Serializable{
private static final long serialVersionUID = -8157926902932567280L; private static final long serialVersionUID = -8157926902932567280L;
org.beetl.core.Template rawTemplate; private final org.beetl.core.Template rawTemplate;
/** /**
* 包装Beetl模板 * 包装Beetl模板

View File

@@ -254,7 +254,7 @@ public final class BeetlUtil {
* *
*/ */
public static class ResourceLoaderBuilder { public static class ResourceLoaderBuilder {
private CompositeResourceLoader compositeResourceLoader = new CompositeResourceLoader(); private final CompositeResourceLoader compositeResourceLoader = new CompositeResourceLoader();
/** /**
* 创建 * 创建

View File

@@ -66,7 +66,6 @@ public class RythmEngine implements TemplateEngine {
props.put("home.template", path); props.put("home.template", path);
} }
final org.rythmengine.RythmEngine engine = new org.rythmengine.RythmEngine(props); return new org.rythmengine.RythmEngine(props);
return engine;
} }
} }

View File

@@ -1,12 +1,14 @@
package cn.hutool.extra.tokenizer; package cn.hutool.extra.tokenizer;
import java.io.Serializable;
/** /**
* 表示分词中的一个词 * 表示分词中的一个词
* *
* @author looly * @author looly
* *
*/ */
public interface Word { public interface Word extends Serializable {
/** /**
* 获取单词文本 * 获取单词文本

View File

@@ -19,7 +19,7 @@ import cn.hutool.extra.tokenizer.TokenizerException;
*/ */
public class AnalysisEngine implements TokenizerEngine { public class AnalysisEngine implements TokenizerEngine {
private Analyzer analyzer; private final Analyzer analyzer;
/** /**
* 构造 * 构造

View File

@@ -18,7 +18,7 @@ import cn.hutool.extra.tokenizer.Word;
*/ */
public class AnalysisResult extends AbstractResult { public class AnalysisResult extends AbstractResult {
private TokenStream stream; private final TokenStream stream;
/** /**
* 构造 * 构造

View File

@@ -13,8 +13,9 @@ import cn.hutool.extra.tokenizer.Word;
* *
*/ */
public class AnalysisWord implements Word { public class AnalysisWord implements Word {
private static final long serialVersionUID = 1L;
private Attribute word; private final Attribute word;
/** /**
* 构造 * 构造

View File

@@ -16,7 +16,7 @@ import cn.hutool.extra.tokenizer.TokenizerEngine;
*/ */
public class AnsjEngine implements TokenizerEngine { public class AnsjEngine implements TokenizerEngine {
private Analysis analysis; private final Analysis analysis;
/** /**
* 构造 * 构造

View File

@@ -16,7 +16,7 @@ import cn.hutool.extra.tokenizer.Word;
*/ */
public class AnsjResult implements Result{ public class AnsjResult implements Result{
Iterator<Term> result; private final Iterator<Term> result;
/** /**
* 构造 * 构造

View File

@@ -11,7 +11,9 @@ import cn.hutool.extra.tokenizer.Word;
* *
*/ */
public class AnsjWord implements Word { public class AnsjWord implements Word {
private Term term; private static final long serialVersionUID = 1L;
private final Term term;
/** /**
* 构造 * 构造

View File

@@ -11,6 +11,7 @@ import cn.hutool.extra.tokenizer.Word;
* *
*/ */
public class HanLPWord implements Word { public class HanLPWord implements Word {
private static final long serialVersionUID = 1L;
private Term term; private Term term;

View File

@@ -11,6 +11,7 @@ import cn.hutool.extra.tokenizer.Word;
* *
*/ */
public class IKAnalyzerWord implements Word { public class IKAnalyzerWord implements Word {
private static final long serialVersionUID = 1L;
private Lexeme word; private Lexeme word;

View File

@@ -11,7 +11,9 @@ import cn.hutool.extra.tokenizer.Word;
* *
*/ */
public class JcsegWord implements Word { public class JcsegWord implements Word {
private IWord word; private static final long serialVersionUID = 1L;
private final IWord word;
/** /**
* 构造 * 构造

View File

@@ -11,7 +11,9 @@ import cn.hutool.extra.tokenizer.Word;
* *
*/ */
public class JiebaWord implements Word { public class JiebaWord implements Word {
private SegToken segToken; private static final long serialVersionUID = 1L;
private final SegToken segToken;
/** /**
* 构造 * 构造

View File

@@ -9,8 +9,9 @@ import cn.hutool.extra.tokenizer.Word;
* *
*/ */
public class MmsegWord implements Word { public class MmsegWord implements Word {
private static final long serialVersionUID = 1L;
private com.chenlb.mmseg4j.Word word; private final com.chenlb.mmseg4j.Word word;
/** /**
* 构造 * 构造

View File

@@ -8,11 +8,11 @@ import cn.hutool.extra.tokenizer.Word;
* mmseg分词中的一个单词包装 * mmseg分词中的一个单词包装
* *
* @author looly * @author looly
*
*/ */
public class MynlpWord implements Word { public class MynlpWord implements Word {
private static final long serialVersionUID = 1L;
private WordTerm word; private final WordTerm word;
/** /**
* 构造 * 构造

View File

@@ -9,8 +9,9 @@ import cn.hutool.extra.tokenizer.Word;
* *
*/ */
public class WordWord implements Word { public class WordWord implements Word {
private static final long serialVersionUID = 1L;
private org.apdplat.word.segmentation.Word word; private final org.apdplat.word.segmentation.Word word;
/** /**
* 构造 * 构造

View File

@@ -1,13 +1,10 @@
package cn.hutool.extra.ssh; package cn.hutool.extra.ssh;
import com.jcraft.jsch.JSch;
import org.junit.Ignore;
import org.junit.Test;
import com.jcraft.jsch.Session;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.Console; import cn.hutool.core.lang.Console;
import com.jcraft.jsch.Session;
import org.junit.Ignore;
import org.junit.Test;
/** /**
* Jsch工具类单元测试 * Jsch工具类单元测试

View File

@@ -19,7 +19,7 @@ import java.security.NoSuchAlgorithmException;
public class AndroidSupportSSLFactory extends CustomProtocolsSSLFactory { public class AndroidSupportSSLFactory extends CustomProtocolsSSLFactory {
// Android低版本不重置的话某些SSL访问就会失败 // Android低版本不重置的话某些SSL访问就会失败
private static String[] protocols = {SSLv3, TLSv1, TLSv11, TLSv12}; private static final String[] protocols = {SSLv3, TLSv1, TLSv11, TLSv12};
public AndroidSupportSSLFactory() throws KeyManagementException, NoSuchAlgorithmException { public AndroidSupportSSLFactory() throws KeyManagementException, NoSuchAlgorithmException {
super(protocols); super(protocols);

View File

@@ -98,13 +98,8 @@ public class UserAgentInfo {
} }
final UserAgentInfo other = (UserAgentInfo) obj; final UserAgentInfo other = (UserAgentInfo) obj;
if (name == null) { if (name == null) {
if (other.name != null) { return other.name == null;
return false; } else return name.equals(other.name);
}
} else if (!name.equals(other.name)) {
return false;
}
return true;
} }
@Override @Override

View File

@@ -18,17 +18,6 @@ public class JSONNull implements Serializable{
*/ */
public static final JSONNull NULL = new JSONNull(); public static final JSONNull NULL = new JSONNull();
/**
* There is only intended to be a single instance of the NULL object, so the clone method returns itself.
*克隆方法只返回本身,此对象是个单例对象
*
* @return NULL.
*/
@Override
protected final Object clone() {
return this;
}
/** /**
* A Null object is equal to the null value and to itself. * A Null object is equal to the null value and to itself.
* 对象与其本身和<code>null</code>值相等 * 对象与其本身和<code>null</code>值相等
@@ -38,7 +27,7 @@ public class JSONNull implements Serializable{
*/ */
@Override @Override
public boolean equals(Object object) { public boolean equals(Object object) {
return object == null || object == this; return object == null || (object instanceof JSONNull && object == this);
} }
@Override @Override

View File

@@ -17,7 +17,6 @@ import cn.hutool.json.serialize.JSONObjectSerializer;
import cn.hutool.json.serialize.JSONSerializer; import cn.hutool.json.serialize.JSONSerializer;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer; import java.io.Writer;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.math.BigDecimal; import java.math.BigDecimal;

View File

@@ -34,7 +34,7 @@ public interface Log extends TraceLog, DebugLog, InfoLog, WarnLog, ErrorLog {
* @return Log * @return Log
* @since 5.0.0 * @since 5.0.0
*/ */
public static Log get(String name) { static Log get(String name) {
return LogFactory.get(name); return LogFactory.get(name);
} }

View File

@@ -140,7 +140,6 @@ public class JdkLog extends AbstractLog {
/** /**
* 传入调用日志类的信息 * 传入调用日志类的信息
* @param callerFQCN 调用者全限定类名 * @param callerFQCN 调用者全限定类名
* @param superFQCN 调用者父类全限定名
* @param record The record to update * @param record The record to update
*/ */
private static void fillCallerData(String callerFQCN, LogRecord record) { private static void fillCallerData(String callerFQCN, LogRecord record) {

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