mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix null bug
This commit is contained in:
@@ -754,23 +754,26 @@ public class Convert {
|
||||
|
||||
// ----------------------------------------------------------------------- 全角半角转换
|
||||
/**
|
||||
* 半角转全角
|
||||
* 半角转全角,{@code null}返回{@code null}
|
||||
*
|
||||
* @param input String.
|
||||
* @return 全角字符串.
|
||||
* @return 全角字符串,{@code null}返回{@code null}
|
||||
*/
|
||||
public static String toSBC(String input) {
|
||||
return toSBC(input, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 半角转全角
|
||||
* 半角转全角,{@code null}返回{@code null}
|
||||
*
|
||||
* @param input String
|
||||
* @param notConvertSet 不替换的字符集合
|
||||
* @return 全角字符串.
|
||||
* @return 全角字符串,{@code null}返回{@code null}
|
||||
*/
|
||||
public static String toSBC(String input, Set<Character> notConvertSet) {
|
||||
if(StrUtil.isEmpty(input)){
|
||||
return input;
|
||||
}
|
||||
final char[] c = input.toCharArray();
|
||||
for (int i = 0; i < c.length; i++) {
|
||||
if (null != notConvertSet && notConvertSet.contains(c[i])) {
|
||||
@@ -1096,7 +1099,7 @@ public class Convert {
|
||||
/**
|
||||
* long转byte数组<br>
|
||||
* 默认以小端序转换<br>
|
||||
* from: https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-java
|
||||
* from: <a href="https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-java">https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-java</a>
|
||||
*
|
||||
* @param longValue long值
|
||||
* @return byte数组
|
||||
@@ -1109,7 +1112,7 @@ public class Convert {
|
||||
/**
|
||||
* byte数组转long<br>
|
||||
* 默认以小端序转换<br>
|
||||
* from: https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-java
|
||||
* from: <a href="https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-java">https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-java</a>
|
||||
*
|
||||
* @param bytes byte数组
|
||||
* @return long值
|
||||
|
@@ -1338,7 +1338,7 @@ public class DateUtil extends CalendarUtil {
|
||||
return offset(date, DateField.HOUR_OF_DAY, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
/**w
|
||||
* 偏移天
|
||||
*
|
||||
* @param date 日期
|
||||
@@ -2101,19 +2101,6 @@ public class DateUtil extends CalendarUtil {
|
||||
return LocalDateTimeUtil.of(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Date} 转换时区
|
||||
*
|
||||
* @param date {@link Date}
|
||||
* @param zoneId{@link zoneId}
|
||||
* @return {@link DateTime}
|
||||
* @see DateTime(Date,ZoneId)
|
||||
* @since 5.0.5
|
||||
*/
|
||||
public static DateTime convertTimeZone(Date date, String zoneId) {
|
||||
return new DateTime(date, ZoneUtil.toTimeZone(ZoneId.of(zoneId)));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Date} 转换时区
|
||||
*
|
||||
@@ -2121,7 +2108,7 @@ public class DateUtil extends CalendarUtil {
|
||||
* @param zoneId{@link zoneId}
|
||||
* @return {@link DateTime}
|
||||
* @see DateTime(Date, ZoneId )
|
||||
* @since 5.0.5
|
||||
* @since 5.8.3
|
||||
*/
|
||||
public static DateTime convertTimeZone(Date date, ZoneId zoneId) {
|
||||
return new DateTime(date, ZoneUtil.toTimeZone(zoneId));
|
||||
@@ -2134,7 +2121,7 @@ public class DateUtil extends CalendarUtil {
|
||||
* @param timeZone{@link timeZone}
|
||||
* @return {@link DateTime}
|
||||
* @see DateTime(Date,ZoneId)
|
||||
* @since 5.0.5
|
||||
* @since 5.8.3
|
||||
*/
|
||||
public static DateTime convertTimeZone(Date date, TimeZone timeZone) {
|
||||
return new DateTime(date, timeZone);
|
||||
|
@@ -392,4 +392,16 @@ public class ConvertTest {
|
||||
final LocalDate convert = Convert.convert(LocalDate.class, localDateTime);
|
||||
Assert.assertEquals(localDateTime.toLocalDate(), convert);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toSBCTest(){
|
||||
final String s = Convert.toSBC(null);
|
||||
Assert.assertNull(s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toDBCTest(){
|
||||
final String s = Convert.toDBC(null);
|
||||
Assert.assertNull(s);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user