add method

This commit is contained in:
Looly
2021-10-14 09:56:04 +08:00
parent d204d58057
commit b5036b4b0b
4 changed files with 29 additions and 12 deletions

View File

@@ -840,12 +840,12 @@ public class Assert {
/**
* 检查值是否在指定范围内
*
* @param value 值
* @param min 最小值(包含)
* @param max 最大值(包含)
* @param value
* @param min 最小值(包含)
* @param max 最大值(包含)
* @param errorSupplier 错误抛出异常附带的消息生产接口
* @throws X if value is out of bound
* @return 经过检查后的值
* @throws X if value is out of bound
* @since 5.7.15
*/
public static <X extends Throwable> int checkBetween(int value, int min, int max, Supplier<? extends X> errorSupplier) throws X {
@@ -885,12 +885,12 @@ public class Assert {
/**
* 检查值是否在指定范围内
*
* @param value 值
* @param min 最小值(包含)
* @param max 最大值(包含)
* @param value
* @param min 最小值(包含)
* @param max 最大值(包含)
* @param errorSupplier 错误抛出异常附带的消息生产接口
* @throws X if value is out of bound
* @return 经过检查后的值
* @throws X if value is out of bound
* @since 5.7.15
*/
public static <X extends Throwable> long checkBetween(long value, long min, long max, Supplier<? extends X> errorSupplier) throws X {
@@ -930,12 +930,12 @@ public class Assert {
/**
* 检查值是否在指定范围内
*
* @param value 值
* @param min 最小值(包含)
* @param max 最大值(包含)
* @param value
* @param min 最小值(包含)
* @param max 最大值(包含)
* @param errorSupplier 错误抛出异常附带的消息生产接口
* @throws X if value is out of bound
* @return 经过检查后的值
* @throws X if value is out of bound
* @since 5.7.15
*/
public static <X extends Throwable> double checkBetween(double value, double min, double max, Supplier<? extends X> errorSupplier) throws X {

View File

@@ -163,6 +163,16 @@ public class RandomUtil {
return 0 == randomInt(2);
}
/**
* 随机汉字('\u4E00'-'\u9FFF'
*
* @return 随机的汉字字符
* @since 5.7.15
*/
public static char randomChinese() {
return (char) randomInt('\u4E00', '\u9FFF');
}
/**
* 获得指定范围内的随机数
*

View File

@@ -53,4 +53,10 @@ public class RandomUtilTest {
final byte[] c = RandomUtil.randomBytes(10);
Assert.assertNotNull(c);
}
@Test
public void randomChineseTest(){
char c = RandomUtil.randomChinese();
Assert.assertTrue(c > 0);
}
}