[POO] equals and hashcode added to aula06.ex1.Person.java
This commit is contained in:
parent
54085d5295
commit
aceef79d56
|
@ -2,6 +2,8 @@ package aula06.ex1;
|
|||
|
||||
import utils.DateYMD;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Person {
|
||||
private String name;
|
||||
private int cc;
|
||||
|
@ -44,4 +46,17 @@ public class Person {
|
|||
public String toString() {
|
||||
return String.format("%s; CC: %d; Data de nascimento: %s", this.name, this.cc, this.birthDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Person person = (Person) o;
|
||||
return cc == person.cc && Objects.equals(name, person.name) && Objects.equals(birthDate, person.birthDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, cc, birthDate);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue