Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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());
}
}
Loading