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

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

View File

@@ -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映射

View File

@@ -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映射

View File

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

View File

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

View File

@@ -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;
/**

View File

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

View File

@@ -9,7 +9,7 @@ package cn.hutool.core.codec;
public class Caesar {
// 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 Object array;
private final Object array;
/** 起始位置 */
private int startIndex;
/** 结束位置 */

View File

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

View File

@@ -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) {

View File

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

View File

@@ -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) {

View File

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

View File

@@ -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;
/**
* 构造,默认转换选项,注入失败的字段忽略

View File

@@ -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;
/**
* 日期转换器
*

View File

@@ -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;
/**

View File

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

View File

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

View File

@@ -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;
/**
* 构造

View File

@@ -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
*/

View File

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

View File

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

View File

@@ -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());

View File

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

View File

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

View File

@@ -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;
/**
* 构造

View File

@@ -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
/**

View File

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

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一致
*/
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));
}
/**

View File

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

View File

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

View File

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

View File

@@ -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 最终结果

View File

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

View File

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

View File

@@ -65,7 +65,7 @@ public class BooleanUtil {
* @return 相反的Boolean值
*/
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 = '$';
/** 原始类型名和其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());
// 加入原始类型数组类型

View File

@@ -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;
/**
* 统一资源定位符相关工具类
*

View File

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

View File

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

View File

@@ -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;
/**
* 类型转换工具单元测试

View File

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

View File

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

View File

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

View File

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

View File

@@ -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\" ?>"//