mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
fix code
This commit is contained in:
parent
147cc683a5
commit
42fbf36042
@ -87,4 +87,4 @@ public final class FastStringWriter extends Writer {
|
||||
return this.builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -110,6 +110,21 @@ public class Opt<T> {
|
||||
return CollectionUtil.isEmpty(value) ? empty() : new Opt<>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行一系列操作,如果途中发生 {@code NPE} 和 {@code IndexOutOfBoundsException},返回一个空的{@code Opt}
|
||||
*
|
||||
* @param supplier 操作
|
||||
* @param <T> 类型
|
||||
* @return 操作执行后的值
|
||||
*/
|
||||
public static <T> Opt<T> exec(Supplier<T> supplier) {
|
||||
try {
|
||||
return Opt.ofNullable(supplier.get());
|
||||
} catch (NullPointerException | IndexOutOfBoundsException e) {
|
||||
return empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 包裹里实际的元素
|
||||
*/
|
||||
@ -411,10 +426,7 @@ public class Opt<T> {
|
||||
* @throws NoSuchElementException 如果包裹里的值不存在则抛出该异常
|
||||
*/
|
||||
public T orElseThrow() {
|
||||
if (value == null) {
|
||||
throw new NoSuchElementException("No value present");
|
||||
}
|
||||
return value;
|
||||
return orElseThrow(NoSuchElementException::new, "No value present");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -469,22 +481,6 @@ public class Opt<T> {
|
||||
return Optional.ofNullable(this.value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 执行一系列操作,如果途中发生 {@code NPE} 和 {@code IndexOutOfBoundsException},返回一个空的{@code Opt}
|
||||
*
|
||||
* @param supplier 操作
|
||||
* @param <T> 类型
|
||||
* @return 操作执行后的值
|
||||
*/
|
||||
public static <T> Opt<T> exec(Supplier<T> supplier) {
|
||||
try {
|
||||
return Opt.ofNullable(supplier.get());
|
||||
} catch (NullPointerException | IndexOutOfBoundsException e) {
|
||||
return empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断传入参数是否与 {@code Opt}相等
|
||||
* 在以下情况下返回true
|
||||
|
@ -2471,21 +2471,22 @@ public class CharSequenceUtil {
|
||||
*
|
||||
* @param str 被重复的字符串
|
||||
* @param count 数量
|
||||
* @param conjunction 分界符
|
||||
* @param delimiter 分界符
|
||||
* @return 连接后的字符串
|
||||
* @since 4.0.1
|
||||
*/
|
||||
public static String repeatAndJoin(CharSequence str, int count, CharSequence conjunction) {
|
||||
public static String repeatAndJoin(CharSequence str, int count, CharSequence delimiter) {
|
||||
if (count <= 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
final StrBuilder builder = StrBuilder.create();
|
||||
boolean isFirst = true;
|
||||
final StringBuilder builder = new StringBuilder(str.length() * count);
|
||||
builder.append(str);
|
||||
count--;
|
||||
|
||||
final boolean isAppendDelimiter = isNotEmpty(delimiter);
|
||||
while (count-- > 0) {
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
} else if (isNotEmpty(conjunction)) {
|
||||
builder.append(conjunction);
|
||||
if (isAppendDelimiter) {
|
||||
builder.append(delimiter);
|
||||
}
|
||||
builder.append(str);
|
||||
}
|
||||
@ -3521,7 +3522,7 @@ public class CharSequenceUtil {
|
||||
fromIndex = 0;
|
||||
}
|
||||
|
||||
final StrBuilder result = StrBuilder.create(strLength + 16);
|
||||
final StringBuilder result = new StringBuilder(strLength - searchStrLength + replacement.length());
|
||||
if (0 != fromIndex) {
|
||||
result.append(str.subSequence(0, fromIndex));
|
||||
}
|
||||
@ -4285,7 +4286,7 @@ public class CharSequenceUtil {
|
||||
// 循环位移,当越界时循环
|
||||
moveLength = moveLength % len;
|
||||
}
|
||||
final StrBuilder strBuilder = StrBuilder.create(len);
|
||||
final StringBuilder strBuilder = new StringBuilder(len);
|
||||
if (moveLength > 0) {
|
||||
int endAfterMove = Math.min(endExclude + moveLength, str.length());
|
||||
strBuilder.append(str.subSequence(0, startInclude))//
|
||||
|
@ -191,11 +191,10 @@ public class StrJoiner implements Appendable, Serializable {
|
||||
/**
|
||||
* 追加对象到拼接器中
|
||||
*
|
||||
* @param <T> 元素类型
|
||||
* @param obj 对象,支持数组、集合等
|
||||
* @return this
|
||||
*/
|
||||
public <T> StrJoiner append(Object obj) {
|
||||
public StrJoiner append(Object obj) {
|
||||
if (null == obj) {
|
||||
append((CharSequence) null);
|
||||
} else if (ArrayUtil.isArray(obj)) {
|
||||
|
@ -25,7 +25,7 @@ public class UnicodeUtil {
|
||||
}
|
||||
|
||||
final int len = unicode.length();
|
||||
StrBuilder sb = StrBuilder.create(len);
|
||||
StringBuilder sb = new StringBuilder(len);
|
||||
int i;
|
||||
int pos = 0;
|
||||
while ((i = StrUtil.indexOfIgnoreCase(unicode, "\\u", pos)) != -1) {
|
||||
@ -101,7 +101,7 @@ public class UnicodeUtil {
|
||||
}
|
||||
|
||||
final int len = str.length();
|
||||
final StrBuilder unicode = StrBuilder.create(str.length() * 6);
|
||||
final StringBuilder unicode = new StringBuilder(str.length() * 6);
|
||||
char c;
|
||||
for (int i = 0; i < len; i++) {
|
||||
c = str.charAt(i);
|
||||
|
@ -177,7 +177,7 @@ public class StrUtil extends CharSequenceUtil implements StrPool {
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String str(byte[] bytes, String charset) {
|
||||
return str(bytes, isBlank(charset) ? Charset.defaultCharset() : Charset.forName(charset));
|
||||
return str(bytes, CharsetUtil.charset(charset));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -206,7 +206,7 @@ public class StrUtil extends CharSequenceUtil implements StrPool {
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String str(Byte[] bytes, String charset) {
|
||||
return str(bytes, isBlank(charset) ? Charset.defaultCharset() : Charset.forName(charset));
|
||||
return str(bytes, CharsetUtil.charset(charset));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -243,7 +243,7 @@ public class StrUtil extends CharSequenceUtil implements StrPool {
|
||||
return null;
|
||||
}
|
||||
|
||||
return str(data, Charset.forName(charset));
|
||||
return str(data, CharsetUtil.charset(charset));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user