mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
fix code
This commit is contained in:
parent
3cef7fa9a7
commit
bf03aebcef
@ -16,8 +16,8 @@ import java.lang.reflect.Method;
|
||||
public class CglibInterceptor implements MethodInterceptor, Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Object target;
|
||||
private Aspect aspect;
|
||||
private final Object target;
|
||||
private final Aspect aspect;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -83,14 +83,6 @@ public interface Cache<K, V> extends Iterable<V>, Serializable {
|
||||
*/
|
||||
V get(K key, boolean isUpdateLastAccess);
|
||||
|
||||
/**
|
||||
* 返回缓存迭代器
|
||||
*
|
||||
* @return 缓存迭代器
|
||||
*/
|
||||
@Override
|
||||
Iterator<V> iterator();
|
||||
|
||||
/**
|
||||
* 返回包含键和值得迭代器
|
||||
*
|
||||
|
@ -45,20 +45,19 @@ public class LFUFileCache extends AbstractFileCache{
|
||||
|
||||
@Override
|
||||
protected Cache<File, byte[]> initCache() {
|
||||
Cache<File, byte[]> cache = new LFUCache<File, byte[]>(this.capacity, this.timeout) {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
return new LFUCache<File, byte[]>(LFUFileCache.this.capacity, LFUFileCache.this.timeout) {
|
||||
private static final long serialVersionUID1 = 1L;
|
||||
|
||||
@Override
|
||||
public boolean isFull() {
|
||||
return LFUFileCache.this.usedSize > this.capacity;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onRemove(File key, byte[] cachedObject) {
|
||||
usedSize -= cachedObject.length;
|
||||
}
|
||||
};
|
||||
return cache;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,20 +45,19 @@ public class LRUFileCache extends AbstractFileCache{
|
||||
|
||||
@Override
|
||||
protected Cache<File, byte[]> initCache() {
|
||||
Cache<File, byte[]> cache = new LRUCache<File, byte[]>(this.capacity, super.timeout) {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
return new LRUCache<File, byte[]>(LRUFileCache.this.capacity, super.timeout) {
|
||||
private static final long serialVersionUID1 = 1L;
|
||||
|
||||
@Override
|
||||
public boolean isFull() {
|
||||
return LRUFileCache.this.usedSize > this.capacity;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onRemove(File key, byte[] cachedObject) {
|
||||
usedSize -= cachedObject.length;
|
||||
}
|
||||
};
|
||||
return cache;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class CacheObj<K, V> implements Serializable{
|
||||
/** 访问次数 */
|
||||
protected long accessCount;
|
||||
/** 对象存活时长,0表示永久存活*/
|
||||
private long ttl;
|
||||
private final long ttl;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -23,7 +23,6 @@ public class CacheObjIterator<K, V> implements Iterator<CacheObj<K, V>>, Seriali
|
||||
* 构造
|
||||
*
|
||||
* @param iterator 原{@link Iterator}
|
||||
* @param readLock 读锁
|
||||
*/
|
||||
CacheObjIterator(Iterator<CacheObj<K, V>> iterator) {
|
||||
this.iterator = iterator;
|
||||
|
@ -17,7 +17,6 @@ public class CacheValuesIterator<V> implements Iterator<V>, Serializable {
|
||||
/**
|
||||
* 构造
|
||||
* @param iterator 原{@link CacheObjIterator}
|
||||
* @param readLock 读锁
|
||||
*/
|
||||
CacheValuesIterator(CacheObjIterator<?, V> iterator) {
|
||||
this.cacheObjIter = iterator;
|
||||
|
@ -1,14 +1,12 @@
|
||||
package cn.hutool.cache.test;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.cache.Cache;
|
||||
import cn.hutool.cache.CacheUtil;
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.lang.func.Func0;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 缓存测试用例
|
||||
@ -27,7 +25,7 @@ public class CacheTest {
|
||||
|
||||
//由于缓存容量只有3,当加入第四个元素的时候,根据FIFO规则,最先放入的对象将被移除
|
||||
String value1 = fifoCache.get("key1");
|
||||
Assert.assertTrue(null == value1);
|
||||
Assert.assertNull(value1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -44,9 +42,9 @@ public class CacheTest {
|
||||
String value1 = lfuCache.get("key1");
|
||||
String value2 = lfuCache.get("key2");
|
||||
String value3 = lfuCache.get("key3");
|
||||
Assert.assertTrue(null != value1);
|
||||
Assert.assertTrue(null == value2);
|
||||
Assert.assertTrue(null == value3);
|
||||
Assert.assertNotNull(value1);
|
||||
Assert.assertNull(value2);
|
||||
Assert.assertNull(value3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -84,21 +82,15 @@ public class CacheTest {
|
||||
|
||||
//5毫秒后由于value2设置了5毫秒过期,因此只有value2被保留下来
|
||||
String value1 = timedCache.get("key1");
|
||||
Assert.assertTrue(null == value1);
|
||||
Assert.assertNull(value1);
|
||||
String value2 = timedCache.get("key2");
|
||||
Assert.assertEquals("value2", value2);
|
||||
|
||||
//5毫秒后,由于设置了默认过期,key3只被保留4毫秒,因此为null
|
||||
String value3 = timedCache.get("key3");
|
||||
Assert.assertTrue(null == value3);
|
||||
Assert.assertNull(value3);
|
||||
|
||||
String value3Supplier = timedCache.get("key3", new Func0<String>() {
|
||||
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
return "Default supplier";
|
||||
}
|
||||
});
|
||||
String value3Supplier = timedCache.get("key3", () -> "Default supplier");
|
||||
Assert.assertEquals("Default supplier", value3Supplier);
|
||||
|
||||
// 永不过期
|
||||
|
@ -13,9 +13,9 @@ public abstract class AbstractGenerator implements CodeGenerator {
|
||||
private static final long serialVersionUID = 8685744597154953479L;
|
||||
|
||||
/** 基础字符集合,用于随机获取字符串的字符集合 */
|
||||
protected String baseStr;
|
||||
protected final String baseStr;
|
||||
/** 验证码长度 */
|
||||
protected int length;
|
||||
protected final int length;
|
||||
|
||||
/**
|
||||
* 构造,使用字母+数字做为基础
|
||||
|
@ -42,12 +42,11 @@ public class MathGenerator implements CodeGenerator {
|
||||
number1 = StrUtil.padAfter(number1, this.numberLength, CharUtil.SPACE);
|
||||
number2 = StrUtil.padAfter(number2, this.numberLength, CharUtil.SPACE);
|
||||
|
||||
final String code = StrUtil.builder()//
|
||||
return StrUtil.builder()//
|
||||
.append(number1)//
|
||||
.append(RandomUtil.randomChar(operators))//
|
||||
.append(number2)//
|
||||
.append('=').toString();
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,9 +35,9 @@ public class BeanDesc implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** Bean类 */
|
||||
private Class<?> beanClass;
|
||||
private final Class<?> beanClass;
|
||||
/** 属性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 {
|
||||
|
||||
/** 字段 */
|
||||
private Field field;
|
||||
private final Field field;
|
||||
/** Getter方法 */
|
||||
private Method getter;
|
||||
private final Method getter;
|
||||
/** Setter方法 */
|
||||
private Method setter;
|
||||
private final Method setter;
|
||||
|
||||
/**
|
||||
* 构造<br>
|
||||
|
@ -11,7 +11,7 @@ import cn.hutool.core.lang.SimpleCache;
|
||||
public enum BeanDescCache {
|
||||
INSTANCE;
|
||||
|
||||
private SimpleCache<Class<?>, BeanDesc> bdCache = new SimpleCache<>();
|
||||
private final SimpleCache<Class<?>, BeanDesc> bdCache = new SimpleCache<>();
|
||||
|
||||
/**
|
||||
* 获得属性名和{@link BeanDesc}Map映射
|
||||
|
@ -14,8 +14,8 @@ import cn.hutool.core.lang.SimpleCache;
|
||||
public enum BeanInfoCache {
|
||||
INSTANCE;
|
||||
|
||||
private SimpleCache<Class<?>, Map<String, PropertyDescriptor>> pdCache = new SimpleCache<>();
|
||||
private SimpleCache<Class<?>, Map<String, PropertyDescriptor>> ignoreCasePdCache = new SimpleCache<>();
|
||||
private final SimpleCache<Class<?>, Map<String, PropertyDescriptor>> pdCache = new SimpleCache<>();
|
||||
private final SimpleCache<Class<?>, Map<String, PropertyDescriptor>> ignoreCasePdCache = new SimpleCache<>();
|
||||
|
||||
/**
|
||||
* 获得属性名和{@link PropertyDescriptor}Map映射
|
||||
|
@ -114,7 +114,6 @@ public class DynaBean extends CloneSupport<DynaBean> implements Serializable{
|
||||
public void set(String fieldName, Object value) throws BeanException{
|
||||
if(Map.class.isAssignableFrom(beanClass)){
|
||||
((Map)bean).put(fieldName, value);
|
||||
return;
|
||||
}else{
|
||||
try {
|
||||
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;
|
||||
if (bean == null) {
|
||||
if (other.bean != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!bean.equals(other.bean)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return other.bean == null;
|
||||
} else return bean.equals(other.bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,13 +36,13 @@ public class BeanCopier<T> implements Copier<T>, Serializable {
|
||||
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
|
||||
|
@ -18,8 +18,8 @@ import cn.hutool.core.util.StrUtil;
|
||||
*/
|
||||
public class BeanValueProvider implements ValueProvider<String> {
|
||||
|
||||
private Object source;
|
||||
private boolean ignoreError;
|
||||
private final Object source;
|
||||
private final boolean ignoreError;
|
||||
final Map<String, PropDesc> sourcePdMap;
|
||||
|
||||
/**
|
||||
|
@ -47,13 +47,12 @@ public class MapValueProvider implements ValueProvider<String> {
|
||||
|
||||
@Override
|
||||
public boolean containsKey(String key) {
|
||||
//检查下划线模式
|
||||
if(map.containsKey(key)) {
|
||||
return true;
|
||||
}else if(map.containsKey(StrUtil.toUnderlineCase(key))) {
|
||||
//检查下划线模式
|
||||
return true;
|
||||
}else {
|
||||
return map.containsKey(StrUtil.toUnderlineCase(key));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ package cn.hutool.core.codec;
|
||||
public class Caesar {
|
||||
|
||||
// 26个字母表
|
||||
public static String table = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
|
||||
public static final String table = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
|
||||
|
||||
/**
|
||||
* 传入明文,加密得到密文
|
||||
|
@ -16,7 +16,7 @@ public class ArrayIter<E> implements Iterator<E>, Iterable<E>, Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 数组 */
|
||||
private Object array;
|
||||
private final Object array;
|
||||
/** 起始位置 */
|
||||
private int startIndex;
|
||||
/** 结束位置 */
|
||||
|
@ -18,8 +18,8 @@ public class BoundedPriorityQueue<E> extends PriorityQueue<E>{
|
||||
private static final long serialVersionUID = 3794348988671694820L;
|
||||
|
||||
//容量
|
||||
private int capacity;
|
||||
private Comparator<? super E> comparator;
|
||||
private final int capacity;
|
||||
private final Comparator<? super E> comparator;
|
||||
|
||||
public BoundedPriorityQueue(int capacity) {
|
||||
this(capacity, null);
|
||||
@ -31,22 +31,17 @@ public class BoundedPriorityQueue<E> extends PriorityQueue<E>{
|
||||
* @param comparator 比较器
|
||||
*/
|
||||
public BoundedPriorityQueue(int capacity, final Comparator<? super E> comparator) {
|
||||
super(capacity, new Comparator<E>(){
|
||||
|
||||
@Override
|
||||
public int compare(E o1, E o2) {
|
||||
int cResult;
|
||||
if(comparator != null) {
|
||||
cResult = comparator.compare(o1, o2);
|
||||
}else {
|
||||
@SuppressWarnings("unchecked")
|
||||
Comparable<E> o1c = (Comparable<E>)o1;
|
||||
cResult = o1c.compareTo(o2);
|
||||
}
|
||||
|
||||
return - cResult;
|
||||
super(capacity, (o1, o2) -> {
|
||||
int cResult;
|
||||
if(comparator != null) {
|
||||
cResult = comparator.compare(o1, o2);
|
||||
}else {
|
||||
@SuppressWarnings("unchecked")
|
||||
Comparable<E> o1c = (Comparable<E>)o1;
|
||||
cResult = o1c.compareTo(o2);
|
||||
}
|
||||
|
||||
|
||||
return - cResult;
|
||||
});
|
||||
this.capacity = capacity;
|
||||
this.comparator = comparator;
|
||||
@ -84,7 +79,7 @@ public class BoundedPriorityQueue<E> extends PriorityQueue<E>{
|
||||
* @return 返回排序后的列表
|
||||
*/
|
||||
public ArrayList<E> toList() {
|
||||
final ArrayList<E> list = new ArrayList<E>(this);
|
||||
final ArrayList<E> list = new ArrayList<>(this);
|
||||
Collections.sort(list, comparator);
|
||||
return list;
|
||||
}
|
||||
|
@ -2366,7 +2366,7 @@ public class CollUtil {
|
||||
*/
|
||||
public static <T> List<List<T>> groupByField(Collection<T> collection, final String fieldName) {
|
||||
return group(collection, new Hash<T>() {
|
||||
private List<Object> fieldNameList = new ArrayList<>();
|
||||
private final List<Object> fieldNameList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public int hash(T t) {
|
||||
|
@ -19,7 +19,7 @@ public class CompareUtil {
|
||||
* @see java.util.Comparator#compare(Object, Object)
|
||||
* @since 4.6.9
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public static <T> int compare(T c1, T c2, Comparator<T> comparator) {
|
||||
if (null == comparator) {
|
||||
return compare((Comparable)c1, (Comparable)c2);
|
||||
|
@ -62,7 +62,7 @@ public class PropertyComparator<T> implements Comparator<T>, Serializable {
|
||||
return compare(o1, o2, v1, v2);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes"})
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
private int compare(T o1, T o2, Comparable fieldValue1, Comparable fieldValue2) {
|
||||
int result = ObjectUtil.compare(fieldValue1, fieldValue2, isNullGreater);
|
||||
if(0 == result) {
|
||||
|
@ -1,14 +1,13 @@
|
||||
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.CharUtil;
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 抽象转换器,提供通用的转换逻辑,同时通过convertInternal实现对应类型的专属逻辑<br>
|
||||
* 转换器不会抛出转换异常,转换失败时会返回{@code null}
|
||||
|
@ -27,9 +27,9 @@ import cn.hutool.core.util.TypeUtil;
|
||||
public class BeanConverter<T> extends AbstractConverter<T> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Type beanType;
|
||||
private Class<T> beanClass;
|
||||
private CopyOptions copyOptions;
|
||||
private final Type beanType;
|
||||
private final Class<T> beanClass;
|
||||
private final CopyOptions copyOptions;
|
||||
|
||||
/**
|
||||
* 构造,默认转换选项,注入失败的字段忽略
|
||||
|
@ -1,14 +1,13 @@
|
||||
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.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* 日期转换器
|
||||
*
|
||||
|
@ -3,7 +3,6 @@ package cn.hutool.core.convert.impl;
|
||||
import cn.hutool.core.convert.AbstractConverter;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Period;
|
||||
import java.time.temporal.TemporalAmount;
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,6 @@ package cn.hutool.core.convert.impl;
|
||||
|
||||
import cn.hutool.core.convert.AbstractConverter;
|
||||
|
||||
import java.time.Period;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,6 @@ import cn.hutool.core.convert.AbstractConverter;
|
||||
|
||||
import java.time.Period;
|
||||
import java.time.temporal.TemporalAmount;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -17,7 +17,7 @@ public class BetweenFormater implements Serializable{
|
||||
/** 格式化级别 */
|
||||
private Level level;
|
||||
/** 格式化级别的最大个数 */
|
||||
private int levelMaxCount;
|
||||
private final int levelMaxCount;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
@ -137,7 +137,7 @@ public class BetweenFormater implements Serializable{
|
||||
MILLSECOND("毫秒");
|
||||
|
||||
/** 级别名称 */
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -44,12 +44,7 @@ class FastDateParser extends AbstractDateBasic implements DateParser {
|
||||
// comparator used to sort regex alternatives
|
||||
// alternatives should be ordered longer first, and shorter last. ('february' before 'feb')
|
||||
// all entries must be lowercase by locale.
|
||||
private static final Comparator<String> LONGER_FIRST_LOWERCASE = new Comparator<String>(){
|
||||
@Override
|
||||
public int compare(final String left, final String right) {
|
||||
return right.compareTo(left);
|
||||
}
|
||||
};
|
||||
private static final Comparator<String> LONGER_FIRST_LOWERCASE = (left, right) -> right.compareTo(left);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -389,7 +384,8 @@ class FastDateParser extends AbstractDateBasic implements DateParser {
|
||||
/**
|
||||
* 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
|
||||
* @return The Strategy that will handle parsing for the field
|
||||
*/
|
||||
|
@ -223,10 +223,7 @@ abstract class FormatCache<F extends Format> {
|
||||
return false;
|
||||
}
|
||||
final MultipartKey other = (MultipartKey) obj;
|
||||
if (false == Arrays.equals(keys, other.keys)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return false != Arrays.equals(keys, other.keys);
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,9 +14,6 @@ import cn.hutool.core.convert.Convert;
|
||||
*/
|
||||
public abstract class OptNullBasicTypeFromObjectGetter<K> extends OptNullBasicTypeGetter<K>{
|
||||
|
||||
@Override
|
||||
public abstract Object getObj(K key, Object defaultValue);
|
||||
|
||||
@Override
|
||||
public String getStr(K key, String defaultValue) {
|
||||
final Object obj = getObj(key);
|
||||
|
@ -14,9 +14,6 @@ import cn.hutool.core.convert.Convert;
|
||||
*/
|
||||
public abstract class OptNullBasicTypeFromStringGetter<K> extends OptNullBasicTypeGetter<K> {
|
||||
|
||||
@Override
|
||||
public abstract String getStr(K key, String defaultValue);
|
||||
|
||||
@Override
|
||||
public Object getObj(K key, Object defaultValue) {
|
||||
return getStr(key, null == defaultValue ? null : defaultValue.toString());
|
||||
|
@ -27,10 +27,11 @@ import cn.hutool.core.util.CharsetUtil;
|
||||
* 参考: http://akini.mbnet.fi/java/unicodereader/UnicodeInputStream.java.txt
|
||||
*/
|
||||
public class BOMInputStream extends InputStream {
|
||||
PushbackInputStream in;
|
||||
boolean isInited = false;
|
||||
String defaultCharset;
|
||||
String charset;
|
||||
|
||||
private final PushbackInputStream in;
|
||||
private boolean isInited = false;
|
||||
private final String defaultCharset;
|
||||
private String charset;
|
||||
|
||||
private static final int BOM_SIZE = 4;
|
||||
|
||||
|
@ -38,10 +38,7 @@ public class IORuntimeException extends RuntimeException {
|
||||
* @return 是否为指定类型异常
|
||||
*/
|
||||
public boolean causeInstanceOf(Class<? extends Throwable> clazz) {
|
||||
Throwable cause = this.getCause();
|
||||
if (null != cause && clazz.isInstance(cause)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
final Throwable cause = this.getCause();
|
||||
return null != clazz && clazz.isInstance(cause);
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ import cn.hutool.core.util.StrUtil;
|
||||
public class BytesResource implements Resource, Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private byte[] bytes;
|
||||
private String name;
|
||||
private final byte[] bytes;
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -20,9 +20,9 @@ import cn.hutool.core.util.URLUtil;
|
||||
public class ClassPathResource extends UrlResource {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String path;
|
||||
private ClassLoader classLoader;
|
||||
private Class<?> clazz;
|
||||
private final String path;
|
||||
private final ClassLoader classLoader;
|
||||
private final Class<?> clazz;
|
||||
|
||||
// -------------------------------------------------------------------------------------- Constructor start
|
||||
/**
|
||||
|
@ -40,10 +40,7 @@ public class NoResourceException extends IORuntimeException {
|
||||
* @return 是否为指定类型异常
|
||||
*/
|
||||
public boolean causeInstanceOf(Class<? extends Throwable> clazz) {
|
||||
Throwable cause = this.getCause();
|
||||
if (clazz.isInstance(cause)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
final Throwable cause = this.getCause();
|
||||
return clazz.isInstance(cause);
|
||||
}
|
||||
}
|
||||
|
@ -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一致
|
||||
*/
|
||||
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 Set<Class<?>> classes = new HashSet<>();
|
||||
/**
|
||||
* 扫描结果集
|
||||
*/
|
||||
private final Set<Class<?>> classes = new HashSet<>();
|
||||
|
||||
/**
|
||||
* 扫描指定包路径下所有包含指定注解的类
|
||||
@ -71,12 +73,7 @@ public class ClassScanner implements Serializable {
|
||||
* @return 类集合
|
||||
*/
|
||||
public static Set<Class<?>> scanPackageByAnnotation(String packageName, final Class<? extends Annotation> annotationClass) {
|
||||
return scanPackage(packageName, new Filter<Class<?>>() {
|
||||
@Override
|
||||
public boolean accept(Class<?> clazz) {
|
||||
return clazz.isAnnotationPresent(annotationClass);
|
||||
}
|
||||
});
|
||||
return scanPackage(packageName, clazz -> clazz.isAnnotationPresent(annotationClass));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,12 +84,7 @@ public class ClassScanner implements Serializable {
|
||||
* @return 类集合
|
||||
*/
|
||||
public static Set<Class<?>> scanPackageBySuper(String packageName, final Class<?> superClass) {
|
||||
return scanPackage(packageName, new Filter<Class<?>>() {
|
||||
@Override
|
||||
public boolean accept(Class<?> clazz) {
|
||||
return superClass.isAssignableFrom(clazz) && !superClass.equals(clazz);
|
||||
}
|
||||
});
|
||||
return scanPackage(packageName, clazz -> superClass.isAssignableFrom(clazz) && !superClass.equals(clazz));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,7 +54,6 @@ public class ParameterizedTypeImpl implements ParameterizedType, Serializable {
|
||||
|
||||
final Type useOwner = this.ownerType;
|
||||
final Class<?> raw = (Class<?>) this.rawType;
|
||||
final Type[] typeArguments = this.actualTypeArguments;
|
||||
if (useOwner == null) {
|
||||
buf.append(raw.getName());
|
||||
} else {
|
||||
@ -66,7 +65,7 @@ public class ParameterizedTypeImpl implements ParameterizedType, Serializable {
|
||||
buf.append('.').append(raw.getSimpleName());
|
||||
}
|
||||
|
||||
appendAllTo(buf.append('<'), ", ", typeArguments).append('>');
|
||||
appendAllTo(buf.append('<'), ", ", this.actualTypeArguments).append('>');
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
|
@ -27,20 +27,20 @@ public class PatternPool {
|
||||
/** 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");
|
||||
/** 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+)?)$");
|
||||
/** 邮件,符合RFC 5322规范,正则来自:http://emailregex.com/ */
|
||||
// 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}");
|
||||
/** 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 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 */
|
||||
public final static Pattern URL = Pattern.compile("[a-zA-z]+://[^\\s]*");
|
||||
/** Http URL */
|
||||
@ -157,13 +157,10 @@ public class PatternPool {
|
||||
return false;
|
||||
}
|
||||
if (regex == null) {
|
||||
if (other.regex != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!regex.equals(other.regex)) {
|
||||
return false;
|
||||
return other.regex == null;
|
||||
} else {
|
||||
return regex.equals(other.regex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -66,10 +66,7 @@ public class Tuple extends CloneSupport<Tuple> implements Iterable<Object>, Seri
|
||||
return false;
|
||||
}
|
||||
Tuple other = (Tuple) obj;
|
||||
if (false == Arrays.deepEquals(members, other.members)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return false != Arrays.deepEquals(members, other.members);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,7 +18,7 @@ import cn.hutool.core.util.NumberUtil;
|
||||
public class Arrangement implements Serializable {
|
||||
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 dataList 待选列表
|
||||
* @param resultList 前面(resultIndex-1)个的排列结果
|
||||
* @param resultIndex 选择索引,从0开始
|
||||
* @param result 最终结果
|
||||
|
@ -10,19 +10,19 @@ import cn.hutool.core.util.NumberUtil;
|
||||
/**
|
||||
* 组合,即C(n, m)<br>
|
||||
* 排列组合相关类 参考:http://cgs1999.iteye.com/blog/2327664
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.0.6
|
||||
*/
|
||||
public class Combination implements Serializable{
|
||||
public class Combination implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String[] datas;
|
||||
private final String[] datas;
|
||||
|
||||
/**
|
||||
* 组合,即C(n, m)<br>
|
||||
* 排列组合相关类 参考:http://cgs1999.iteye.com/blog/2327664
|
||||
*
|
||||
*
|
||||
* @param datas 用于组合的数据
|
||||
*/
|
||||
public Combination(String[] datas) {
|
||||
@ -31,30 +31,30 @@ public class Combination implements Serializable{
|
||||
|
||||
/**
|
||||
* 计算组合数,即C(n, m) = n!/((n-m)! * m!)
|
||||
*
|
||||
*
|
||||
* @param n 总数
|
||||
* @param m 选择的个数
|
||||
* @return 组合数
|
||||
*/
|
||||
public static long count(int n, int m) {
|
||||
if(0 == m) {
|
||||
if (0 == m) {
|
||||
return 1;
|
||||
}
|
||||
if(n == m) {
|
||||
if (n == m) {
|
||||
return NumberUtil.factorial(n) / NumberUtil.factorial(m);
|
||||
}
|
||||
return (n > m) ? NumberUtil.factorial(n, n - m) / NumberUtil.factorial(m) : 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 计算组合总数,即C(n, 1) + C(n, 2) + C(n, 3)...
|
||||
*
|
||||
*
|
||||
* @param n 总数
|
||||
* @return 组合数
|
||||
*/
|
||||
public static long countAll(int n) {
|
||||
long total = 0;
|
||||
for(int i = 1; i <= n; i++) {
|
||||
for (int i = 1; i <= n; i++) {
|
||||
total += count(n, i);
|
||||
}
|
||||
return total;
|
||||
@ -62,7 +62,7 @@ public class Combination implements Serializable{
|
||||
|
||||
/**
|
||||
* 组合选择(从列表中选择m个组合)
|
||||
*
|
||||
*
|
||||
* @param m 选择个数
|
||||
* @return 组合结果
|
||||
*/
|
||||
@ -71,15 +71,15 @@ public class Combination implements Serializable{
|
||||
select(0, new String[m], 0, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 全组合
|
||||
*
|
||||
*
|
||||
* @return 全排列结果
|
||||
*/
|
||||
public List<String[]> selectAll(){
|
||||
final List<String[]> result = new ArrayList<>((int)countAll(this.datas.length));
|
||||
for(int i = 1; i <= this.datas.length; i++) {
|
||||
public List<String[]> selectAll() {
|
||||
final List<String[]> result = new ArrayList<>((int) countAll(this.datas.length));
|
||||
for (int i = 1; i <= this.datas.length; i++) {
|
||||
result.addAll(select(i));
|
||||
}
|
||||
return result;
|
||||
@ -87,11 +87,11 @@ public class Combination implements Serializable{
|
||||
|
||||
/**
|
||||
* 组合选择
|
||||
*
|
||||
* @param dataList 待选列表
|
||||
* @param dataIndex 待选开始索引
|
||||
* @param resultList 前面(resultIndex-1)个的组合结果
|
||||
*
|
||||
* @param dataIndex 待选开始索引
|
||||
* @param resultList 前面(resultIndex-1)个的组合结果
|
||||
* @param resultIndex 选择索引,从0开始
|
||||
* @param result 结果集
|
||||
*/
|
||||
private void select(int dataIndex, String[] resultList, int resultIndex, List<String[]> result) {
|
||||
int resultLen = resultList.length;
|
||||
|
@ -29,9 +29,9 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
|
||||
/** 重试等待 */
|
||||
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;
|
||||
|
||||
|
@ -65,7 +65,7 @@ public class BooleanUtil {
|
||||
* @return 相反的Boolean值
|
||||
*/
|
||||
public static boolean negate(boolean bool) {
|
||||
return bool ? false : true;
|
||||
return !bool;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,11 +33,11 @@ public class ClassLoaderUtil {
|
||||
private static final char INNER_CLASS_SEPARATOR = '$';
|
||||
|
||||
/** 原始类型名和其class对应表,例如:int =》 int.class */
|
||||
private static final Map<String, Class<?>> primitiveTypeNameMap = new ConcurrentHashMap<String, Class<?>>(32);
|
||||
private static SimpleCache<String, Class<?>> classCache = new SimpleCache<>();
|
||||
private static final Map<String, Class<?>> primitiveTypeNameMap = new ConcurrentHashMap<>(32);
|
||||
private static final SimpleCache<String, Class<?>> classCache = new SimpleCache<>();
|
||||
|
||||
static {
|
||||
List<Class<?>> primitiveTypes = new ArrayList<Class<?>>(32);
|
||||
List<Class<?>> primitiveTypes = new ArrayList<>(32);
|
||||
// 加入原始类型
|
||||
primitiveTypes.addAll(BasicType.primitiveWrapperMap.keySet());
|
||||
// 加入原始类型数组类型
|
||||
|
@ -1,5 +1,13 @@
|
||||
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.File;
|
||||
import java.io.IOException;
|
||||
@ -15,15 +23,6 @@ import java.net.URLStreamHandler;
|
||||
import java.nio.charset.Charset;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 统一资源定位符相关工具类
|
||||
*
|
||||
|
@ -3,10 +3,6 @@ package cn.hutool.core.clone;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.clone.CloneRuntimeException;
|
||||
import cn.hutool.core.clone.CloneSupport;
|
||||
import cn.hutool.core.clone.Cloneable;
|
||||
|
||||
/**
|
||||
* 克隆单元测试
|
||||
* @author Looly
|
||||
@ -72,13 +68,8 @@ public class CloneTest {
|
||||
return false;
|
||||
}
|
||||
if (name == null) {
|
||||
if (other.name != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!name.equals(other.name)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return other.name == null;
|
||||
} else return name.equals(other.name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,13 +107,8 @@ public class CloneTest {
|
||||
return false;
|
||||
}
|
||||
if (name == null) {
|
||||
if (other.name != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!name.equals(other.name)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return other.name == null;
|
||||
} else return name.equals(other.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,13 @@
|
||||
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.Collection;
|
||||
import java.util.Comparator;
|
||||
@ -12,19 +20,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
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);
|
||||
|
||||
Assert.assertEquals(3, CollectionUtil.count(union, new Matcher<String>() {
|
||||
|
||||
@Override
|
||||
public boolean match(String t) {
|
||||
return t.equals("b");
|
||||
}
|
||||
|
||||
}));
|
||||
Assert.assertEquals(3, CollectionUtil.count(union, t -> t.equals("b")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -79,14 +67,7 @@ public class CollUtilTest {
|
||||
ArrayList<String> list2 = CollectionUtil.newArrayList("a", "b", "b", "b", "c", "d");
|
||||
|
||||
Collection<String> union = CollectionUtil.intersection(list1, list2);
|
||||
Assert.assertEquals(2, CollectionUtil.count(union, new Matcher<String>() {
|
||||
|
||||
@Override
|
||||
public boolean match(String t) {
|
||||
return t.equals("b");
|
||||
}
|
||||
|
||||
}));
|
||||
Assert.assertEquals(2, CollectionUtil.count(union, t -> t.equals("b")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -188,12 +169,9 @@ public class CollUtilTest {
|
||||
map.put("c", "3");
|
||||
|
||||
final String[] result = new String[1];
|
||||
CollectionUtil.forEach(map, new CollUtil.KVConsumer<String, String>() {
|
||||
@Override
|
||||
public void accept(String key, String value, int index) {
|
||||
if (key.equals("a")) {
|
||||
result[0] = value;
|
||||
}
|
||||
CollectionUtil.forEach(map, (key, value, index) -> {
|
||||
if (key.equals("a")) {
|
||||
result[0] = value;
|
||||
}
|
||||
});
|
||||
Assert.assertEquals("1", result[0]);
|
||||
@ -203,12 +181,7 @@ public class CollUtilTest {
|
||||
public void filterTest() {
|
||||
ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
|
||||
|
||||
Collection<String> filtered = CollUtil.filter(list, new Editor<String>() {
|
||||
@Override
|
||||
public String edit(String t) {
|
||||
return t + 1;
|
||||
}
|
||||
});
|
||||
Collection<String> filtered = CollUtil.filter(list, (Editor<String>) t -> t + 1);
|
||||
|
||||
Assert.assertEquals(CollUtil.newArrayList("a1", "b1", "c1"), filtered);
|
||||
}
|
||||
@ -217,16 +190,10 @@ public class CollUtilTest {
|
||||
public void filterTest2() {
|
||||
ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
|
||||
|
||||
ArrayList<String> filtered = CollUtil.filter(list, new Filter<String>() {
|
||||
|
||||
@Override
|
||||
public boolean accept(String t) {
|
||||
return false == "a".equals(t);
|
||||
}
|
||||
});
|
||||
ArrayList<String> filtered = CollUtil.filter(list, (Filter<String>) t -> false == "a".equals(t));
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertTrue(list == filtered);
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(CollUtil.newArrayList("b", "c"), filtered);
|
||||
}
|
||||
|
||||
@ -237,7 +204,7 @@ public class CollUtilTest {
|
||||
ArrayList<String> filtered = CollUtil.removeNull(list);
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertTrue(list == filtered);
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(CollUtil.newArrayList("a", "b", "c", "", " "), filtered);
|
||||
}
|
||||
|
||||
@ -248,7 +215,7 @@ public class CollUtilTest {
|
||||
ArrayList<String> filtered = CollUtil.removeEmpty(list);
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertTrue(list == filtered);
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(CollUtil.newArrayList("a", "b", "c", " "), filtered);
|
||||
}
|
||||
|
||||
@ -259,7 +226,7 @@ public class CollUtilTest {
|
||||
ArrayList<String> filtered = CollUtil.removeBlank(list);
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertTrue(list == filtered);
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(CollUtil.newArrayList("a", "b", "c"), filtered);
|
||||
}
|
||||
|
||||
@ -269,13 +236,9 @@ public class CollUtilTest {
|
||||
List<List<String>> group = CollectionUtil.group(list, null);
|
||||
Assert.assertTrue(group.size() > 0);
|
||||
|
||||
List<List<String>> group2 = CollectionUtil.group(list, new Hash<String>() {
|
||||
@Override
|
||||
public int hash(String t) {
|
||||
// 按照奇数偶数分类
|
||||
return Integer.parseInt(t) % 2;
|
||||
}
|
||||
|
||||
List<List<String>> group2 = CollectionUtil.group(list, t -> {
|
||||
// 按照奇数偶数分类
|
||||
return Integer.parseInt(t) % 2;
|
||||
});
|
||||
Assert.assertEquals(CollUtil.newArrayList("2", "4", "6"), group2.get(0));
|
||||
Assert.assertEquals(CollUtil.newArrayList("1", "3", "5"), group2.get(1));
|
||||
@ -497,10 +460,7 @@ public class CollUtilTest {
|
||||
Assert.assertEquals(arrayList, retval);
|
||||
}
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void subInput1PositiveNegativePositiveOutputArrayIndexOutOfBoundsException() {
|
||||
// Arrange
|
||||
final List<Integer> list = new ArrayList<>();
|
||||
@ -510,7 +470,6 @@ public class CollUtilTest {
|
||||
final int step = 2;
|
||||
|
||||
// Act
|
||||
thrown.expect(ArrayIndexOutOfBoundsException.class);
|
||||
CollUtil.sub(list, start, end, step);
|
||||
// Method is not expected to return due to exception thrown
|
||||
}
|
||||
@ -588,13 +547,7 @@ public class CollUtilTest {
|
||||
@Test
|
||||
public void sortPageAllTest() {
|
||||
ArrayList<Integer> list = CollUtil.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
List<Integer> sortPageAll = CollUtil.sortPageAll(2, 5, new Comparator<Integer>() {
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2) {
|
||||
// 反序
|
||||
return o2.compareTo(o1);
|
||||
}
|
||||
}, list);
|
||||
List<Integer> sortPageAll = CollUtil.sortPageAll(2, 5, Comparator.reverseOrder(), list);
|
||||
|
||||
Assert.assertEquals(CollUtil.newArrayList(4, 3, 2, 1), sortPageAll);
|
||||
}
|
||||
|
@ -1,11 +1,9 @@
|
||||
package cn.hutool.core.convert;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 类型转换工具单元测试
|
||||
|
@ -1,7 +1,6 @@
|
||||
package cn.hutool.core.convert;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -52,7 +52,7 @@ public class ArrangementTest {
|
||||
Assert.assertEquals(Arrangement.countAll(4), selectAll.size());
|
||||
|
||||
List<String[]> list2 = arrangement.select(0);
|
||||
Assert.assertTrue(1 == list2.size());
|
||||
Assert.assertEquals(1, list2.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -61,7 +61,7 @@ public class ClassUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDeclaredMethod() throws Exception {
|
||||
public void getDeclaredMethod() {
|
||||
Method noMethod = ClassUtil.getDeclaredMethod(TestSubClass.class, "noMethod");
|
||||
Assert.assertNull(noMethod);
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -21,10 +21,6 @@ import cn.hutool.core.map.MapUtil;
|
||||
*/
|
||||
public class XmlUtilTest {
|
||||
|
||||
@Test
|
||||
public void buildTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseTest() {
|
||||
String result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"//
|
||||
|
@ -16,12 +16,10 @@ public class SimpleTaskListener implements TaskListener{
|
||||
|
||||
@Override
|
||||
public void onSucceeded(TaskExecutor executor) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(TaskExecutor executor, Throwable exception) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
*/
|
||||
public class BoolArrayValueMatcher implements ValueMatcher{
|
||||
|
||||
boolean[] bValues;
|
||||
private final boolean[] bValues;
|
||||
|
||||
public BoolArrayValueMatcher(List<Integer> intValueList) {
|
||||
bValues = new boolean[Collections.max(intValueList) + 1];
|
||||
|
@ -18,8 +18,7 @@ import cn.hutool.cron.CronException;
|
||||
*
|
||||
*/
|
||||
public class InvokeTask implements Task{
|
||||
|
||||
private Class<?> clazz;
|
||||
|
||||
private Object obj;
|
||||
private Method method;
|
||||
|
||||
@ -41,18 +40,18 @@ public class InvokeTask implements Task{
|
||||
if(StrUtil.isBlank(className)) {
|
||||
throw new IllegalArgumentException("Class name is blank !");
|
||||
}
|
||||
this.clazz = ClassLoaderUtil.loadClass(className);
|
||||
if(null == this.clazz) {
|
||||
final Class<?> clazz = ClassLoaderUtil.loadClass(className);
|
||||
if(null == clazz) {
|
||||
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);
|
||||
if(StrUtil.isBlank(methodName)) {
|
||||
throw new IllegalArgumentException("Method name is blank !");
|
||||
}
|
||||
this.method = ClassUtil.getPublicMethod(this.clazz, methodName);
|
||||
this.method = ClassUtil.getPublicMethod(clazz, methodName);
|
||||
if(null == this.method) {
|
||||
throw new IllegalArgumentException("No method with name of [" + methodName + "] !");
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ public class TestJob {
|
||||
/**
|
||||
* 执行循环定时任务,测试在定时任务结束时作为deamon线程是否能正常结束
|
||||
*/
|
||||
@SuppressWarnings("InfiniteLoopStatement")
|
||||
public void doWhileTest() {
|
||||
String name = Thread.currentThread().getName();
|
||||
while (true) {
|
||||
|
@ -1,30 +1,9 @@
|
||||
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.io.FileUtil;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.HexUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
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.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>
|
||||
|
@ -17,7 +17,7 @@ public enum AsymmetricAlgorithm {
|
||||
/** EC(Elliptic Curve)算法 */
|
||||
EC("EC");
|
||||
|
||||
private String value;
|
||||
private final String value;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -26,7 +26,7 @@ public class BaseAsymmetric<T extends BaseAsymmetric<T>>{
|
||||
/** 私钥 */
|
||||
protected PrivateKey privateKey;
|
||||
/** 锁 */
|
||||
protected Lock lock = new ReentrantLock();
|
||||
protected final Lock lock = new ReentrantLock();
|
||||
|
||||
// ------------------------------------------------------------------ Constructor start
|
||||
/**
|
||||
|
@ -1,25 +1,21 @@
|
||||
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.lang.Console;
|
||||
import cn.hutool.core.util.*;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.HexUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.asymmetric.KeyType;
|
||||
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.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import java.security.KeyPair;
|
||||
import java.security.PublicKey;
|
||||
|
||||
/**
|
||||
* RSA算法单元测试
|
||||
|
@ -33,7 +33,7 @@ import cn.hutool.db.sql.Wrapper;
|
||||
public abstract class AbstractDb implements Serializable {
|
||||
private static final long serialVersionUID = 3858951941916349062L;
|
||||
|
||||
protected DataSource ds;
|
||||
protected final DataSource ds;
|
||||
/**
|
||||
* 是否支持事务
|
||||
*/
|
||||
|
@ -15,7 +15,7 @@ import cn.hutool.core.map.MapUtil;
|
||||
public class ActiveEntity extends Entity {
|
||||
private static final long serialVersionUID = 6112321379601134750L;
|
||||
|
||||
private Db db;
|
||||
private final Db db;
|
||||
|
||||
// --------------------------------------------------------------- Static method start
|
||||
/**
|
||||
|
@ -44,7 +44,6 @@ public class HikariDSFactory extends AbstractDSFactory {
|
||||
config.put("password", pass);
|
||||
}
|
||||
|
||||
final HikariDataSource ds = new HikariDataSource(new HikariConfig(config));
|
||||
return ds;
|
||||
return new HikariDataSource(new HikariConfig(config));
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import java.sql.SQLException;
|
||||
public class BeanHandler<E> implements RsHandler<E>{
|
||||
private static final long serialVersionUID = -5491214744966544475L;
|
||||
|
||||
private Class<E> elementBeanType;
|
||||
private final Class<E> elementBeanType;
|
||||
|
||||
/**
|
||||
* 创建一个 BeanHandler对象
|
||||
@ -24,7 +24,7 @@ public class BeanHandler<E> implements RsHandler<E>{
|
||||
* @return BeanHandler对象
|
||||
*/
|
||||
public static <E> BeanHandler<E> create(Class<E> beanType) {
|
||||
return new BeanHandler<E>(beanType);
|
||||
return new BeanHandler<>(beanType);
|
||||
}
|
||||
|
||||
public BeanHandler(Class<E> beanType) {
|
||||
|
@ -15,7 +15,7 @@ import java.util.List;
|
||||
public class BeanListHandler<E> implements RsHandler<List<E>> {
|
||||
private static final long serialVersionUID = 4510569754766197707L;
|
||||
|
||||
private Class<E> elementBeanType;
|
||||
private final Class<E> elementBeanType;
|
||||
|
||||
/**
|
||||
* 创建一个 BeanListHandler对象
|
||||
@ -25,7 +25,7 @@ public class BeanListHandler<E> implements RsHandler<List<E>> {
|
||||
* @return BeanListHandler对象
|
||||
*/
|
||||
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
|
||||
public List<E> handle(ResultSet rs) throws SQLException {
|
||||
return HandleHelper.handleRsToBeanList(rs, new ArrayList<E>(), elementBeanType);
|
||||
return HandleHelper.handleRsToBeanList(rs, new ArrayList<>(), elementBeanType);
|
||||
}
|
||||
}
|
||||
|
@ -222,13 +222,11 @@ public class Ftp extends AbstractFtp {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean flag = true;
|
||||
try {
|
||||
flag = client.changeWorkingDirectory(directory);
|
||||
return client.changeWorkingDirectory(directory);
|
||||
} catch (IOException e) {
|
||||
throw new FtpException(e);
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -285,13 +283,11 @@ public class Ftp extends AbstractFtp {
|
||||
|
||||
@Override
|
||||
public boolean mkdir(String dir) {
|
||||
boolean flag = true;
|
||||
try {
|
||||
flag = this.client.makeDirectory(dir);
|
||||
return this.client.makeDirectory(dir);
|
||||
} catch (IOException e) {
|
||||
throw new FtpException(e);
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -307,10 +303,7 @@ public class Ftp extends AbstractFtp {
|
||||
} catch (IOException e) {
|
||||
throw new FtpException(e);
|
||||
}
|
||||
if (ArrayUtil.isNotEmpty(ftpFileArr)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ArrayUtil.isNotEmpty(ftpFileArr);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,12 +1,11 @@
|
||||
package cn.hutool.extra.servlet.multipart;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.log.Log;
|
||||
import cn.hutool.log.StaticLog;
|
||||
import cn.hutool.setting.Setting;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* 上传文件设定文件
|
||||
*
|
||||
|
@ -27,7 +27,7 @@ public enum ChannelType {
|
||||
SUBSYSTEM("subsystem");
|
||||
|
||||
/** channel值 */
|
||||
private String value;
|
||||
private final String value;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -221,10 +221,10 @@ public class JschUtil {
|
||||
public static boolean unBindPort(Session session, int localPort) {
|
||||
try {
|
||||
session.delPortForwardingL(localPort);
|
||||
return true;
|
||||
} catch (JSchException e) {
|
||||
throw new JschRuntimeException(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -181,9 +181,6 @@ public class TemplateConfig implements Serializable {
|
||||
} else if (!path.equals(other.path)) {
|
||||
return false;
|
||||
}
|
||||
if (resourceMode != other.resourceMode) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return resourceMode == other.resourceMode;
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import cn.hutool.extra.template.TemplateEngine;
|
||||
*/
|
||||
public class BeetlEngine implements TemplateEngine {
|
||||
|
||||
private GroupTemplate engine;
|
||||
private final GroupTemplate engine;
|
||||
|
||||
// --------------------------------------------------------------------------------- Constructor start
|
||||
/**
|
||||
|
@ -15,7 +15,7 @@ import cn.hutool.extra.template.AbstractTemplate;
|
||||
public class BeetlTemplate extends AbstractTemplate implements Serializable{
|
||||
private static final long serialVersionUID = -8157926902932567280L;
|
||||
|
||||
org.beetl.core.Template rawTemplate;
|
||||
private final org.beetl.core.Template rawTemplate;
|
||||
|
||||
/**
|
||||
* 包装Beetl模板
|
||||
|
@ -254,7 +254,7 @@ public final class BeetlUtil {
|
||||
*
|
||||
*/
|
||||
public static class ResourceLoaderBuilder {
|
||||
private CompositeResourceLoader compositeResourceLoader = new CompositeResourceLoader();
|
||||
private final CompositeResourceLoader compositeResourceLoader = new CompositeResourceLoader();
|
||||
|
||||
/**
|
||||
* 创建
|
||||
|
@ -66,7 +66,6 @@ public class RythmEngine implements TemplateEngine {
|
||||
props.put("home.template", path);
|
||||
}
|
||||
|
||||
final org.rythmengine.RythmEngine engine = new org.rythmengine.RythmEngine(props);
|
||||
return engine;
|
||||
return new org.rythmengine.RythmEngine(props);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
package cn.hutool.extra.tokenizer;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 表示分词中的一个词
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public interface Word {
|
||||
public interface Word extends Serializable {
|
||||
|
||||
/**
|
||||
* 获取单词文本
|
||||
|
@ -19,7 +19,7 @@ import cn.hutool.extra.tokenizer.TokenizerException;
|
||||
*/
|
||||
public class AnalysisEngine implements TokenizerEngine {
|
||||
|
||||
private Analyzer analyzer;
|
||||
private final Analyzer analyzer;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -18,7 +18,7 @@ import cn.hutool.extra.tokenizer.Word;
|
||||
*/
|
||||
public class AnalysisResult extends AbstractResult {
|
||||
|
||||
private TokenStream stream;
|
||||
private final TokenStream stream;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -13,8 +13,9 @@ import cn.hutool.extra.tokenizer.Word;
|
||||
*
|
||||
*/
|
||||
public class AnalysisWord implements Word {
|
||||
|
||||
private Attribute word;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Attribute word;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -16,7 +16,7 @@ import cn.hutool.extra.tokenizer.TokenizerEngine;
|
||||
*/
|
||||
public class AnsjEngine implements TokenizerEngine {
|
||||
|
||||
private Analysis analysis;
|
||||
private final Analysis analysis;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -16,7 +16,7 @@ import cn.hutool.extra.tokenizer.Word;
|
||||
*/
|
||||
public class AnsjResult implements Result{
|
||||
|
||||
Iterator<Term> result;
|
||||
private final Iterator<Term> result;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -11,7 +11,9 @@ import cn.hutool.extra.tokenizer.Word;
|
||||
*
|
||||
*/
|
||||
public class AnsjWord implements Word {
|
||||
private Term term;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Term term;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -11,6 +11,7 @@ import cn.hutool.extra.tokenizer.Word;
|
||||
*
|
||||
*/
|
||||
public class HanLPWord implements Word {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Term term;
|
||||
|
||||
|
@ -11,6 +11,7 @@ import cn.hutool.extra.tokenizer.Word;
|
||||
*
|
||||
*/
|
||||
public class IKAnalyzerWord implements Word {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Lexeme word;
|
||||
|
||||
|
@ -11,7 +11,9 @@ import cn.hutool.extra.tokenizer.Word;
|
||||
*
|
||||
*/
|
||||
public class JcsegWord implements Word {
|
||||
private IWord word;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final IWord word;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -11,7 +11,9 @@ import cn.hutool.extra.tokenizer.Word;
|
||||
*
|
||||
*/
|
||||
public class JiebaWord implements Word {
|
||||
private SegToken segToken;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final SegToken segToken;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -9,8 +9,9 @@ import cn.hutool.extra.tokenizer.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;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -6,17 +6,17 @@ import cn.hutool.extra.tokenizer.Word;
|
||||
|
||||
/**
|
||||
* mmseg分词中的一个单词包装
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public class MynlpWord implements Word {
|
||||
|
||||
private WordTerm word;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final WordTerm word;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param word {@link WordTerm}
|
||||
*/
|
||||
public MynlpWord(WordTerm word) {
|
||||
@ -27,12 +27,12 @@ public class MynlpWord implements Word {
|
||||
public String getText() {
|
||||
return word.getWord();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getStartOffset() {
|
||||
return this.word.offset;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getEndOffset() {
|
||||
return getStartOffset() + word.word.length();
|
||||
|
@ -9,8 +9,9 @@ import cn.hutool.extra.tokenizer.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;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
|
@ -1,13 +1,10 @@
|
||||
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.lang.Console;
|
||||
import com.jcraft.jsch.Session;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Jsch工具类单元测试
|
||||
|
@ -19,7 +19,7 @@ import java.security.NoSuchAlgorithmException;
|
||||
public class AndroidSupportSSLFactory extends CustomProtocolsSSLFactory {
|
||||
|
||||
// Android低版本不重置的话某些SSL访问就会失败
|
||||
private static String[] protocols = {SSLv3, TLSv1, TLSv11, TLSv12};
|
||||
private static final String[] protocols = {SSLv3, TLSv1, TLSv11, TLSv12};
|
||||
|
||||
public AndroidSupportSSLFactory() throws KeyManagementException, NoSuchAlgorithmException {
|
||||
super(protocols);
|
||||
|
@ -98,13 +98,8 @@ public class UserAgentInfo {
|
||||
}
|
||||
final UserAgentInfo other = (UserAgentInfo) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!name.equals(other.name)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return other.name == null;
|
||||
} else return name.equals(other.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,17 +18,6 @@ public class JSONNull implements Serializable{
|
||||
*/
|
||||
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.
|
||||
* 对象与其本身和<code>null</code>值相等
|
||||
@ -38,7 +27,7 @@ public class JSONNull implements Serializable{
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
return object == null || object == this;
|
||||
return object == null || (object instanceof JSONNull && object == this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,7 +17,6 @@ import cn.hutool.json.serialize.JSONObjectSerializer;
|
||||
import cn.hutool.json.serialize.JSONSerializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
|
@ -34,7 +34,7 @@ public interface Log extends TraceLog, DebugLog, InfoLog, WarnLog, ErrorLog {
|
||||
* @return Log
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public static Log get(String name) {
|
||||
static Log get(String name) {
|
||||
return LogFactory.get(name);
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,6 @@ public class JdkLog extends AbstractLog {
|
||||
/**
|
||||
* 传入调用日志类的信息
|
||||
* @param callerFQCN 调用者全限定类名
|
||||
* @param superFQCN 调用者父类全限定名
|
||||
* @param record The record to update
|
||||
*/
|
||||
private static void fillCallerData(String callerFQCN, LogRecord record) {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user