mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-09 23:28:01 +08:00
add method
This commit is contained in:
parent
d6784ca99e
commit
46fafeeb86
@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# 5.4.4 (2020-09-19)
|
# 5.4.4 (2020-09-22)
|
||||||
|
|
||||||
### 新特性
|
### 新特性
|
||||||
* 【core 】 ServiceLoaderUtil改为使用contextClassLoader(pr#183@Gitee)
|
* 【core 】 ServiceLoaderUtil改为使用contextClassLoader(pr#183@Gitee)
|
||||||
|
* 【core 】 NetUtil增加getLocalHostName(pr#1103@Github)
|
||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
|
|
||||||
|
@ -1383,30 +1383,6 @@ public class DateUtil extends CalendarUtil {
|
|||||||
return new DateBetween(beginDate, endDate).betweenMonth(isReset);
|
return new DateBetween(beginDate, endDate).betweenMonth(isReset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取两个日期之间所有的月份
|
|
||||||
* @param start 开始时间
|
|
||||||
* @param end 结束时间
|
|
||||||
* @return List<String> 格式为yyyMM格式的月份列表 包含收尾</>
|
|
||||||
* @since 5.4.4
|
|
||||||
*/
|
|
||||||
public static List<String> getBetweenMonths(Date start, Date end) {
|
|
||||||
List<String> result = new ArrayList<>();
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
|
|
||||||
Calendar tempStart = Calendar.getInstance();
|
|
||||||
tempStart.setTime(start);
|
|
||||||
// 加一个月,保证开始和结束同步时返回当月
|
|
||||||
tempStart.add(Calendar.MONTH, 1);
|
|
||||||
Calendar tempEnd = Calendar.getInstance();
|
|
||||||
tempEnd.setTime(end);
|
|
||||||
result.add(sdf.format(start));
|
|
||||||
while (tempStart.before(tempEnd) || tempStart.equals(tempEnd)) {
|
|
||||||
result.add(sdf.format(tempStart.getTime()));
|
|
||||||
tempStart.add(Calendar.MONTH, 1);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算两个日期相差年数<br>
|
* 计算两个日期相差年数<br>
|
||||||
* 在非重置情况下,如果起始日期的月小于结束日期的月,年数要少算1(不足1年)
|
* 在非重置情况下,如果起始日期的月小于结束日期的月,年数要少算1(不足1年)
|
||||||
|
@ -42,7 +42,8 @@ import java.util.TreeSet;
|
|||||||
public class NetUtil {
|
public class NetUtil {
|
||||||
|
|
||||||
public final static String LOCAL_IP = "127.0.0.1";
|
public final static String LOCAL_IP = "127.0.0.1";
|
||||||
public static String LOCAL_HOSTNAME = "";
|
|
||||||
|
public static String localhostName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认最小端口,1024
|
* 默认最小端口,1024
|
||||||
@ -535,20 +536,26 @@ public class NetUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取主机名称
|
* 获取主机名称,一次获取会缓存名称
|
||||||
|
*
|
||||||
* @return 主机名称
|
* @return 主机名称
|
||||||
* @since 5.4.4
|
* @since 5.4.4
|
||||||
*/
|
*/
|
||||||
public static String getLocalHostName() {
|
public static String getLocalHostName() {
|
||||||
try {
|
if (StrUtil.isNotBlank(localhostName)) {
|
||||||
if (StrUtil.isNotBlank(LOCAL_HOSTNAME)) {
|
return localhostName;
|
||||||
return LOCAL_HOSTNAME;
|
|
||||||
}
|
|
||||||
LOCAL_HOSTNAME = InetAddress.getLocalHost().getHostName();
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
LOCAL_HOSTNAME = getLocalhostStr();
|
|
||||||
}
|
}
|
||||||
return LOCAL_HOSTNAME;
|
|
||||||
|
final InetAddress localhost = getLocalhost();
|
||||||
|
if(null != localhost){
|
||||||
|
String name = localhost.getHostName();
|
||||||
|
if(StrUtil.isEmpty(name)){
|
||||||
|
name = localhost.getHostAddress();
|
||||||
|
}
|
||||||
|
localhostName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return localhostName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,7 +3,6 @@ package cn.hutool.core.date;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.date.BetweenFormater.Level;
|
import cn.hutool.core.date.BetweenFormater.Level;
|
||||||
import cn.hutool.core.date.format.FastDateFormat;
|
import cn.hutool.core.date.format.FastDateFormat;
|
||||||
import cn.hutool.core.lang.Console;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -820,12 +819,4 @@ public class DateUtilTest {
|
|||||||
final DateTime parse = DateUtil.parse(dt);
|
final DateTime parse = DateUtil.parse(dt);
|
||||||
Assert.assertEquals("2020-06-03 12:32:12", parse.toString());
|
Assert.assertEquals("2020-06-03 12:32:12", parse.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getBetweenMonthsTest() {
|
|
||||||
List<String> months1 = DateUtil.getBetweenMonths(new Date(), new Date());
|
|
||||||
Assert.assertEquals(1, months1.size());
|
|
||||||
List<String> months = DateUtil.getBetweenMonths(DateUtil.parse("2020-05-08 3:12:3"), new Date());
|
|
||||||
Assert.assertEquals(5, months.size());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -229,4 +229,18 @@ public class SM2Test {
|
|||||||
Assert.assertEquals(data, decryptStr);
|
Assert.assertEquals(data, decryptStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void encryptAndSignTest(){
|
||||||
|
SM2 sm2 = SmUtil.sm2();
|
||||||
|
|
||||||
|
String src = "Sm2Test";
|
||||||
|
byte[] data = sm2.encrypt(src, KeyType.PublicKey);
|
||||||
|
byte[] sign = sm2.sign(src.getBytes());
|
||||||
|
|
||||||
|
Assert.assertTrue(sm2.verify( src.getBytes(), sign));
|
||||||
|
|
||||||
|
byte[] dec = sm2.decrypt(data, KeyType.PrivateKey);
|
||||||
|
Assert.assertArrayEquals(dec, src.getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,18 @@ public class Setting extends AbsSetting implements Map<String, String> {
|
|||||||
Assert.notNull(url, "Null setting url define!");
|
Assert.notNull(url, "Null setting url define!");
|
||||||
this.init(new UrlResource(url), charset, isUseVariable);
|
this.init(new UrlResource(url), charset, isUseVariable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param resource Setting的Resource
|
||||||
|
* @param charset 字符集
|
||||||
|
* @param isUseVariable 是否使用变量
|
||||||
|
* @since 5.4.4
|
||||||
|
*/
|
||||||
|
public Setting(Resource resource, Charset charset, boolean isUseVariable) {
|
||||||
|
this.init(resource, charset, isUseVariable);
|
||||||
|
}
|
||||||
// ------------------------------------------------------------------------------------- Constructor end
|
// ------------------------------------------------------------------------------------- Constructor end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -176,7 +188,7 @@ public class Setting extends AbsSetting implements Map<String, String> {
|
|||||||
*/
|
*/
|
||||||
public boolean init(Resource resource, Charset charset, boolean isUseVariable) {
|
public boolean init(Resource resource, Charset charset, boolean isUseVariable) {
|
||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
throw new NullPointerException("Null setting url define!");
|
throw new NullPointerException("Null setting resource define!");
|
||||||
}
|
}
|
||||||
this.settingUrl = resource.getUrl();
|
this.settingUrl = resource.getUrl();
|
||||||
this.charset = charset;
|
this.charset = charset;
|
||||||
@ -319,10 +331,10 @@ public class Setting extends AbsSetting implements Map<String, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取group分组下所有配置键值对,组成新的{@link Setting}
|
* 获取group分组下所有配置键值对,组成新的Setting
|
||||||
*
|
*
|
||||||
* @param group 分组
|
* @param group 分组
|
||||||
* @return {@link Setting}
|
* @return Setting
|
||||||
*/
|
*/
|
||||||
public Setting getSetting(String group) {
|
public Setting getSetting(String group) {
|
||||||
final Setting setting = new Setting();
|
final Setting setting = new Setting();
|
||||||
|
Loading…
Reference in New Issue
Block a user