diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/result/MenuViewObject.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/result/MenuViewObject.java index 1870391..c2fdd6d 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/result/MenuViewObject.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/result/MenuViewObject.java @@ -2,9 +2,10 @@ package xyz.zhouxy.plusone.system.application.query.result; import java.util.ArrayList; import java.util.Collection; -import java.util.Comparator; +import java.util.Collections; import java.util.List; -import java.util.Objects; +import java.util.SortedSet; +import java.util.TreeSet; import com.fasterxml.jackson.annotation.JsonInclude; @@ -81,18 +82,18 @@ public class MenuViewObject implements IWithOrderNumber { List actions; // MENU_LIST - List children; + SortedSet children; public void addChild(MenuViewObject child) { if (this.children == null) { - this.children = new ArrayList<>(); + this.children = new TreeSet<>(); } this.children.add(child); } public void addChildren(Collection children) { if (this.children == null) { - this.children = new ArrayList<>(); + this.children = new TreeSet<>(); } this.children.addAll(children); } @@ -121,11 +122,33 @@ public class MenuViewObject implements IWithOrderNumber { } public List getChildren() { - return Objects.nonNull(this.children) - ? this.children - .stream() - .sorted(Comparator.comparing(IWithOrderNumber::getOrderNumber)) - .toList() - : null; + return this.children == null || this.children.isEmpty() + ? Collections.emptyList() + : new ArrayList<>(this.children); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MenuViewObject other = (MenuViewObject) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; } }