This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new a5f34da273 Add missing equals and hashCode methods in modular Java 
path type (#11118)
a5f34da273 is described below

commit a5f34da273ebc948a8fe0a9056de3b515e82e98e
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Wed Sep 17 10:17:34 2025 +0200

    Add missing equals and hashCode methods in modular Java path type (#11118)
---
 .../main/java/org/apache/maven/api/JavaPathType.java  | 19 +++++++++++++++++++
 .../java/org/apache/maven/api/JavaPathTypeTest.java   | 15 +++++++++++++++
 2 files changed, 34 insertions(+)

diff --git 
a/api/maven-api-core/src/main/java/org/apache/maven/api/JavaPathType.java 
b/api/maven-api-core/src/main/java/org/apache/maven/api/JavaPathType.java
index 63188ec6fd..b2e98ed3c6 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/JavaPathType.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/JavaPathType.java
@@ -376,6 +376,25 @@ public String[] option(Iterable<? extends Path> paths) {
             return format(moduleName, paths);
         }
 
+        /**
+         * {@return a hash code value based on the raw type and module name}.
+         */
+        @Override
+        public int hashCode() {
+            return rawType().hashCode() + 17 * moduleName.hashCode();
+        }
+
+        /**
+         * {@return whether the given object represents the same type of path 
as this object}.
+         */
+        @Override
+        public boolean equals(Object obj) {
+            if (obj instanceof Modular m) {
+                return rawType() == m.rawType() && 
moduleName.equals(m.moduleName);
+            }
+            return false;
+        }
+
         /**
          * Returns the programmatic name of this path type, including the 
module to patch.
          * For example, if this type was created by {@code 
JavaPathType.patchModule("foo.bar")},
diff --git 
a/api/maven-api-core/src/test/java/org/apache/maven/api/JavaPathTypeTest.java 
b/api/maven-api-core/src/test/java/org/apache/maven/api/JavaPathTypeTest.java
index e46ca80a26..701a82775b 100644
--- 
a/api/maven-api-core/src/test/java/org/apache/maven/api/JavaPathTypeTest.java
+++ 
b/api/maven-api-core/src/test/java/org/apache/maven/api/JavaPathTypeTest.java
@@ -25,6 +25,7 @@
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
 
 public class JavaPathTypeTest {
     /**
@@ -65,4 +66,18 @@ public void testModularOption() {
         assertEquals("--patch-module", formatted[0]);
         
assertEquals(toPlatformSpecific("my.module=\"src/foo.java:src/bar.java\""), 
formatted[1]);
     }
+
+    /**
+     * Tests the {@code equals} and {@code hashCode} methods of options.
+     */
+    @Test
+    public void testEqualsHashCode() {
+        JavaPathType.Modular foo1 = JavaPathType.patchModule("foo");
+        JavaPathType.Modular foo2 = JavaPathType.patchModule("foo");
+        JavaPathType.Modular bar = JavaPathType.patchModule("bar");
+        assertEquals(foo1, foo2);
+        assertEquals(foo1.hashCode(), foo2.hashCode());
+        assertNotEquals(foo1, bar);
+        assertNotEquals(foo1.hashCode(), bar.hashCode());
+    }
 }

Reply via email to