File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
main/java/org/apache/maven/api
test/java/org/apache/maven/api Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -376,6 +376,25 @@ public String[] option(Iterable<? extends Path> paths) {
376
376
return format (moduleName , paths );
377
377
}
378
378
379
+ /**
380
+ * {@return a hash code value based on the raw type and module name}.
381
+ */
382
+ @ Override
383
+ public int hashCode () {
384
+ return rawType ().hashCode () + 17 * moduleName .hashCode ();
385
+ }
386
+
387
+ /**
388
+ * {@return whether the given object represents the same type of path as this object}.
389
+ */
390
+ @ Override
391
+ public boolean equals (Object obj ) {
392
+ if (obj instanceof Modular m ) {
393
+ return rawType () == m .rawType () && moduleName .equals (m .moduleName );
394
+ }
395
+ return false ;
396
+ }
397
+
379
398
/**
380
399
* Returns the programmatic name of this path type, including the module to patch.
381
400
* For example, if this type was created by {@code JavaPathType.patchModule("foo.bar")},
Original file line number Diff line number Diff line change 25
25
import org .junit .jupiter .api .Test ;
26
26
27
27
import static org .junit .jupiter .api .Assertions .assertEquals ;
28
+ import static org .junit .jupiter .api .Assertions .assertNotEquals ;
28
29
29
30
public class JavaPathTypeTest {
30
31
/**
@@ -65,4 +66,18 @@ public void testModularOption() {
65
66
assertEquals ("--patch-module" , formatted [0 ]);
66
67
assertEquals (toPlatformSpecific ("my.module=\" src/foo.java:src/bar.java\" " ), formatted [1 ]);
67
68
}
69
+
70
+ /**
71
+ * Tests the {@code equals} and {@code hashCode} methods of options.
72
+ */
73
+ @ Test
74
+ public void testEqualsHashCode () {
75
+ JavaPathType .Modular foo1 = JavaPathType .patchModule ("foo" );
76
+ JavaPathType .Modular foo2 = JavaPathType .patchModule ("foo" );
77
+ JavaPathType .Modular bar = JavaPathType .patchModule ("bar" );
78
+ assertEquals (foo1 , foo2 );
79
+ assertEquals (foo1 .hashCode (), foo2 .hashCode ());
80
+ assertNotEquals (foo1 , bar );
81
+ assertNotEquals (foo1 .hashCode (), bar .hashCode ());
82
+ }
68
83
}
You can’t perform that action at this time.
0 commit comments