mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -512,7 +512,7 @@ public class HashCodeBuilder implements Builder<Integer> {
|
||||
/**
|
||||
* Running total of the hashCode.
|
||||
*/
|
||||
private int iTotal = 0;
|
||||
private int iTotal;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@@ -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) {
|
||||
|
@@ -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;
|
||||
|
@@ -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) {
|
||||
|
@@ -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; // 加:
|
||||
// thousand、million、billion
|
||||
lm.insert(0, transThree(a[i]) + " " + parseMore(i) + " "); // 加:
|
||||
// thousand、million、billion
|
||||
} 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整除
|
||||
|
@@ -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;
|
||||
|
@@ -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) {
|
||||
|
@@ -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) {
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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();
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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进制字符串 */
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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()) {
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -6,17 +6,16 @@ import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* 提供Unicode字符串和普通字符串之间的转换
|
||||
*
|
||||
*
|
||||
* @author 兜兜毛毛, looly
|
||||
* @since 4.0.0
|
||||
*
|
||||
*/
|
||||
public class UnicodeUtil {
|
||||
|
||||
/**
|
||||
* Unicode字符串转为普通字符串<br>
|
||||
* Unicode字符串的表现方式为:\\uXXXX
|
||||
*
|
||||
*
|
||||
* @param unicode Unicode字符串
|
||||
* @return 普通字符串
|
||||
*/
|
||||
@@ -27,37 +26,37 @@ 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;
|
||||
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);
|
||||
pos = i + 6;//跳过整个Unicode符
|
||||
} catch (NumberFormatException e) {
|
||||
//非法Unicode符,跳过
|
||||
sb.append(unicode, pos, i+2);//写入"\\u"
|
||||
sb.append(unicode, pos, i + 2);//写入"\\u"
|
||||
pos = i + 2;
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
pos = i;//非Unicode符,结束
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(pos < len) {
|
||||
sb.append(unicode,pos, len);
|
||||
|
||||
if (pos < len) {
|
||||
sb.append(unicode, pos, len);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字符串编码为Unicode形式
|
||||
*
|
||||
*
|
||||
* @param str 被编码的字符串
|
||||
* @return Unicode字符串
|
||||
*/
|
||||
@@ -67,8 +66,8 @@ public class UnicodeUtil {
|
||||
|
||||
/**
|
||||
* 字符串编码为Unicode形式
|
||||
*
|
||||
* @param str 被编码的字符串
|
||||
*
|
||||
* @param str 被编码的字符串
|
||||
* @param isSkipAscii 是否跳过ASCII字符(只跳过可见字符)
|
||||
* @return Unicode字符串
|
||||
*/
|
||||
@@ -82,9 +81,9 @@ public class UnicodeUtil {
|
||||
char c;
|
||||
for (int i = 0; i < len; i++) {
|
||||
c = str.charAt(i);
|
||||
if(isSkipAscii && CharUtil.isAsciiPrintable(c) ) {
|
||||
if (isSkipAscii && CharUtil.isAsciiPrintable(c)) {
|
||||
unicode.append(c);
|
||||
}else {
|
||||
} else {
|
||||
unicode.append(HexUtil.toUnicodeHex(c));
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
@@ -7,28 +7,27 @@ 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
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
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>
|
||||
* 如果是,需要使用对应数字类型对象的<code>decode</code>方法解码<br>
|
||||
* 例如:{@code Integer.decode}方法解码int类型的16进制数字
|
||||
*
|
||||
*
|
||||
* @param value 值
|
||||
* @return 是否为16进制
|
||||
*/
|
||||
@@ -41,12 +40,13 @@ public class HexUtil {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------- encode
|
||||
|
||||
/**
|
||||
* 将字节数组转换为十六进制字符数组
|
||||
*
|
||||
@@ -60,7 +60,7 @@ public class HexUtil {
|
||||
/**
|
||||
* 将字节数组转换为十六进制字符数组
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param str 字符串
|
||||
* @param charset 编码
|
||||
* @return 十六进制char[]
|
||||
*/
|
||||
@@ -71,7 +71,7 @@ public class HexUtil {
|
||||
/**
|
||||
* 将字节数组转换为十六进制字符数组
|
||||
*
|
||||
* @param data byte[]
|
||||
* @param data byte[]
|
||||
* @param toLowerCase <code>true</code> 传换成小写格式 , <code>false</code> 传换成大写格式
|
||||
* @return 十六进制char[]
|
||||
*/
|
||||
@@ -92,7 +92,7 @@ public class HexUtil {
|
||||
/**
|
||||
* 将字节数组转换为十六进制字符串,结果为小写
|
||||
*
|
||||
* @param data 被编码的字符串
|
||||
* @param data 被编码的字符串
|
||||
* @param charset 编码
|
||||
* @return 十六进制String
|
||||
*/
|
||||
@@ -113,7 +113,7 @@ public class HexUtil {
|
||||
/**
|
||||
* 将字节数组转换为十六进制字符串
|
||||
*
|
||||
* @param data byte[]
|
||||
* @param data byte[]
|
||||
* @param toLowerCase <code>true</code> 传换成小写格式 , <code>false</code> 传换成大写格式
|
||||
* @return 十六进制String
|
||||
*/
|
||||
@@ -122,6 +122,7 @@ public class HexUtil {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------- decode
|
||||
|
||||
/**
|
||||
* 将十六进制字符数组转换为字符串,默认编码UTF-8
|
||||
*
|
||||
@@ -135,7 +136,7 @@ public class HexUtil {
|
||||
/**
|
||||
* 将十六进制字符数组转换为字符串
|
||||
*
|
||||
* @param hexStr 十六进制String
|
||||
* @param hexStr 十六进制String
|
||||
* @param charset 编码
|
||||
* @return 字符串
|
||||
*/
|
||||
@@ -200,9 +201,10 @@ public class HexUtil {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------- Color
|
||||
|
||||
/**
|
||||
* 将{@link Color}编码为Hex形式
|
||||
*
|
||||
*
|
||||
* @param color {@link Color}
|
||||
* @return Hex字符串
|
||||
* @since 3.0.8
|
||||
@@ -213,14 +215,14 @@ public class HexUtil {
|
||||
|
||||
/**
|
||||
* 将{@link Color}编码为Hex形式
|
||||
*
|
||||
* @param color {@link Color}
|
||||
*
|
||||
* @param color {@link Color}
|
||||
* @param prefix 前缀字符串,可以是#、0x等
|
||||
* @return Hex字符串
|
||||
* @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()) {
|
||||
@@ -242,7 +244,7 @@ public class HexUtil {
|
||||
|
||||
/**
|
||||
* 将Hex颜色值转为
|
||||
*
|
||||
*
|
||||
* @param hexColor 16进制颜色值,可以以#开头,也可以用0x开头
|
||||
* @return {@link Color}
|
||||
* @since 3.0.8
|
||||
@@ -254,11 +256,11 @@ public class HexUtil {
|
||||
/**
|
||||
* 将指定int值转换为Unicode字符串形式,常用于特殊字符(例如汉字)转Unicode形式<br>
|
||||
* 转换的字符串如果u后不足4位,则前面用0填充,例如:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* '我' =》\u4f60
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param value int值,也可以是char
|
||||
* @return Unicode表现形式
|
||||
*/
|
||||
@@ -279,28 +281,26 @@ public class HexUtil {
|
||||
/**
|
||||
* 将指定char值转换为Unicode字符串形式,常用于特殊字符(例如汉字)转Unicode形式<br>
|
||||
* 转换的字符串如果u后不足4位,则前面用0填充,例如:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* '我' =》\u4f60
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param ch char值
|
||||
* @return Unicode表现形式
|
||||
* @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];
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为16进制字符串
|
||||
*
|
||||
*
|
||||
* @param value int值
|
||||
* @return 16进制字符串
|
||||
* @since 4.4.1
|
||||
@@ -311,7 +311,7 @@ public class HexUtil {
|
||||
|
||||
/**
|
||||
* 转为16进制字符串
|
||||
*
|
||||
*
|
||||
* @param value int值
|
||||
* @return 16进制字符串
|
||||
* @since 4.4.1
|
||||
@@ -319,17 +319,18 @@ public class HexUtil {
|
||||
public static String toHex(long value) {
|
||||
return Long.toHexString(value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将byte值转为16进制并添加到{@link StringBuilder}中
|
||||
* @param builder {@link StringBuilder}
|
||||
* @param b byte
|
||||
*
|
||||
* @param builder {@link StringBuilder}
|
||||
* @param b byte
|
||||
* @param toLowerCase 是否使用小写
|
||||
* @since 4.4.1
|
||||
*/
|
||||
public static void appendHex(StringBuilder builder, byte b, boolean toLowerCase) {
|
||||
final char[] toDigits = toLowerCase ? DIGITS_LOWER : DIGITS_UPPER;
|
||||
|
||||
|
||||
int high = (b & 0xf0) >>> 4;//高位
|
||||
int low = b & 0x0f;//低位
|
||||
builder.append(toDigits[high]);
|
||||
@@ -337,10 +338,11 @@ public class HexUtil {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------- Private method start
|
||||
|
||||
/**
|
||||
* 将字节数组转换为十六进制字符串
|
||||
*
|
||||
* @param data byte[]
|
||||
* @param data byte[]
|
||||
* @param toDigits 用于控制输出的char[]
|
||||
* @return 十六进制String
|
||||
*/
|
||||
@@ -351,7 +353,7 @@ public class HexUtil {
|
||||
/**
|
||||
* 将字节数组转换为十六进制字符数组
|
||||
*
|
||||
* @param data byte[]
|
||||
* @param data byte[]
|
||||
* @param toDigits 用于控制输出的char[]
|
||||
* @return 十六进制char[]
|
||||
*/
|
||||
@@ -369,7 +371,7 @@ public class HexUtil {
|
||||
/**
|
||||
* 将十六进制字符转换成一个整数
|
||||
*
|
||||
* @param ch 十六进制char
|
||||
* @param ch 十六进制char
|
||||
* @param index 十六进制字符在字符数组中的位置
|
||||
* @return 一个整数
|
||||
* @throws RuntimeException 当ch不是一个合法的十六进制字符时,抛出运行时异常
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -21,7 +21,7 @@ public @interface AnnotationForTest {
|
||||
/**
|
||||
* 注解的默认属性值
|
||||
*
|
||||
* @return
|
||||
* @return 属性值
|
||||
*/
|
||||
String value();
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ public class AnnotationUtilTest {
|
||||
}
|
||||
|
||||
@AnnotationForTest("测试")
|
||||
class ClassWithAnnotation{
|
||||
static class ClassWithAnnotation{
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ public class ClassUtilTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
class TestClass {
|
||||
static class TestClass {
|
||||
private String privateField;
|
||||
protected String field;
|
||||
|
||||
|
Reference in New Issue
Block a user