src/main/java/de/uapcore/lightpit/MenuEntry.java

changeset 36
0f4f8f255c32
parent 34
824d4042c857
child 45
cc7f082c5ef3
--- a/src/main/java/de/uapcore/lightpit/MenuEntry.java	Sun May 10 10:11:10 2020 +0200
+++ b/src/main/java/de/uapcore/lightpit/MenuEntry.java	Sun May 10 10:11:37 2020 +0200
@@ -28,6 +28,8 @@
  */
 package de.uapcore.lightpit;
 
+import java.util.Objects;
+
 /**
  * Maps a resource key for the menu label to the path name for the underlying
  * site.
@@ -35,40 +37,67 @@
  * Objects of this class are internally instantiated by the
  * {@link ModuleManager}.
  */
-public class MenuEntry {
+public class MenuEntry implements Comparable<MenuEntry> {
+
+    /**
+     * Class name of the module for which this menu is built.
+     */
+    private final String moduleClassName;
 
     /**
      * Resource key for the menu label.
      */
-    private ResourceKey resourceKey;
+    private final ResourceKey resourceKey;
 
     /**
      * Path name of the module, linked by this menu entry.
      */
-    private String pathName;
+    private final String pathName;
 
-    public MenuEntry() {
+    /**
+     * Sequence number to determine the ordering of the menu.
+     */
+    private final int sequence;
+
+    public MenuEntry(String moduleClassName, ResourceKey resourceKey, String pathName, int sequence) {
+        this.moduleClassName = moduleClassName;
+        this.resourceKey = resourceKey;
+        this.pathName = pathName;
+        this.sequence = sequence;
     }
 
-    public MenuEntry(ResourceKey resourceKey, String pathName) {
-        this.resourceKey = resourceKey;
-        this.pathName = pathName;
-    }
-
-    public void setResourceKey(ResourceKey resourceKey) {
-        this.resourceKey = resourceKey;
+    public String getModuleClassName() {
+        return moduleClassName;
     }
 
     public ResourceKey getResourceKey() {
         return resourceKey;
     }
 
-    public void setPathName(String pathName) {
-        this.pathName = pathName;
-    }
-
     public String getPathName() {
         return pathName;
     }
 
+    public int getSequence() {
+        return sequence;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        MenuEntry menuEntry = (MenuEntry) o;
+        return resourceKey.equals(menuEntry.resourceKey) &&
+                pathName.equals(menuEntry.pathName);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(resourceKey, pathName);
+    }
+
+    @Override
+    public int compareTo(MenuEntry menuEntry) {
+        return Integer.compare(this.sequence, menuEntry.sequence);
+    }
 }

mercurial