This commit is contained in:
2023-08-31 09:57:42 +08:00
parent 09d6b26394
commit ce7bf55d23

View File

@@ -57,16 +57,10 @@ public class ResourceEntity extends CommonEntity {
private Boolean visible;
@Comment("其他数据")
private String metadata;
public void addChildren(ResourceEntity newRs) {
// log.info("addChildren1 {} {}", this.getUrl(), newRs.getUrl());
@@ -81,7 +75,7 @@ public class ResourceEntity extends CommonEntity {
for (ResourceEntity child : this.children) {
if (newRs.getUrl().startsWith(child.getUrl())) {
if (isChildren(newRs, child)) {
child.addChildren(newRs);
@@ -119,11 +113,39 @@ public class ResourceEntity extends CommonEntity {
}
private boolean isChildren(ResourceEntity c, ResourceEntity p) {
if (!isSamePath(c.getUrl(), p.getUrl())) {
// 判断list是否有相同前缀
String[] pl = StringUtils.split(p.getUrl(), "/");
String[] cl = StringUtils.split(c.getUrl(), "/");
for (int i = 0; i < pl.length; i++) {
if (i >= cl.length) {
return false;
}
if (!pl[i].equalsIgnoreCase(cl[i])) {
return false;
}
}
return true;
}
return false;
}
private boolean isSamePath(String a, String b) {
return a.equalsIgnoreCase(b) || (a + "/").equalsIgnoreCase(b);
}
private static String getParent(String path) {
log.info("getParent {}", path);
return "/" + StringUtils.join(Stream.of(StringUtils.split(path, "/")).dropRight(1), "/");
}