This commit is contained in:
Looly 2019-10-29 19:53:17 +08:00
parent f9ee2af71c
commit e754ec3e86
45 changed files with 172 additions and 179 deletions

View File

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

View File

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

View File

@ -512,7 +512,7 @@ public class HashCodeBuilder implements Builder<Integer> {
/**
* Running total of the hashCode.
*/
private int iTotal = 0;
private int iTotal;
/**
* <p>

View File

@ -38,8 +38,11 @@ public class Base32 {
* @return base32
*/
public static String encode(final byte[] bytes) {
int i = 0, index = 0, digit = 0;
int currByte, nextByte;
int i = 0;
int index = 0;
int digit;
int currByte;
int nextByte;
StringBuilder base32 = new StringBuilder((bytes.length + 7) * 8 / 5);
while (i < bytes.length) {

View File

@ -6,6 +6,7 @@ import java.util.BitSet;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import cn.hutool.core.lang.Chain;
@ -23,7 +24,7 @@ public class ComparatorChain<E> implements Chain<Comparator<E>, ComparatorChain<
/** 比较器链. */
private final List<Comparator<E>> chain;
/** 对应比较器位置是否反序. */
private BitSet orderingBits = null;
private BitSet orderingBits;
/** 比较器是否被锁定。锁定的比较器链不能再添加新的比较器。比较器会在开始比较时开始加锁。 */
private boolean lock = false;
@ -31,7 +32,7 @@ public class ComparatorChain<E> implements Chain<Comparator<E>, ComparatorChain<
* 构造空的比较器链必须至少有一个比较器否则会在compare时抛出{@link UnsupportedOperationException}
*/
public ComparatorChain() {
this(new ArrayList<Comparator<E>>(), new BitSet());
this(new ArrayList<>(), new BitSet());
}
/**
@ -50,7 +51,7 @@ public class ComparatorChain<E> implements Chain<Comparator<E>, ComparatorChain<
* @param reverse 是否反序true表示反序false正序
*/
public ComparatorChain(final Comparator<E> comparator, final boolean reverse) {
chain = new ArrayList<Comparator<E>>(1);
chain = new ArrayList<>(1);
chain.add(comparator);
orderingBits = new BitSet(1);
if (reverse == true) {
@ -248,7 +249,7 @@ public class ComparatorChain<E> implements Chain<Comparator<E>, ComparatorChain<
}
if (object.getClass().equals(this.getClass())) {
final ComparatorChain<?> otherChain = (ComparatorChain<?>) object;
return (null == orderingBits ? null == otherChain.orderingBits : this.orderingBits.equals(otherChain.orderingBits)) //
return (Objects.equals(this.orderingBits, otherChain.orderingBits)) //
&& (null == otherChain ? null == otherChain.chain : this.chain.equals(otherChain.chain));
}
return false;

View File

@ -5,6 +5,7 @@ import java.util.Comparator;
import java.util.List;
import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
/**
@ -49,7 +50,7 @@ public class VersionComparator implements Comparator<String>, Serializable {
*/
@Override
public int compare(String version1, String version2) {
if(version1 == version2) {
if(ObjectUtil.equal(version1, version2)) {
return 0;
}
if (version1 == null && version2 == null) {

View File

@ -45,7 +45,7 @@ public class NumberWordFormater {
*/
private static String format(String x) {
int z = x.indexOf("."); // 取小数点位置
String lstr = "", rstr = "";
String lstr, rstr = "";
if (z > -1) { // 看是否有小数如果有则分别取左边和右边
lstr = x.substring(0, z);
rstr = x.substring(z + 1);
@ -65,19 +65,20 @@ public class NumberWordFormater {
lstrrev += "0";
break;
}
String lm = ""; // 用来存放转换後的整数部分
StringBuilder lm = new StringBuilder(); // 用来存放转换後的整数部分
for (int i = 0; i < lstrrev.length() / 3; i++) {
a[i] = StrUtil.reverse(lstrrev.substring(3 * i, 3 * i + 3)); // 截取第一个叁位
if (!a[i].equals("000")) { // 用来避免这种情况1000000 = one million
// thousand only
if (i != 0) {
lm = transThree(a[i]) + " " + parseMore(String.valueOf(i)) + " " + lm; // :
lm.insert(0, transThree(a[i]) + " " + parseMore(i) + " "); // :
// thousandmillionbillion
} else {
lm = transThree(a[i]); // 防止i=0时 在多加两个空格.
// 防止i=0时 在多加两个空格.
lm = new StringBuilder(transThree(a[i]));
}
} else {
lm += transThree(a[i]);
lm.append(transThree(a[i]));
}
}
@ -86,7 +87,7 @@ public class NumberWordFormater {
xs = "AND CENTS " + transTwo(rstr) + " "; // 小数部分存在时转换小数
}
return lm.trim() + " " + xs + "ONLY";
return lm.toString().trim() + " " + xs + "ONLY";
}
private static String parseFirst(String s) {
@ -101,13 +102,13 @@ public class NumberWordFormater {
return NUMBER_TEN[Integer.parseInt(s.substring(0, 1)) - 1];
}
private static String parseMore(String s) {
return NUMBER_MORE[Integer.parseInt(s)];
private static String parseMore(int i) {
return NUMBER_MORE[i];
}
// 两位
private static String transTwo(String s) {
String value = "";
String value;
// 判断位数
if (s.length() > 2) {
s = s.substring(0, 2);
@ -130,7 +131,7 @@ public class NumberWordFormater {
// 制作叁位的数
// s.length = 3
private static String transThree(String s) {
String value = "";
String value;
if (s.startsWith("0")) {// 是否小於100
value = transTwo(s.substring(1));
} else if (s.substring(1).equals("00")) {// 是否被100整除

View File

@ -97,7 +97,7 @@ public class ArrayConverter extends AbstractConverter<Object> {
}
final ConverterRegistry converter = ConverterRegistry.getInstance();
Object result = null;
Object result;
if (value instanceof List) {
// List转数组
final List<?> list = (List<?>) value;

View File

@ -61,7 +61,7 @@ public class CollectionConverter implements Converter<Collection<?>> {
@Override
public Collection<?> convert(Object value, Collection<?> defaultValue) throws IllegalArgumentException {
Collection<?> result = null;
Collection<?> result;
try {
result = convertInternal(value);
} catch (RuntimeException e) {

View File

@ -76,18 +76,18 @@ public class NumberConverter extends AbstractConverter<Number> {
return StrUtil.isBlank(valueStr) ? null : Integer.valueOf(NumberUtil.parseInt(valueStr));
} else if (AtomicInteger.class == targetType) {
int intValue;
final AtomicInteger intValue = new AtomicInteger();
if (value instanceof Number) {
intValue = ((Number) value).intValue();
intValue.set(((Number) value).intValue());
} else if(value instanceof Boolean) {
intValue = BooleanUtil.toInt((Boolean)value);
intValue.set(BooleanUtil.toInt((Boolean) value));
}
final String valueStr = convertToStr(value);
if (StrUtil.isBlank(valueStr)) {
return null;
}
intValue = NumberUtil.parseInt(valueStr);
return new AtomicInteger(intValue);
intValue.set(NumberUtil.parseInt(valueStr));
return intValue;
} else if (Long.class == targetType) {
if (value instanceof Number) {
return Long.valueOf(((Number) value).longValue());
@ -98,18 +98,18 @@ public class NumberConverter extends AbstractConverter<Number> {
return StrUtil.isBlank(valueStr) ? null : Long.valueOf(NumberUtil.parseLong(valueStr));
} else if (AtomicLong.class == targetType) {
long longValue;
final AtomicLong longValue = new AtomicLong();
if (value instanceof Number) {
longValue = ((Number) value).longValue();
longValue.set(((Number) value).longValue());
} else if(value instanceof Boolean) {
longValue = BooleanUtil.toLong((Boolean)value);
longValue.set(BooleanUtil.toLong((Boolean) value));
}
final String valueStr = convertToStr(value);
if (StrUtil.isBlank(valueStr)) {
return null;
}
longValue = NumberUtil.parseLong(valueStr);
return new AtomicLong(longValue);
longValue.set(NumberUtil.parseLong(valueStr));
return longValue;
} else if (Float.class == targetType) {
if (value instanceof Number) {

View File

@ -51,8 +51,10 @@ public class BetweenFormater implements Serializable{
long day = betweenMs / DateUnit.DAY.getMillis();
long hour = betweenMs / DateUnit.HOUR.getMillis() - day * 24;
long minute = betweenMs / DateUnit.MINUTE.getMillis() - day * 24 * 60 - hour * 60;
long second = betweenMs / DateUnit.SECOND.getMillis() - ((day * 24 + hour) * 60 + minute) * 60;
long millisecond = betweenMs - (((day * 24 + hour) * 60 + minute) * 60 + second) * 1000;
final long BetweenOfSecond = ((day * 24 + hour) * 60 + minute) * 60;
long second = betweenMs / DateUnit.SECOND.getMillis() - BetweenOfSecond;
long millisecond = betweenMs - (BetweenOfSecond + second) * 1000;
final int level = this.level.ordinal();
int levelCount = 0;

View File

@ -104,7 +104,7 @@ class FastDatePrinter extends AbstractDateBasic implements DatePrinter {
if (tokenLen == 2) {
rule = TwoDigitYearField.INSTANCE;
} else {
rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen);
rule = selectNumberRule(Calendar.YEAR, Math.max(tokenLen, 4));
}
if (c == 'Y') {
rule = new WeekYear((NumberRule) rule);

View File

@ -137,7 +137,7 @@ public class Tailer implements Serializable {
/**
* 预读取行
*
* @throws IOException
* @throws IOException IO异常
*/
private void readTail() throws IOException {
final long len = this.randomAccessFile.length();

View File

@ -173,11 +173,9 @@ public class ObjectId {
int loaderId = (loader != null) ? System.identityHashCode(loader) : 0;
// 进程ID + 对象加载ID
StringBuilder processSb = new StringBuilder();
processSb.append(Integer.toHexString(processId));
processSb.append(Integer.toHexString(loaderId));
// 保留前2位
processPiece = processSb.toString().hashCode() & 0xFFFF;
final String processSb = Integer.toHexString(processId) + Integer.toHexString(loaderId);
processPiece = processSb.hashCode() & 0xFFFF;
return processPiece;
}

View File

@ -27,7 +27,7 @@ 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-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 IPV6 = Pattern.compile("(([0-9a-fA-F]{1,4}:){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]+|::(ffff(:0{1,4})?:)?((25[0-5]|(2[0-4]|1?[0-9])?[0-9])\\.){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-9])?[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/ */
@ -52,7 +52,7 @@ public class PatternPool {
/** 不带横线的UUID */
public final static Pattern UUID_SIMPLE = Pattern.compile("^[0-9a-z]{32}$");
/** 中国车牌号码 */
public final static Pattern PLATE_NUMBER = Pattern.compile("^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$");
public final static Pattern PLATE_NUMBER = Pattern.compile("^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z][A-Z][A-Z0-9]{4}[A-Z0-9挂学警港澳]$");
/** MAC地址正则 */
public static final Pattern MAC_ADDRESS = Pattern.compile("((?:[A-F0-9]{1,2}[:-]){5}[A-F0-9]{1,2})|(?:0x)(\\d{12})(?:.+ETHER)", Pattern.CASE_INSENSITIVE);
/** 16进制字符串 */

View File

@ -39,9 +39,9 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
/** 索引 */
private int index = 0;
/** 是否包含第一个元素 */
private boolean includeStart = true;
private boolean includeStart;
/** 是否包含最后一个元素 */
private boolean includeEnd = true;
private boolean includeEnd;
/**
* 构造
@ -80,6 +80,7 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
this.steper = steper;
this.next = safeStep(this.current);
this.includeStart = isIncludeStart;
includeEnd = true;
this.includeEnd = isIncludeEnd;
}

View File

@ -64,7 +64,7 @@ public class CallerUtil {
* @return {@link Caller}实现
*/
private static Caller tryCreateCaller() {
Caller caller = null;
Caller caller;
try {
caller = new SecurityManagerCaller();
if(null != caller.getCaller() && null != caller.getCallerCaller()) {

View File

@ -58,16 +58,19 @@ public class TableMap<K, V> implements Map<K, V>, Serializable {
@Override
public boolean containsKey(Object key) {
//noinspection SuspiciousMethodCalls
return keys.contains(key);
}
@Override
public boolean containsValue(Object value) {
//noinspection SuspiciousMethodCalls
return values.contains(value);
}
@Override
public V get(Object key) {
//noinspection SuspiciousMethodCalls
final int index = keys.indexOf(key);
if (index > -1 && index < values.size()) {
return values.get(index);
@ -84,6 +87,7 @@ public class TableMap<K, V> implements Map<K, V>, Serializable {
@Override
public V remove(Object key) {
//noinspection SuspiciousMethodCalls
int index = keys.indexOf(key);
if (index > -1) {
keys.remove(index);
@ -121,7 +125,7 @@ public class TableMap<K, V> implements Map<K, V>, Serializable {
public Set<Map.Entry<K, V>> entrySet() {
HashSet<Map.Entry<K, V>> hashSet = new HashSet<>();
for (int i = 0; i < size(); i++) {
hashSet.add(new Entry<K, V>(keys.get(i), values.get(i)));
hashSet.add(new Entry<>(keys.get(i), values.get(i)));
}
return hashSet;
}

View File

@ -9,7 +9,6 @@ import cn.hutool.core.util.StrUtil;
*
* @author 兜兜毛毛, looly
* @since 4.0.0
*
*/
public class UnicodeUtil {
@ -27,13 +26,13 @@ public class UnicodeUtil {
final int len = unicode.length();
StrBuilder sb = StrBuilder.create(len);
int i = -1;
int i;
int pos = 0;
while ((i = StrUtil.indexOfIgnoreCase(unicode, "\\u", pos)) != -1) {
sb.append(unicode, pos, i);//写入Unicode符之前的部分
pos = i;
if (i + 5 < len) {
char c = 0;
char c;
try {
c = (char) Integer.parseInt(unicode.substring(i + 2, i + 6), 16);
sb.append(c);

View File

@ -132,6 +132,7 @@ public final class CsvRow implements List<String> {
@Override
public <T> T[] toArray(T[] a) {
//noinspection SuspiciousToArrayCall
return this.fields.toArray(a);
}

View File

@ -85,7 +85,8 @@ public class EscapeUtil {
}
StringBuilder tmp = new StringBuilder(content.length());
int lastPos = 0, pos = 0;
int lastPos = 0;
int pos;
char ch;
while (lastPos < content.length()) {
pos = content.indexOf("%", lastPos);
@ -104,7 +105,7 @@ public class EscapeUtil {
tmp.append(content.substring(lastPos));
lastPos = content.length();
} else {
tmp.append(content.substring(lastPos, pos));
tmp.append(content, lastPos, pos);
lastPos = pos;
}
}

View File

@ -92,7 +92,7 @@ public class HashUtil {
for (i = 0; i < (len << 3); i += 8) {
char k = key[i >> 3];
if ((k & 0x01) == 0) {
hash ^= tab[i + 0];
hash ^= tab[i];
}
if ((k & 0x02) == 0) {
hash ^= tab[i + 1];
@ -238,7 +238,7 @@ public class HashUtil {
int oneEighth = bitsInUnsignedInt / 8;
int highBits = 0xFFFFFFFF << (bitsInUnsignedInt - oneEighth);
int hash = 0;
int test = 0;
int test;
for (int i = 0; i < str.length(); i++) {
hash = (hash << oneEighth) + str.charAt(i);
@ -259,7 +259,7 @@ public class HashUtil {
*/
public static int elfHash(String str) {
int hash = 0;
int x = 0;
int x;
for (int i = 0; i < str.length(); i++) {
hash = (hash << 4) + str.charAt(i);
@ -361,7 +361,7 @@ public class HashUtil {
* @return Hash值
*/
public static long tianlHash(String str) {
long hash = 0;
long hash;
int iLength = str.length();
if (iLength == 0) {

View File

@ -7,11 +7,10 @@ import java.nio.charset.Charset;
* 十六进制简写为hex或下标16在数学中是一种逢16进1的进位制一般用数字0到9和字母A到F表示其中:A~F即10~15<br>
* 例如十进制数57在二进制写作111001在16进制写作39<br>
* 像java,c这样的语言为了区分十六进制和十进制数值,会在十六进制数的前面加上 0x,比如0x20是十进制的32,而不是十进制的20<br>
*
* <p>
* 参考https://my.oschina.net/xinxingegeya/blog/287476
*
* @author Looly
*
*/
public class HexUtil {
@ -47,6 +46,7 @@ public class HexUtil {
}
// ---------------------------------------------------------------------------------------------------- encode
/**
* 将字节数组转换为十六进制字符数组
*
@ -122,6 +122,7 @@ public class HexUtil {
}
// ---------------------------------------------------------------------------------------------------- decode
/**
* 将十六进制字符数组转换为字符串默认编码UTF-8
*
@ -200,6 +201,7 @@ public class HexUtil {
}
// ---------------------------------------------------------------------------------------- Color
/**
* {@link Color}编码为Hex形式
*
@ -220,7 +222,7 @@ public class HexUtil {
* @since 3.0.8
*/
public static String encodeColor(Color color, String prefix) {
final StringBuffer builder = new StringBuffer(prefix);
final StringBuilder builder = new StringBuilder(prefix);
String colorHex;
colorHex = Integer.toHexString(color.getRed());
if (1 == colorHex.length()) {
@ -289,13 +291,11 @@ public class HexUtil {
* @since 4.0.1
*/
public static String toUnicodeHex(char ch) {
StringBuilder sb = new StringBuilder(6);
sb.append("\\u");
sb.append(DIGITS_LOWER[(ch >> 12) & 15]);
sb.append(DIGITS_LOWER[(ch >> 8) & 15]);
sb.append(DIGITS_LOWER[(ch >> 4) & 15]);
sb.append(DIGITS_LOWER[(ch) & 15]);
return sb.toString();
return "\\u" +//
DIGITS_LOWER[(ch >> 12) & 15] +//
DIGITS_LOWER[(ch >> 8) & 15] +//
DIGITS_LOWER[(ch >> 4) & 15] +//
DIGITS_LOWER[(ch) & 15];
}
/**
@ -322,6 +322,7 @@ public class HexUtil {
/**
* 将byte值转为16进制并添加到{@link StringBuilder}
*
* @param builder {@link StringBuilder}
* @param b byte
* @param toLowerCase 是否使用小写
@ -337,6 +338,7 @@ public class HexUtil {
}
// ---------------------------------------------------------------------------------------- Private method start
/**
* 将字节数组转换为十六进制字符串
*

View File

@ -85,8 +85,7 @@ public class PageUtil {
* @return 分页条
*/
public static int[] rainbow(int currentPage, int pageCount, int displayCount) {
boolean isEven = true;
isEven = displayCount % 2 == 0;
boolean isEven = displayCount % 2 == 0;
int left = displayCount / 2;
int right = displayCount / 2;

View File

@ -300,6 +300,7 @@ public class TypeUtil {
// 查找方法定义所在类或接口中此泛型参数的位置
final Type[] result = new Type[size];
for(int i = 0; i < typeVariables.length; i++) {
//noinspection SuspiciousMethodCalls
result[i] = (typeVariables[i] instanceof TypeVariable) ? tableMap.get(typeVariables[i]) : typeVariables[i];
}
return result;

View File

@ -21,7 +21,7 @@ public @interface AnnotationForTest {
/**
* 注解的默认属性值
*
* @return
* @return 属性值
*/
String value();
}

View File

@ -12,7 +12,7 @@ public class AnnotationUtilTest {
}
@AnnotationForTest("测试")
class ClassWithAnnotation{
static class ClassWithAnnotation{
}
}

View File

@ -24,7 +24,7 @@ public class ClassUtilTest {
}
@SuppressWarnings("unused")
class TestClass {
static class TestClass {
private String privateField;
protected String field;

View File

@ -35,7 +35,7 @@ public class DayOfWeekValueParser extends SimpleValueParser {
* 解析别名
* @param value 别名值
* @return 月份int值
* @throws CronException
* @throws CronException 无效别名抛出此异常
*/
private int parseAlias(String value) throws CronException {
if(value.equalsIgnoreCase("L")){

View File

@ -30,7 +30,7 @@ public class MonthValueParser extends SimpleValueParser {
* 解析别名
* @param value 别名值
* @return 月份int值
* @throws CronException
* @throws CronException 无效月别名抛出此异常
*/
private int parseAlias(String value) throws CronException {
for (int i = 0; i < ALIASES.length; i++) {

View File

@ -81,7 +81,7 @@ public class DefaultHMacEngine implements MacEngine {
}
byte[] buffer = new byte[bufferLength];
byte[] result = null;
byte[] result;
try {
int read = data.read(buffer, 0, bufferLength);

View File

@ -55,7 +55,7 @@ public class DialectFactory {
public final static String DRIVER_DM7 = "dm.jdbc.driver.DmDriver";
private static Map<DataSource, Dialect> dialectPool = new ConcurrentHashMap<>();
private static Object lock = new Object();
private static final Object lock = new Object();
private DialectFactory() {
}

View File

@ -44,7 +44,7 @@ public class DriverUtil {
}
Connection conn = null;
String driver = null;
String driver;
try {
try {
conn = ds.getConnection();
@ -69,7 +69,7 @@ public class DriverUtil {
* @throws DbRuntimeException SQL异常包装获取元数据信息失败
*/
public static String identifyDriver(Connection conn) throws DbRuntimeException {
String driver = null;
String driver;
DatabaseMetaData meta;
try {
meta = conn.getMetaData();

View File

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

View File

@ -37,7 +37,7 @@ public class ConcurentTest {
ThreadUtil.execute(new Runnable() {
@Override
public void run() {
List<Entity> find = null;
List<Entity> find;
try {
find = db.find(CollectionUtil.newArrayList("name AS name2"), Entity.create("user"), new EntityListHandler());
} catch (SQLException e) {

View File

@ -33,15 +33,12 @@ public class MySQLTest {
* 事务测试<br>
* 更新三条信息低2条后抛出异常正常情况下三条都应该不变
*
* @throws SQLException
* @throws SQLException SQL异常
*/
@Test(expected=SQLException.class)
@Ignore
public void txTest() throws SQLException {
Db.use("mysql").tx(new VoidFunc1<Db>() {
@Override
public void call(Db db) throws Exception {
Db.use("mysql").tx(db -> {
int update = db.update(Entity.create("user").set("text", "描述100"), Entity.create().set("id", 100));
db.update(Entity.create("user").set("text", "描述101"), Entity.create().set("id", 101));
if(1 == update) {
@ -49,7 +46,6 @@ public class MySQLTest {
throw new RuntimeException("Error");
}
db.update(Entity.create("user").set("text", "描述102"), Entity.create().set("id", 102));
}
});
}

View File

@ -1,14 +1,11 @@
package cn.hutool.db;
import java.sql.SQLException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import java.sql.SQLException;
public class UpdateTest {
@ -22,7 +19,7 @@ public class UpdateTest {
/**
* 对更新做单元测试
*
* @throws SQLException
* @throws SQLException SQL异常
*/
@Test
@Ignore

View File

@ -205,12 +205,7 @@ public class Sftp extends AbstractFtp {
* @since 4.0.5
*/
public List<String> lsDirs(String path) {
return ls(path, new Filter<LsEntry>() {
@Override
public boolean accept(LsEntry t) {
return t.getAttrs().isDir();
}
});
return ls(path, t -> t.getAttrs().isDir());
}
/**
@ -221,12 +216,7 @@ public class Sftp extends AbstractFtp {
* @since 4.0.5
*/
public List<String> lsFiles(String path) {
return ls(path, new Filter<LsEntry>() {
@Override
public boolean accept(LsEntry t) {
return false == t.getAttrs().isDir();
}
});
return ls(path, t -> false == t.getAttrs().isDir());
}
/**
@ -240,17 +230,14 @@ public class Sftp extends AbstractFtp {
public List<String> ls(String path, final Filter<LsEntry> filter) {
final List<String> fileNames = new ArrayList<>();
try {
channel.ls(path, new LsEntrySelector() {
@Override
public int select(LsEntry entry) {
channel.ls(path, entry -> {
String fileName = entry.getFilename();
if (false == StrUtil.equals(".", fileName) && false == StrUtil.equals("..", fileName)) {
if (null == filter || filter.accept(entry)) {
fileNames.add(entry.getFilename());
}
}
return CONTINUE;
}
return LsEntrySelector.CONTINUE;
});
} catch (SftpException e) {
throw new JschRuntimeException(e);
@ -316,7 +303,7 @@ public class Sftp extends AbstractFtp {
return false;
}
Vector<LsEntry> list = null;
Vector<LsEntry> list;
try {
list = channel.ls(channel.pwd());
} catch (SftpException e) {
@ -418,7 +405,7 @@ public class Sftp extends AbstractFtp {
}
@Override
public void close() throws IOException {
public void close() {
JschUtil.close(this.channel);
JschUtil.close(this.session);
}

View File

@ -68,7 +68,7 @@ public class ThymeleafEngine implements TemplateEngine {
config = new TemplateConfig();
}
ITemplateResolver resolver = null;
ITemplateResolver resolver;
switch (config.getResourceMode()) {
case CLASSPATH:
final ClassLoaderTemplateResolver classLoaderResolver = new ClassLoaderTemplateResolver();
@ -94,9 +94,6 @@ public class ThymeleafEngine implements TemplateEngine {
case STRING:
resolver = new StringTemplateResolver();
break;
case COMPOSITE:
resolver = new DefaultTemplateResolver();
break;
default:
resolver = new DefaultTemplateResolver();
break;

View File

@ -33,7 +33,7 @@ public class VelocityUtil {
/** 是否初始化了默认引擎 */
private static boolean isInited;
/** 全局上下文,当设定值时,对于每个模板都有效 */
private static Map<String, Object> globalContext = new HashMap<String, Object>();
private static Map<String, Object> globalContext = new HashMap<>();
/**
* 设置Velocity全局上下文<br>
@ -278,7 +278,7 @@ public class VelocityUtil {
public static VelocityContext parseRequest(VelocityContext context, javax.servlet.http.HttpServletRequest request) {
final Enumeration<String> attrs = request.getAttributeNames();
if (attrs != null) {
String attrName = null;
String attrName;
while (attrs.hasMoreElements()) {
attrName = attrs.nextElement();
context.put(attrName, request.getAttribute(attrName));
@ -298,7 +298,7 @@ public class VelocityUtil {
if (null != session) {
final Enumeration<String> sessionAttrs = session.getAttributeNames();
if (sessionAttrs != null) {
String attrName = null;
String attrName;
while (sessionAttrs.hasMoreElements()) {
attrName = sessionAttrs.nextElement();
context.put(attrName, session.getAttribute(attrName));

View File

@ -31,7 +31,7 @@ public class IKAnalyzerResult extends AbstractResult {
@Override
protected Word nextWord() {
Lexeme next = null;
Lexeme next;
try {
next = this.seg.next();
} catch (IOException e) {

View File

@ -36,7 +36,7 @@ public class JcsegResult implements Result{
if (this.cachedWord != null) {
return true;
}
IWord next = null;
IWord next;
try {
next = this.result.next();
} catch (IOException e) {

View File

@ -30,7 +30,7 @@ public class MmsegResult extends AbstractResult {
@Override
protected Word nextWord() {
com.chenlb.mmseg4j.Word next = null;
com.chenlb.mmseg4j.Word next;
try {
next = this.mmSeg.next();
} catch (IOException e) {

View File

@ -81,7 +81,7 @@ public class SoapUtil {
} catch (SOAPException | IOException e) {
throw new SoapRuntimeException(e);
}
String messageToString = null;
String messageToString;
try {
messageToString = out.toString(charset.toString());
} catch (UnsupportedEncodingException e) {

View File

@ -2,7 +2,9 @@ package cn.hutool.json;
import java.util.Iterator;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.XmlUtil;
/**
@ -46,12 +48,12 @@ public class XML {
* @param context The JSONObject that will include the new material.
* @param name The tag name.
* @return true if the close tag is processed.
* @throws JSONException
* @throws JSONException JSON异常
*/
private static boolean parse(XMLTokener x, JSONObject context, String name, boolean keepStrings) throws JSONException {
char c;
int i;
JSONObject jsonobject = null;
JSONObject jsonobject;
String string;
String tagName;
Object token;
@ -265,7 +267,6 @@ public class XML {
JSONObject jo;
String key;
Iterator<String> keys;
String string;
Object value;
if (object instanceof JSONObject) {
@ -284,11 +285,10 @@ public class XML {
key = keys.next();
value = jo.get(key);
if (value == null) {
value = "";
} else if (value.getClass().isArray()) {
value = StrUtil.EMPTY;
} else if (ArrayUtil.isArray(value)) {
value = new JSONArray(value);
}
string = value instanceof String ? (String) value : null;
// Emit content in body
if ("content".equals(key)) {
@ -362,8 +362,10 @@ public class XML {
}
}
string = (object == null) ? "null" : XmlUtil.escape(object.toString());
return (tagName == null) ? "\"" + string + "\"" : (string.length() == 0) ? "<" + tagName + "/>" : "<" + tagName + ">" + string + "</" + tagName + ">";
String string = (object == null) ? StrUtil.NULL : XmlUtil.escape(object.toString());
return (tagName == null) ?
"\"" + string + "\"" : (string.length() == 0) ? "<" + tagName + "/>"
: "<" + tagName + ">" + string + "</" + tagName + ">";
}
}