Skip to content

Fix equals and hash code variable #1586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -6,16 +6,20 @@
* A {@link VariableId} is an entity/variable of a given solution.
* {@link VariableId} cannot be compared across different solution instances,
* since variableDescriptor and entity are compared by reference equality.
*
* <p>
* Note: The entity is compared using {@link Object#equals(Object)} and {@link Object#hashCode()},
* so it's important that the planning entity class properly overrides both methods,
* typically based on a unique identifier (e.g. a UId).
* <p>
* @param variableDescriptor The variable this {@link VariableId} refers to.
* @param entity The entity this {@link VariableId} refers to.
*/
public record VariableId<Solution_>(VariableDescriptor<Solution_> variableDescriptor, Object entity) {
@Override
public boolean equals(Object other) {
if (other instanceof VariableId<?> variableId) {
return variableDescriptor == variableId.variableDescriptor &&
entity == variableId.entity;
return variableDescriptor.equals(variableId.variableDescriptor) &&
entity.equals(variableId.entity);
}
return false;
}
Expand Down
Loading