From 9058be6a35a3fee3c2db933b21f1e4d68247034b Mon Sep 17 00:00:00 2001 From: filippo-ferrari Date: Sat, 22 Jun 2024 15:38:30 +0200 Subject: [PATCH] feat: Person equals & hashcode --- .../com/application/munera/data/Person.java | 22 ++++++++++++++++++- .../munera/services/PersonService.java | 4 ++-- .../munera/views/expenses/PeopleView.java | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/application/munera/data/Person.java b/src/main/java/com/application/munera/data/Person.java index 8cbb7e3..b1dc56c 100644 --- a/src/main/java/com/application/munera/data/Person.java +++ b/src/main/java/com/application/munera/data/Person.java @@ -7,6 +7,7 @@ import lombok.Getter; import lombok.Setter; import java.math.BigDecimal; +import java.util.Objects; import java.util.Set; @Entity @@ -47,4 +48,23 @@ public class Person { @ManyToMany(mappedBy = "participants") private Set events; -} + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof Person)) { + return false; + } + Person other = (Person) obj; + return Objects.equals(firstName, other.firstName) && + Objects.equals(lastName, other.lastName) && + Objects.equals(email, other.email); + } + + @Override + public int hashCode() { + return Objects.hash(firstName, lastName, email); + } +} \ No newline at end of file diff --git a/src/main/java/com/application/munera/services/PersonService.java b/src/main/java/com/application/munera/services/PersonService.java index b96f28b..eff44fc 100644 --- a/src/main/java/com/application/munera/services/PersonService.java +++ b/src/main/java/com/application/munera/services/PersonService.java @@ -9,7 +9,7 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import java.math.BigDecimal; -import java.util.List; +import java.util.Collection; import java.util.Optional; @Service @@ -27,7 +27,7 @@ public class PersonService { return personRepository.findById(id); } - public List findAll() { + public Collection findAll() { return this.personRepository.findAll(); } diff --git a/src/main/java/com/application/munera/views/expenses/PeopleView.java b/src/main/java/com/application/munera/views/expenses/PeopleView.java index aabfa4e..d232a98 100644 --- a/src/main/java/com/application/munera/views/expenses/PeopleView.java +++ b/src/main/java/com/application/munera/views/expenses/PeopleView.java @@ -226,7 +226,7 @@ public class PeopleView extends Div implements BeforeEnterObserver { badge.setText("Debit"); badge.getElement().getThemeList().add("badge error"); } else { - badge.setText("Nothing"); + badge.setText("Clear"); badge.getElement().getThemeList().add("badge contrast"); } return badge;