forked from plusone/plusone-commons
添加 StringTools#isNotBlank
This commit is contained in:
@@ -6,6 +6,7 @@ import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
@@ -47,15 +48,14 @@ class DateTimeToolsTests {
|
||||
void testToJodaDateTime() {
|
||||
ZonedDateTime dt = ZonedDateTime.of(2008, 1, 8, 10, 23, 50, 108000000, ZoneId.systemDefault());
|
||||
Instant instant = DateTimeTools.toInstant(dt.toInstant().toEpochMilli());
|
||||
|
||||
|
||||
org.joda.time.format.DateTimeFormatter f = org.joda.time.format.DateTimeFormat
|
||||
.forPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
|
||||
org.joda.time.DateTime jodaDateTime = DateTimeTools.toJodaDateTime(instant, ZoneId.of("+08:00"));
|
||||
log.info("jodaDateTime: {}", jodaDateTime);
|
||||
assertEquals("2008-01-08 10:23:50.108", f.print(jodaDateTime));
|
||||
|
||||
|
||||
|
||||
jodaDateTime = DateTimeTools.toJodaDateTime(instant, ZoneId.of("+02:00"));
|
||||
log.info("jodaDateTime: {}", jodaDateTime);
|
||||
assertEquals("2008-01-08 04:23:50.108", f.print(jodaDateTime));
|
||||
@@ -65,8 +65,8 @@ class DateTimeToolsTests {
|
||||
void test() {
|
||||
java.time.Instant now = java.time.Instant.now();
|
||||
org.joda.time.DateTime jodaDateTime = DateTimeTools.toJodaDateTime(now, ZoneId.of("America/New_York"));
|
||||
org.joda.time.format.DateTimeFormatter formatter =
|
||||
org.joda.time.format.DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
org.joda.time.format.DateTimeFormatter formatter = org.joda.time.format.DateTimeFormat
|
||||
.forPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
log.info(formatter.print(jodaDateTime));
|
||||
log.info(jodaDateTime.getZone().toString());
|
||||
log.info(jodaDateTime.toString());
|
||||
@@ -74,7 +74,8 @@ class DateTimeToolsTests {
|
||||
org.joda.time.Instant instant = new org.joda.time.Instant(System.currentTimeMillis() - 500000);
|
||||
log.info(instant.toString());
|
||||
log.info(DateTimeTools.toJavaInstant(instant).toString());
|
||||
log.info(DateTimeTools.toZonedDateTime(instant, org.joda.time.DateTimeZone.forID("America/New_York")).toString());
|
||||
log.info(DateTimeTools.toZonedDateTime(instant, org.joda.time.DateTimeZone.forID("America/New_York"))
|
||||
.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,5 +85,10 @@ class DateTimeToolsTests {
|
||||
|
||||
org.joda.time.Instant jodaInstant = DateTimeTools.toJodaInstant(javaInstant);
|
||||
log.info("jodaInstant: {}", jodaInstant);
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
DateTimeFormatter formatter2 = formatter.withZone(ZoneId.systemDefault());
|
||||
log.info("{}", formatter);
|
||||
log.info("{}", formatter2);
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
package xyz.zhouxy.plusone.commons.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
@@ -10,6 +12,7 @@ import org.slf4j.LoggerFactory;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.ToString;
|
||||
|
||||
class TreeBuilderTests {
|
||||
@@ -37,11 +40,15 @@ class TreeBuilderTests {
|
||||
/**//**/MenuItem.of("C1", "C1002", "三级菜单C1002", "/c/c1/c1002", 2),
|
||||
/**/MenuItem.of("C", "C2", "二级菜单C2", "/c/c2", 1));
|
||||
|
||||
List<Menu> menuTreeSortedByOrderNum = treeBuilder.buildTree(menus);
|
||||
List<Menu> clonedMenus;
|
||||
|
||||
clonedMenus = menus.stream().map(m -> ObjectUtil.clone(m)).collect(Collectors.toList());
|
||||
List<Menu> menuTreeSortedByOrderNum = treeBuilder.buildTree(clonedMenus);
|
||||
log.info("menuTreeSortedByOrderNum: {}", new Gson().toJson(menuTreeSortedByOrderNum));
|
||||
|
||||
clonedMenus = menus.stream().map(m -> ObjectUtil.clone(m)).collect(Collectors.toList());
|
||||
List<Menu> menuTreeSortedByMenuCode = treeBuilder.buildTree(
|
||||
menus,
|
||||
clonedMenus,
|
||||
(a, b) -> a.getMenuCode().compareTo(b.getMenuCode())
|
||||
);
|
||||
log.info("menuTreeSortedByMenuCode: {}", new Gson().toJson(menuTreeSortedByMenuCode));
|
||||
@@ -49,7 +56,7 @@ class TreeBuilderTests {
|
||||
}
|
||||
|
||||
@ToString
|
||||
abstract class Menu {
|
||||
abstract class Menu implements Serializable {
|
||||
protected final String parentMenuCode;
|
||||
protected final String menuCode;
|
||||
protected final String title;
|
||||
@@ -77,6 +84,8 @@ abstract class Menu {
|
||||
public int getOrderNum() {
|
||||
return orderNum;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 20240917181424L;
|
||||
}
|
||||
|
||||
@ToString(callSuper = true)
|
||||
@@ -100,6 +109,8 @@ class MenuItem extends Menu {
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 20240917181910L;
|
||||
}
|
||||
|
||||
@ToString(callSuper = true)
|
||||
@@ -135,4 +146,6 @@ class MenuList extends Menu {
|
||||
}
|
||||
this.children.add(child);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 20240917181917L;
|
||||
}
|
||||
|
Reference in New Issue
Block a user