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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -61,7 +61,7 @@ public class CollectionConverter implements Converter<Collection<?>> {
@Override @Override
public Collection<?> convert(Object value, Collection<?> defaultValue) throws IllegalArgumentException { public Collection<?> convert(Object value, Collection<?> defaultValue) throws IllegalArgumentException {
Collection<?> result = null; Collection<?> result;
try { try {
result = convertInternal(value); result = convertInternal(value);
} catch (RuntimeException e) { } 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)); return StrUtil.isBlank(valueStr) ? null : Integer.valueOf(NumberUtil.parseInt(valueStr));
} else if (AtomicInteger.class == targetType) { } else if (AtomicInteger.class == targetType) {
int intValue; final AtomicInteger intValue = new AtomicInteger();
if (value instanceof Number) { if (value instanceof Number) {
intValue = ((Number) value).intValue(); intValue.set(((Number) value).intValue());
} else if(value instanceof Boolean) { } else if(value instanceof Boolean) {
intValue = BooleanUtil.toInt((Boolean)value); intValue.set(BooleanUtil.toInt((Boolean) value));
} }
final String valueStr = convertToStr(value); final String valueStr = convertToStr(value);
if (StrUtil.isBlank(valueStr)) { if (StrUtil.isBlank(valueStr)) {
return null; return null;
} }
intValue = NumberUtil.parseInt(valueStr); intValue.set(NumberUtil.parseInt(valueStr));
return new AtomicInteger(intValue); return intValue;
} else if (Long.class == targetType) { } else if (Long.class == targetType) {
if (value instanceof Number) { if (value instanceof Number) {
return Long.valueOf(((Number) value).longValue()); 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)); return StrUtil.isBlank(valueStr) ? null : Long.valueOf(NumberUtil.parseLong(valueStr));
} else if (AtomicLong.class == targetType) { } else if (AtomicLong.class == targetType) {
long longValue; final AtomicLong longValue = new AtomicLong();
if (value instanceof Number) { if (value instanceof Number) {
longValue = ((Number) value).longValue(); longValue.set(((Number) value).longValue());
} else if(value instanceof Boolean) { } else if(value instanceof Boolean) {
longValue = BooleanUtil.toLong((Boolean)value); longValue.set(BooleanUtil.toLong((Boolean) value));
} }
final String valueStr = convertToStr(value); final String valueStr = convertToStr(value);
if (StrUtil.isBlank(valueStr)) { if (StrUtil.isBlank(valueStr)) {
return null; return null;
} }
longValue = NumberUtil.parseLong(valueStr); longValue.set(NumberUtil.parseLong(valueStr));
return new AtomicLong(longValue); return longValue;
} else if (Float.class == targetType) { } else if (Float.class == targetType) {
if (value instanceof Number) { if (value instanceof Number) {

View File

@ -51,8 +51,10 @@ public class BetweenFormater implements Serializable{
long day = betweenMs / DateUnit.DAY.getMillis(); long day = betweenMs / DateUnit.DAY.getMillis();
long hour = betweenMs / DateUnit.HOUR.getMillis() - day * 24; long hour = betweenMs / DateUnit.HOUR.getMillis() - day * 24;
long minute = betweenMs / DateUnit.MINUTE.getMillis() - day * 24 * 60 - hour * 60; 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(); final int level = this.level.ordinal();
int levelCount = 0; int levelCount = 0;

View File

@ -104,7 +104,7 @@ class FastDatePrinter extends AbstractDateBasic implements DatePrinter {
if (tokenLen == 2) { if (tokenLen == 2) {
rule = TwoDigitYearField.INSTANCE; rule = TwoDigitYearField.INSTANCE;
} else { } else {
rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen); rule = selectNumberRule(Calendar.YEAR, Math.max(tokenLen, 4));
} }
if (c == 'Y') { if (c == 'Y') {
rule = new WeekYear((NumberRule) rule); 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 { private void readTail() throws IOException {
final long len = this.randomAccessFile.length(); final long len = this.randomAccessFile.length();

View File

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

View File

@ -27,7 +27,7 @@ public class PatternPool {
/** IP v4 */ /** IP v4 */
public final static Pattern IPV4 = Pattern.compile("\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b"); public final static Pattern IPV4 = Pattern.compile("\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b");
/** IP v6 */ /** IP v6 */
public final static Pattern IPV6 = Pattern.compile("(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1?[0-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+)?)$"); public final static Pattern MONEY = Pattern.compile("^(\\d+(?:\\.\\d+)?)$");
/** 邮件符合RFC 5322规范正则来自http://emailregex.com/ */ /** 邮件符合RFC 5322规范正则来自http://emailregex.com/ */
@ -52,7 +52,7 @@ public class PatternPool {
/** 不带横线的UUID */ /** 不带横线的UUID */
public final static Pattern UUID_SIMPLE = Pattern.compile("^[0-9a-z]{32}$"); 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地址正则 */ /** 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); 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进制字符串 */ /** 16进制字符串 */

View File

@ -39,9 +39,9 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
/** 索引 */ /** 索引 */
private int index = 0; 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.steper = steper;
this.next = safeStep(this.current); this.next = safeStep(this.current);
this.includeStart = isIncludeStart; this.includeStart = isIncludeStart;
includeEnd = true;
this.includeEnd = isIncludeEnd; this.includeEnd = isIncludeEnd;
} }

View File

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

View File

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

View File

@ -6,17 +6,16 @@ import cn.hutool.core.util.StrUtil;
/** /**
* 提供Unicode字符串和普通字符串之间的转换 * 提供Unicode字符串和普通字符串之间的转换
* *
* @author 兜兜毛毛, looly * @author 兜兜毛毛, looly
* @since 4.0.0 * @since 4.0.0
*
*/ */
public class UnicodeUtil { public class UnicodeUtil {
/** /**
* Unicode字符串转为普通字符串<br> * Unicode字符串转为普通字符串<br>
* Unicode字符串的表现方式为\\uXXXX * Unicode字符串的表现方式为\\uXXXX
* *
* @param unicode Unicode字符串 * @param unicode Unicode字符串
* @return 普通字符串 * @return 普通字符串
*/ */
@ -27,37 +26,37 @@ public class UnicodeUtil {
final int len = unicode.length(); final int len = unicode.length();
StrBuilder sb = StrBuilder.create(len); StrBuilder sb = StrBuilder.create(len);
int i = -1; int i;
int pos = 0; int pos = 0;
while ((i = StrUtil.indexOfIgnoreCase(unicode, "\\u", pos)) != -1) { while ((i = StrUtil.indexOfIgnoreCase(unicode, "\\u", pos)) != -1) {
sb.append(unicode, pos, i);//写入Unicode符之前的部分 sb.append(unicode, pos, i);//写入Unicode符之前的部分
pos = i; pos = i;
if (i + 5 < len) { if (i + 5 < len) {
char c = 0; char c;
try { try {
c = (char) Integer.parseInt(unicode.substring(i + 2, i + 6), 16); c = (char) Integer.parseInt(unicode.substring(i + 2, i + 6), 16);
sb.append(c); sb.append(c);
pos = i + 6;//跳过整个Unicode符 pos = i + 6;//跳过整个Unicode符
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
//非法Unicode符跳过 //非法Unicode符跳过
sb.append(unicode, pos, i+2);//写入"\\u" sb.append(unicode, pos, i + 2);//写入"\\u"
pos = i + 2; pos = i + 2;
} }
}else { } else {
pos = i;//非Unicode符结束 pos = i;//非Unicode符结束
break; break;
} }
} }
if(pos < len) { if (pos < len) {
sb.append(unicode,pos, len); sb.append(unicode, pos, len);
} }
return sb.toString(); return sb.toString();
} }
/** /**
* 字符串编码为Unicode形式 * 字符串编码为Unicode形式
* *
* @param str 被编码的字符串 * @param str 被编码的字符串
* @return Unicode字符串 * @return Unicode字符串
*/ */
@ -67,8 +66,8 @@ public class UnicodeUtil {
/** /**
* 字符串编码为Unicode形式 * 字符串编码为Unicode形式
* *
* @param str 被编码的字符串 * @param str 被编码的字符串
* @param isSkipAscii 是否跳过ASCII字符只跳过可见字符 * @param isSkipAscii 是否跳过ASCII字符只跳过可见字符
* @return Unicode字符串 * @return Unicode字符串
*/ */
@ -82,9 +81,9 @@ public class UnicodeUtil {
char c; char c;
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
c = str.charAt(i); c = str.charAt(i);
if(isSkipAscii && CharUtil.isAsciiPrintable(c) ) { if (isSkipAscii && CharUtil.isAsciiPrintable(c)) {
unicode.append(c); unicode.append(c);
}else { } else {
unicode.append(HexUtil.toUnicodeHex(c)); unicode.append(HexUtil.toUnicodeHex(c));
} }
} }

View File

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

View File

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

View File

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

View File

@ -7,28 +7,27 @@ import java.nio.charset.Charset;
* 十六进制简写为hex或下标16在数学中是一种逢16进1的进位制一般用数字0到9和字母A到F表示其中:A~F即10~15<br> * 十六进制简写为hex或下标16在数学中是一种逢16进1的进位制一般用数字0到9和字母A到F表示其中:A~F即10~15<br>
* 例如十进制数57在二进制写作111001在16进制写作39<br> * 例如十进制数57在二进制写作111001在16进制写作39<br>
* 像java,c这样的语言为了区分十六进制和十进制数值,会在十六进制数的前面加上 0x,比如0x20是十进制的32,而不是十进制的20<br> * 像java,c这样的语言为了区分十六进制和十进制数值,会在十六进制数的前面加上 0x,比如0x20是十进制的32,而不是十进制的20<br>
* * <p>
* 参考https://my.oschina.net/xinxingegeya/blog/287476 * 参考https://my.oschina.net/xinxingegeya/blog/287476
*
* @author Looly
* *
* @author Looly
*/ */
public class HexUtil { public class HexUtil {
/** /**
* 用于建立十六进制字符的输出的小写字符数组 * 用于建立十六进制字符的输出的小写字符数组
*/ */
private static final char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; private static final char[] DIGITS_LOWER = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
/** /**
* 用于建立十六进制字符的输出的大写字符数组 * 用于建立十六进制字符的输出的大写字符数组
*/ */
private static final char[] DIGITS_UPPER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; private static final char[] DIGITS_UPPER = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
/** /**
* 判断给定字符串是否为16进制数<br> * 判断给定字符串是否为16进制数<br>
* 如果是需要使用对应数字类型对象的<code>decode</code>方法解码<br> * 如果是需要使用对应数字类型对象的<code>decode</code>方法解码<br>
* 例如{@code Integer.decode}方法解码int类型的16进制数字 * 例如{@code Integer.decode}方法解码int类型的16进制数字
* *
* @param value * @param value
* @return 是否为16进制 * @return 是否为16进制
*/ */
@ -41,12 +40,13 @@ public class HexUtil {
return false; return false;
} }
return true; return true;
}else { } else {
return false; return false;
} }
} }
// ---------------------------------------------------------------------------------------------------- encode // ---------------------------------------------------------------------------------------------------- encode
/** /**
* 将字节数组转换为十六进制字符数组 * 将字节数组转换为十六进制字符数组
* *
@ -60,7 +60,7 @@ public class HexUtil {
/** /**
* 将字节数组转换为十六进制字符数组 * 将字节数组转换为十六进制字符数组
* *
* @param str 字符串 * @param str 字符串
* @param charset 编码 * @param charset 编码
* @return 十六进制char[] * @return 十六进制char[]
*/ */
@ -71,7 +71,7 @@ public class HexUtil {
/** /**
* 将字节数组转换为十六进制字符数组 * 将字节数组转换为十六进制字符数组
* *
* @param data byte[] * @param data byte[]
* @param toLowerCase <code>true</code> 传换成小写格式 <code>false</code> 传换成大写格式 * @param toLowerCase <code>true</code> 传换成小写格式 <code>false</code> 传换成大写格式
* @return 十六进制char[] * @return 十六进制char[]
*/ */
@ -92,7 +92,7 @@ public class HexUtil {
/** /**
* 将字节数组转换为十六进制字符串结果为小写 * 将字节数组转换为十六进制字符串结果为小写
* *
* @param data 被编码的字符串 * @param data 被编码的字符串
* @param charset 编码 * @param charset 编码
* @return 十六进制String * @return 十六进制String
*/ */
@ -113,7 +113,7 @@ public class HexUtil {
/** /**
* 将字节数组转换为十六进制字符串 * 将字节数组转换为十六进制字符串
* *
* @param data byte[] * @param data byte[]
* @param toLowerCase <code>true</code> 传换成小写格式 <code>false</code> 传换成大写格式 * @param toLowerCase <code>true</code> 传换成小写格式 <code>false</code> 传换成大写格式
* @return 十六进制String * @return 十六进制String
*/ */
@ -122,6 +122,7 @@ public class HexUtil {
} }
// ---------------------------------------------------------------------------------------------------- decode // ---------------------------------------------------------------------------------------------------- decode
/** /**
* 将十六进制字符数组转换为字符串默认编码UTF-8 * 将十六进制字符数组转换为字符串默认编码UTF-8
* *
@ -135,7 +136,7 @@ public class HexUtil {
/** /**
* 将十六进制字符数组转换为字符串 * 将十六进制字符数组转换为字符串
* *
* @param hexStr 十六进制String * @param hexStr 十六进制String
* @param charset 编码 * @param charset 编码
* @return 字符串 * @return 字符串
*/ */
@ -200,9 +201,10 @@ public class HexUtil {
} }
// ---------------------------------------------------------------------------------------- Color // ---------------------------------------------------------------------------------------- Color
/** /**
* {@link Color}编码为Hex形式 * {@link Color}编码为Hex形式
* *
* @param color {@link Color} * @param color {@link Color}
* @return Hex字符串 * @return Hex字符串
* @since 3.0.8 * @since 3.0.8
@ -213,14 +215,14 @@ public class HexUtil {
/** /**
* {@link Color}编码为Hex形式 * {@link Color}编码为Hex形式
* *
* @param color {@link Color} * @param color {@link Color}
* @param prefix 前缀字符串可以是#0x等 * @param prefix 前缀字符串可以是#0x等
* @return Hex字符串 * @return Hex字符串
* @since 3.0.8 * @since 3.0.8
*/ */
public static String encodeColor(Color color, String prefix) { public static String encodeColor(Color color, String prefix) {
final StringBuffer builder = new StringBuffer(prefix); final StringBuilder builder = new StringBuilder(prefix);
String colorHex; String colorHex;
colorHex = Integer.toHexString(color.getRed()); colorHex = Integer.toHexString(color.getRed());
if (1 == colorHex.length()) { if (1 == colorHex.length()) {
@ -242,7 +244,7 @@ public class HexUtil {
/** /**
* 将Hex颜色值转为 * 将Hex颜色值转为
* *
* @param hexColor 16进制颜色值可以以#开头也可以用0x开头 * @param hexColor 16进制颜色值可以以#开头也可以用0x开头
* @return {@link Color} * @return {@link Color}
* @since 3.0.8 * @since 3.0.8
@ -254,11 +256,11 @@ public class HexUtil {
/** /**
* 将指定int值转换为Unicode字符串形式常用于特殊字符例如汉字转Unicode形式<br> * 将指定int值转换为Unicode字符串形式常用于特殊字符例如汉字转Unicode形式<br>
* 转换的字符串如果u后不足4位则前面用0填充例如 * 转换的字符串如果u后不足4位则前面用0填充例如
* *
* <pre> * <pre>
* '我' =\u4f60 * '我' =\u4f60
* </pre> * </pre>
* *
* @param value int值也可以是char * @param value int值也可以是char
* @return Unicode表现形式 * @return Unicode表现形式
*/ */
@ -279,28 +281,26 @@ public class HexUtil {
/** /**
* 将指定char值转换为Unicode字符串形式常用于特殊字符例如汉字转Unicode形式<br> * 将指定char值转换为Unicode字符串形式常用于特殊字符例如汉字转Unicode形式<br>
* 转换的字符串如果u后不足4位则前面用0填充例如 * 转换的字符串如果u后不足4位则前面用0填充例如
* *
* <pre> * <pre>
* '我' =\u4f60 * '我' =\u4f60
* </pre> * </pre>
* *
* @param ch char值 * @param ch char值
* @return Unicode表现形式 * @return Unicode表现形式
* @since 4.0.1 * @since 4.0.1
*/ */
public static String toUnicodeHex(char ch) { public static String toUnicodeHex(char ch) {
StringBuilder sb = new StringBuilder(6); return "\\u" +//
sb.append("\\u"); DIGITS_LOWER[(ch >> 12) & 15] +//
sb.append(DIGITS_LOWER[(ch >> 12) & 15]); DIGITS_LOWER[(ch >> 8) & 15] +//
sb.append(DIGITS_LOWER[(ch >> 8) & 15]); DIGITS_LOWER[(ch >> 4) & 15] +//
sb.append(DIGITS_LOWER[(ch >> 4) & 15]); DIGITS_LOWER[(ch) & 15];
sb.append(DIGITS_LOWER[(ch) & 15]);
return sb.toString();
} }
/** /**
* 转为16进制字符串 * 转为16进制字符串
* *
* @param value int值 * @param value int值
* @return 16进制字符串 * @return 16进制字符串
* @since 4.4.1 * @since 4.4.1
@ -311,7 +311,7 @@ public class HexUtil {
/** /**
* 转为16进制字符串 * 转为16进制字符串
* *
* @param value int值 * @param value int值
* @return 16进制字符串 * @return 16进制字符串
* @since 4.4.1 * @since 4.4.1
@ -319,17 +319,18 @@ public class HexUtil {
public static String toHex(long value) { public static String toHex(long value) {
return Long.toHexString(value); return Long.toHexString(value);
} }
/** /**
* 将byte值转为16进制并添加到{@link StringBuilder} * 将byte值转为16进制并添加到{@link StringBuilder}
* @param builder {@link StringBuilder} *
* @param b byte * @param builder {@link StringBuilder}
* @param b byte
* @param toLowerCase 是否使用小写 * @param toLowerCase 是否使用小写
* @since 4.4.1 * @since 4.4.1
*/ */
public static void appendHex(StringBuilder builder, byte b, boolean toLowerCase) { public static void appendHex(StringBuilder builder, byte b, boolean toLowerCase) {
final char[] toDigits = toLowerCase ? DIGITS_LOWER : DIGITS_UPPER; final char[] toDigits = toLowerCase ? DIGITS_LOWER : DIGITS_UPPER;
int high = (b & 0xf0) >>> 4;//高位 int high = (b & 0xf0) >>> 4;//高位
int low = b & 0x0f;//低位 int low = b & 0x0f;//低位
builder.append(toDigits[high]); builder.append(toDigits[high]);
@ -337,10 +338,11 @@ public class HexUtil {
} }
// ---------------------------------------------------------------------------------------- Private method start // ---------------------------------------------------------------------------------------- Private method start
/** /**
* 将字节数组转换为十六进制字符串 * 将字节数组转换为十六进制字符串
* *
* @param data byte[] * @param data byte[]
* @param toDigits 用于控制输出的char[] * @param toDigits 用于控制输出的char[]
* @return 十六进制String * @return 十六进制String
*/ */
@ -351,7 +353,7 @@ public class HexUtil {
/** /**
* 将字节数组转换为十六进制字符数组 * 将字节数组转换为十六进制字符数组
* *
* @param data byte[] * @param data byte[]
* @param toDigits 用于控制输出的char[] * @param toDigits 用于控制输出的char[]
* @return 十六进制char[] * @return 十六进制char[]
*/ */
@ -369,7 +371,7 @@ public class HexUtil {
/** /**
* 将十六进制字符转换成一个整数 * 将十六进制字符转换成一个整数
* *
* @param ch 十六进制char * @param ch 十六进制char
* @param index 十六进制字符在字符数组中的位置 * @param index 十六进制字符在字符数组中的位置
* @return 一个整数 * @return 一个整数
* @throws RuntimeException 当ch不是一个合法的十六进制字符时抛出运行时异常 * @throws RuntimeException 当ch不是一个合法的十六进制字符时抛出运行时异常

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -30,7 +30,7 @@ public class MonthValueParser extends SimpleValueParser {
* 解析别名 * 解析别名
* @param value 别名值 * @param value 别名值
* @return 月份int值 * @return 月份int值
* @throws CronException * @throws CronException 无效月别名抛出此异常
*/ */
private int parseAlias(String value) throws CronException { private int parseAlias(String value) throws CronException {
for (int i = 0; i < ALIASES.length; i++) { 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[] buffer = new byte[bufferLength];
byte[] result = null; byte[] result;
try { try {
int read = data.read(buffer, 0, bufferLength); 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"; public final static String DRIVER_DM7 = "dm.jdbc.driver.DmDriver";
private static Map<DataSource, Dialect> dialectPool = new ConcurrentHashMap<>(); private static Map<DataSource, Dialect> dialectPool = new ConcurrentHashMap<>();
private static Object lock = new Object(); private static final Object lock = new Object();
private DialectFactory() { private DialectFactory() {
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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