Skip to content

Commit

Permalink
refactor: override equals & hashCode methods in User entity
Browse files Browse the repository at this point in the history
  • Loading branch information
thisdudkin committed Oct 5, 2024
1 parent d143568 commit bd6fa05
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import static dev.earlspilner.users.model.UserRole.ROLE_VISITOR;

Expand Down Expand Up @@ -79,6 +80,26 @@ public User(Integer id, String name, String username, String email,
this.roles = roles;
}

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof User user)) return false;

return name.equals(user.name) && username.equals(user.username) && email.equals(user.email) && password.equals(user.password) && createdUtc.equals(user.createdUtc) && Objects.equals(updatedUtc, user.updatedUtc) && roles.equals(user.roles);
}

@Override
public int hashCode() {
int result = name.hashCode();
result = 31 * result + username.hashCode();
result = 31 * result + email.hashCode();
result = 31 * result + password.hashCode();
result = 31 * result + createdUtc.hashCode();
result = 31 * result + Objects.hashCode(updatedUtc);
result = 31 * result + roles.hashCode();
return result;
}

@Override
public String toString() {
return "User{" +
Expand Down

0 comments on commit bd6fa05

Please sign in to comment.