forked from plusone/plusone-commons
Compare commits
1 Commits
feature/nu
...
feature/Da
Author | SHA1 | Date | |
---|---|---|---|
0e029e6a18 |
@@ -27,11 +27,11 @@ import java.time.Year;
|
||||
import java.time.YearMonth;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.chrono.IsoChronology;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import com.google.common.collect.BoundType;
|
||||
import com.google.common.collect.Range;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.time.Quarter;
|
||||
@@ -673,6 +673,44 @@ public class DateTimeTools {
|
||||
return Range.closedOpen(date.atStartOfDay(zone), startOfNextDate(date, zone));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定日期范围转为日期时间范围
|
||||
*
|
||||
* @param dateRange 日期范围
|
||||
* @return 对应的日期时间范围
|
||||
*/
|
||||
public static Range<LocalDateTime> toDateTimeRange(Range<LocalDate> dateRange) {
|
||||
BoundType lowerBoundType = dateRange.lowerBoundType();
|
||||
LocalDateTime lowerEndpoint = lowerBoundType == BoundType.CLOSED
|
||||
? dateRange.lowerEndpoint().atStartOfDay()
|
||||
: dateRange.lowerEndpoint().plusDays(1).atStartOfDay();
|
||||
BoundType upperBoundType = dateRange.upperBoundType();
|
||||
LocalDateTime upperEndpoint = upperBoundType == BoundType.CLOSED
|
||||
? dateRange.upperEndpoint().plusDays(1).atStartOfDay()
|
||||
: dateRange.upperEndpoint().atStartOfDay();
|
||||
|
||||
return Range.closedOpen(lowerEndpoint, upperEndpoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定日期范围转为日期时间范围
|
||||
*
|
||||
* @param dateRange 日期范围
|
||||
* @return 对应的日期时间范围
|
||||
*/
|
||||
public static Range<ZonedDateTime> toDateTimeRange(Range<LocalDate> dateRange, ZoneId zone) {
|
||||
BoundType lowerBoundType = dateRange.lowerBoundType();
|
||||
ZonedDateTime lowerEndpoint = lowerBoundType == BoundType.CLOSED
|
||||
? dateRange.lowerEndpoint().atStartOfDay(zone)
|
||||
: dateRange.lowerEndpoint().plusDays(1).atStartOfDay(zone);
|
||||
BoundType upperBoundType = dateRange.upperBoundType();
|
||||
ZonedDateTime upperEndpoint = upperBoundType == BoundType.CLOSED
|
||||
? dateRange.upperEndpoint().plusDays(1).atStartOfDay(zone)
|
||||
: dateRange.upperEndpoint().atStartOfDay(zone);
|
||||
|
||||
return Range.closedOpen(lowerEndpoint, upperEndpoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断指定年份是否为闰年
|
||||
*
|
||||
@@ -680,7 +718,7 @@ public class DateTimeTools {
|
||||
* @return 指定年份是否为闰年
|
||||
*/
|
||||
public static boolean isLeapYear(int year) {
|
||||
return IsoChronology.INSTANCE.isLeapYear(year);
|
||||
return Year.isLeap(year);
|
||||
}
|
||||
|
||||
// ================================
|
||||
|
@@ -29,9 +29,7 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public class Numbers {
|
||||
|
||||
// ================================
|
||||
// #region - sum
|
||||
// ================================
|
||||
|
||||
/**
|
||||
* 求和
|
||||
@@ -133,13 +131,9 @@ public class Numbers {
|
||||
return BigDecimals.sum(numbers);
|
||||
}
|
||||
|
||||
// ================================
|
||||
// #endregion
|
||||
// ================================
|
||||
|
||||
// ================================
|
||||
// #region - nullToZero
|
||||
// ================================
|
||||
|
||||
/**
|
||||
* 将 {@code null} 转换为 {@code 0}
|
||||
@@ -223,122 +217,7 @@ public class Numbers {
|
||||
return BigDecimals.nullToZero(val);
|
||||
}
|
||||
|
||||
// ================================
|
||||
// #endregion - nullToZero
|
||||
// ================================
|
||||
|
||||
// ================================
|
||||
// #region - parse
|
||||
// ================================
|
||||
|
||||
/**
|
||||
* 将字符串转为对应 {@link Short},转换失败时返回 {@code defaultValue}(允许为 {@code null})。
|
||||
*
|
||||
* @param str 要转换的字符串
|
||||
* @param defaultValue 默认值
|
||||
* @return 转换结果
|
||||
*/
|
||||
@Nullable
|
||||
public static Short parseShort(@Nullable String str, @Nullable Short defaultValue) {
|
||||
if (StringTools.isBlank(str)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Short.parseShort(str);
|
||||
}
|
||||
catch (NumberFormatException ignore) {
|
||||
// ignore
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串转为 {@link Integer},转换失败时返回 {@code defaultValue}(允许为 {@code null})。
|
||||
*
|
||||
* @param str 要转换的字符串
|
||||
* @param defaultValue 默认值
|
||||
* @return 转换结果
|
||||
*/
|
||||
@Nullable
|
||||
public static Integer parseInteger(@Nullable String str, @Nullable Integer defaultValue) {
|
||||
if (StringTools.isBlank(str)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(str);
|
||||
}
|
||||
catch (NumberFormatException ignore) {
|
||||
// ignore
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串转为 {@link Long},转换失败时返回 {@code defaultValue}(允许为 {@code null})。
|
||||
*
|
||||
* @param str 要转换的字符串
|
||||
* @param defaultValue 默认值
|
||||
* @return 转换结果
|
||||
*/
|
||||
@Nullable
|
||||
public static Long parseLong(@Nullable String str, @Nullable Long defaultValue) {
|
||||
if (StringTools.isBlank(str)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Long.parseLong(str);
|
||||
}
|
||||
catch (NumberFormatException ignore) {
|
||||
// ignore
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串转为 {@link Float},转换失败时返回 {@code defaultValue}(允许为 {@code null})。
|
||||
*
|
||||
* @param str 要转换的字符串
|
||||
* @param defaultValue 默认值
|
||||
* @return 转换结果
|
||||
*/
|
||||
@Nullable
|
||||
public static Float parseFloat(@Nullable String str, @Nullable Float defaultValue) {
|
||||
if (StringTools.isBlank(str)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Float.parseFloat(str);
|
||||
}
|
||||
catch (NumberFormatException ignore) {
|
||||
// ignore
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串转为 {@link Double},转换失败时返回 {@code defaultValue}(允许为 {@code null})。
|
||||
*
|
||||
* @param str 要转换的字符串
|
||||
* @param defaultValue 默认值
|
||||
* @return 转换结果
|
||||
*/
|
||||
@Nullable
|
||||
public static Double parseDouble(@Nullable String str, @Nullable Double defaultValue) {
|
||||
if (StringTools.isBlank(str)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Double.parseDouble(str);
|
||||
}
|
||||
catch (NumberFormatException ignore) {
|
||||
// ignore
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
// ================================
|
||||
// #endregion - parse
|
||||
// ================================
|
||||
// #endregion
|
||||
|
||||
private Numbers() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
|
@@ -43,6 +43,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.collect.BoundType;
|
||||
import com.google.common.collect.Range;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.time.Quarter;
|
||||
@@ -83,24 +84,6 @@ class DateTimeToolsTests {
|
||||
CALENDAR.setTime(DATE);
|
||||
}
|
||||
|
||||
// Joda
|
||||
static final org.joda.time.LocalDateTime JODA_LOCAL_DATE_TIME
|
||||
= new org.joda.time.LocalDateTime(2024, 12, 29, 12, 58, 30, 333);
|
||||
static final org.joda.time.LocalDate JODA_LOCAL_DATE = JODA_LOCAL_DATE_TIME.toLocalDate();
|
||||
static final org.joda.time.LocalTime JODA_LOCAL_TIME = JODA_LOCAL_DATE_TIME.toLocalTime();
|
||||
|
||||
// Joda - 2024-12-29 12:58:30.333 SystemDefaultZone
|
||||
static final org.joda.time.DateTimeZone JODA_SYS_ZONE = org.joda.time.DateTimeZone.getDefault();
|
||||
static final org.joda.time.DateTime JODA_DATE_TIME_WITH_SYS_ZONE = JODA_LOCAL_DATE_TIME.toDateTime(JODA_SYS_ZONE);
|
||||
static final org.joda.time.Instant JODA_INSTANT_WITH_SYS_ZONE = JODA_DATE_TIME_WITH_SYS_ZONE.toInstant();
|
||||
static final long JODA_INSTANT_MILLIS = JODA_INSTANT_WITH_SYS_ZONE.getMillis();
|
||||
|
||||
// Joda - 2024-12-29 12:58:30.333 GMT+04:00
|
||||
static final org.joda.time.DateTimeZone JODA_ZONE = org.joda.time.DateTimeZone.forID("GMT+04:00");
|
||||
static final org.joda.time.DateTime JODA_DATE_TIME = JODA_LOCAL_DATE_TIME.toDateTime(JODA_ZONE);
|
||||
static final org.joda.time.Instant JODA_INSTANT = JODA_DATE_TIME.toInstant();
|
||||
static final long JODA_MILLIS = JODA_INSTANT.getMillis();
|
||||
|
||||
// ================================
|
||||
// #region - toDate
|
||||
// ================================
|
||||
@@ -109,9 +92,7 @@ class DateTimeToolsTests {
|
||||
void toDate_timeMillis() {
|
||||
assertNotEquals(SYS_DATE, DATE);
|
||||
log.info("SYS_DATE: {}, DATE: {}", SYS_DATE, DATE);
|
||||
assertEquals(SYS_DATE, JODA_DATE_TIME_WITH_SYS_ZONE.toDate());
|
||||
assertEquals(SYS_DATE, DateTimeTools.toDate(INSTANT_MILLIS));
|
||||
assertEquals(DATE, JODA_DATE_TIME.toDate());
|
||||
assertEquals(DATE, DateTimeTools.toDate(MILLIS));
|
||||
}
|
||||
|
||||
@@ -397,7 +378,7 @@ class DateTimeToolsTests {
|
||||
// ================================
|
||||
|
||||
@Test
|
||||
void startDateTimeRange() {
|
||||
void toDateTimeRange_specifiedDate() {
|
||||
Range<LocalDateTime> localDateTimeRange = DateTimeTools.toDateTimeRange(LOCAL_DATE);
|
||||
assertEquals(LOCAL_DATE.atStartOfDay(), localDateTimeRange.lowerEndpoint());
|
||||
assertEquals(LocalDate.of(2024, 12, 30).atStartOfDay(), localDateTimeRange.upperEndpoint());
|
||||
@@ -411,6 +392,94 @@ class DateTimeToolsTests {
|
||||
assertFalse(zonedDateTimeRange.contains(LocalDate.of(2024, 12, 30).atStartOfDay().atZone(SYS_ZONE_ID)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toDateTimeRange_dateRange_openRange() {
|
||||
// (2000-01-01..2025-10-01) -> [2000-01-02T00:00..2025-10-01T00:00)
|
||||
Range<LocalDate> dateRange = Range.open(
|
||||
LocalDate.of(2000, 1, 1),
|
||||
LocalDate.of(2025, 10, 1));
|
||||
|
||||
Range<LocalDateTime> localDateTimeRange = DateTimeTools.toDateTimeRange(dateRange);
|
||||
assertEquals(BoundType.CLOSED, localDateTimeRange.lowerBoundType());
|
||||
assertEquals(LocalDateTime.of(2000, 1, 2, 0, 0), localDateTimeRange.lowerEndpoint());
|
||||
assertEquals(BoundType.OPEN, localDateTimeRange.upperBoundType());
|
||||
assertEquals(LocalDateTime.of(2025, 10, 1, 0, 0), localDateTimeRange.upperEndpoint());
|
||||
log.info(localDateTimeRange.toString());
|
||||
|
||||
Range<ZonedDateTime> zonedDateTimeRange = DateTimeTools.toDateTimeRange(dateRange, ZONE_ID);
|
||||
assertEquals(BoundType.CLOSED, zonedDateTimeRange.lowerBoundType());
|
||||
assertEquals(LocalDateTime.of(2000, 1, 2, 0, 0).atZone(ZONE_ID), zonedDateTimeRange.lowerEndpoint());
|
||||
assertEquals(BoundType.OPEN, zonedDateTimeRange.upperBoundType());
|
||||
assertEquals(LocalDateTime.of(2025, 10, 1, 0, 0).atZone(ZONE_ID), zonedDateTimeRange.upperEndpoint());
|
||||
log.info(zonedDateTimeRange.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toDateTimeRange_dateRange_openClosedRange() {
|
||||
// (2000-01-01..2025-10-01] -> [2025-01-02T00-00..2025-10-02 00:00)
|
||||
Range<LocalDate> dateRange = Range.openClosed(
|
||||
LocalDate.of(2000, 1, 1),
|
||||
LocalDate.of(2025, 10, 1));
|
||||
|
||||
Range<LocalDateTime> localDateTimeRange = DateTimeTools.toDateTimeRange(dateRange);
|
||||
assertEquals(BoundType.CLOSED, localDateTimeRange.lowerBoundType());
|
||||
assertEquals(LocalDateTime.of(2000, 1, 2, 0, 0), localDateTimeRange.lowerEndpoint());
|
||||
assertEquals(BoundType.OPEN, localDateTimeRange.upperBoundType());
|
||||
assertEquals(LocalDateTime.of(2025, 10, 2, 0, 0), localDateTimeRange.upperEndpoint());
|
||||
log.info(localDateTimeRange.toString());
|
||||
|
||||
Range<ZonedDateTime> zonedDateTimeRange = DateTimeTools.toDateTimeRange(dateRange, ZONE_ID);
|
||||
assertEquals(BoundType.CLOSED, zonedDateTimeRange.lowerBoundType());
|
||||
assertEquals(LocalDateTime.of(2000, 1, 2, 0, 0).atZone(ZONE_ID), zonedDateTimeRange.lowerEndpoint());
|
||||
assertEquals(BoundType.OPEN, zonedDateTimeRange.upperBoundType());
|
||||
assertEquals(LocalDateTime.of(2025, 10, 2, 0, 0).atZone(ZONE_ID), zonedDateTimeRange.upperEndpoint());
|
||||
log.info(zonedDateTimeRange.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toDateTimeRange_dateRange_closedRange() {
|
||||
// [2000-01-01..2025-10-01] -> [2025-01-01T00-00..2025-10-02 00:00)
|
||||
Range<LocalDate> dateRange = Range.closed(
|
||||
LocalDate.of(2000, 1, 1),
|
||||
LocalDate.of(2025, 10, 1));
|
||||
|
||||
Range<LocalDateTime> localDateTimeRange = DateTimeTools.toDateTimeRange(dateRange);
|
||||
assertEquals(BoundType.CLOSED, localDateTimeRange.lowerBoundType());
|
||||
assertEquals(LocalDateTime.of(2000, 1, 1, 0, 0), localDateTimeRange.lowerEndpoint());
|
||||
assertEquals(BoundType.OPEN, localDateTimeRange.upperBoundType());
|
||||
assertEquals(LocalDateTime.of(2025, 10, 2, 0, 0), localDateTimeRange.upperEndpoint());
|
||||
log.info(localDateTimeRange.toString());
|
||||
|
||||
Range<ZonedDateTime> zonedDateTimeRange = DateTimeTools.toDateTimeRange(dateRange, ZONE_ID);
|
||||
assertEquals(BoundType.CLOSED, zonedDateTimeRange.lowerBoundType());
|
||||
assertEquals(LocalDateTime.of(2000, 1, 1, 0, 0).atZone(ZONE_ID), zonedDateTimeRange.lowerEndpoint());
|
||||
assertEquals(BoundType.OPEN, zonedDateTimeRange.upperBoundType());
|
||||
assertEquals(LocalDateTime.of(2025, 10, 2, 0, 0).atZone(ZONE_ID), zonedDateTimeRange.upperEndpoint());
|
||||
log.info(zonedDateTimeRange.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toDateTimeRange_dateRange_closedOpenRange() {
|
||||
// [2025-01-01..2025-10-01) -> [2025-01-01T00-00..2025-10-01 00:00)
|
||||
Range<LocalDate> dateRange = Range.closedOpen(
|
||||
LocalDate.of(2000, 1, 1),
|
||||
LocalDate.of(2025, 10, 1));
|
||||
|
||||
Range<LocalDateTime> localDateTimeRange = DateTimeTools.toDateTimeRange(dateRange);
|
||||
assertEquals(BoundType.CLOSED, localDateTimeRange.lowerBoundType());
|
||||
assertEquals(LocalDateTime.of(2000, 1, 1, 0, 0), localDateTimeRange.lowerEndpoint());
|
||||
assertEquals(BoundType.OPEN, localDateTimeRange.upperBoundType());
|
||||
assertEquals(LocalDateTime.of(2025, 10, 1, 0, 0), localDateTimeRange.upperEndpoint());
|
||||
log.info(localDateTimeRange.toString());
|
||||
|
||||
Range<ZonedDateTime> zonedDateTimeRange = DateTimeTools.toDateTimeRange(dateRange, ZONE_ID);
|
||||
assertEquals(BoundType.CLOSED, zonedDateTimeRange.lowerBoundType());
|
||||
assertEquals(LocalDateTime.of(2000, 1, 1, 0, 0).atZone(ZONE_ID), zonedDateTimeRange.lowerEndpoint());
|
||||
assertEquals(BoundType.OPEN, zonedDateTimeRange.upperBoundType());
|
||||
assertEquals(LocalDateTime.of(2025, 10, 1, 0, 0).atZone(ZONE_ID), zonedDateTimeRange.upperEndpoint());
|
||||
log.info(zonedDateTimeRange.toString());
|
||||
}
|
||||
|
||||
// ================================
|
||||
// #endregion - others
|
||||
// ================================
|
||||
|
@@ -26,7 +26,6 @@ import java.util.Arrays;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public
|
||||
@@ -69,16 +68,9 @@ class NumbersTests {
|
||||
|
||||
@Test
|
||||
public void sum_BigIntegerArray_ReturnsCorrectSum() {
|
||||
BigInteger[] numbers = {
|
||||
new BigInteger("1"),
|
||||
new BigInteger("2"),
|
||||
null,
|
||||
new BigInteger("3")
|
||||
};
|
||||
BigInteger[] numbers = {new BigInteger("1"), new BigInteger("2"), new BigInteger("3")};
|
||||
BigInteger result = Numbers.sum(numbers);
|
||||
assertEquals(new BigInteger("6"), result);
|
||||
|
||||
assertEquals(BigInteger.ZERO, Numbers.sum(new BigInteger[0]));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -200,100 +192,6 @@ class NumbersTests {
|
||||
assertEquals(BigDecimal.ZERO, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link Numbers#parseShort(String, Short)}.
|
||||
*/
|
||||
@Test
|
||||
public void parseShort() {
|
||||
assertEquals((short) 12345, Numbers.parseShort("12345", (short) 5));
|
||||
assertEquals((short) 5, Numbers.parseShort("1234.5", (short) 5));
|
||||
assertEquals((short) 5, Numbers.parseShort("", (short) 5));
|
||||
assertEquals((short) 5, Numbers.parseShort(null, (short) 5));
|
||||
|
||||
assertEquals((short) 12345, Numbers.parseShort("12345", null));
|
||||
assertNull(Numbers.parseShort("1234.5", null));
|
||||
assertNull(Numbers.parseShort("", null));
|
||||
assertNull(Numbers.parseShort(null, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link Numbers#parseInteger(String, Integer)}.
|
||||
*/
|
||||
@Test
|
||||
public void parseInteger() {
|
||||
assertEquals(12345, Numbers.parseInteger("12345", 5));
|
||||
assertEquals(5, Numbers.parseInteger("1234.5", 5));
|
||||
assertEquals(5, Numbers.parseInteger("", 5));
|
||||
assertEquals(5, Numbers.parseInteger(null, 5));
|
||||
|
||||
assertEquals(12345, Numbers.parseInteger("12345", null));
|
||||
assertNull(Numbers.parseInteger("1234.5", null));
|
||||
assertNull(Numbers.parseInteger("", null));
|
||||
assertNull(Numbers.parseInteger(null, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link Numbers#parseLong(String, Long)}.
|
||||
*/
|
||||
@Test
|
||||
public void parseLong() {
|
||||
assertEquals(12345L, Numbers.parseLong("12345", 5L));
|
||||
assertEquals(5L, Numbers.parseLong("1234.5", 5L));
|
||||
assertEquals(5L, Numbers.parseLong("", 5L));
|
||||
assertEquals(5L, Numbers.parseLong(null, 5L));
|
||||
|
||||
assertEquals(12345L, Numbers.parseLong("12345", null));
|
||||
assertNull(Numbers.parseLong("1234.5", null));
|
||||
assertNull(Numbers.parseLong("", null));
|
||||
assertNull(Numbers.parseLong(null, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link Numbers#parseFloat(String, Float)}.
|
||||
*/
|
||||
@Test
|
||||
public void parseFloat() {
|
||||
assertEquals(1.2345f, Numbers.parseFloat("1.2345", 5.1f));
|
||||
assertEquals(5.0f, Numbers.parseFloat("a", 5.0f));
|
||||
assertEquals(5.0f, Numbers.parseFloat("-001Z.2345", 5.0f));
|
||||
assertEquals(5.0f, Numbers.parseFloat("+001AB.2345", 5.0f));
|
||||
assertEquals(5.0f, Numbers.parseFloat("001Z.2345", 5.0f));
|
||||
assertEquals(5.0f, Numbers.parseFloat("", 5.0f));
|
||||
assertEquals(5.0f, Numbers.parseFloat(null, 5.0f));
|
||||
|
||||
assertEquals(1.2345f, Numbers.parseFloat("1.2345", null));
|
||||
assertNull(Numbers.parseFloat("a", null));
|
||||
assertNull(Numbers.parseFloat("-001Z.2345", null));
|
||||
assertNull(Numbers.parseFloat("+001AB.2345", null));
|
||||
assertNull(Numbers.parseFloat("001Z.2345", null));
|
||||
assertNull(Numbers.parseFloat("", null));
|
||||
assertNull(Numbers.parseFloat(null, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link Numbers#parseDouble(String, Double)}.
|
||||
*/
|
||||
@Test
|
||||
public void parseDouble() {
|
||||
assertEquals(1.2345d, Numbers.parseDouble("1.2345", 5.1d));
|
||||
assertEquals(5.0d, Numbers.parseDouble("a", 5.0d));
|
||||
assertEquals(1.2345d, Numbers.parseDouble("001.2345", 5.1d));
|
||||
assertEquals(-1.2345d, Numbers.parseDouble("-001.2345", 5.1d));
|
||||
assertEquals(1.2345d, Numbers.parseDouble("+001.2345", 5.1d));
|
||||
assertEquals(0d, Numbers.parseDouble("000.00", 5.1d));
|
||||
assertEquals(5.1d, Numbers.parseDouble("", 5.1d));
|
||||
assertEquals(5.1d, Numbers.parseDouble((String) null, 5.1d));
|
||||
|
||||
assertEquals(1.2345d, Numbers.parseDouble("1.2345", null));
|
||||
assertEquals(null, Numbers.parseDouble("a", null));
|
||||
assertEquals(1.2345d, Numbers.parseDouble("001.2345", null));
|
||||
assertEquals(-1.2345d, Numbers.parseDouble("-001.2345", null));
|
||||
assertEquals(1.2345d, Numbers.parseDouble("+001.2345", null));
|
||||
assertEquals(0d, Numbers.parseDouble("000.00", null));
|
||||
assertEquals(null, Numbers.parseDouble("", null));
|
||||
assertEquals(null, Numbers.parseDouble((String) null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_constructor_isNotAccessible_ThrowsIllegalStateException() {
|
||||
Constructor<?>[] constructors = Numbers.class.getDeclaredConstructors();
|
||||
|
Reference in New Issue
Block a user