diff --git a/src/main/java/es/uvigo/esei/daa/entities/Pet.java b/src/main/java/es/uvigo/esei/daa/entities/Pet.java index 98b931687e5d0a8c1e3a2c1d8c2530abcf4acec6..e3f73321d87b0587fbbc28e827d925658185b5a8 100644 --- a/src/main/java/es/uvigo/esei/daa/entities/Pet.java +++ b/src/main/java/es/uvigo/esei/daa/entities/Pet.java @@ -1,5 +1,7 @@ package es.uvigo.esei.daa.entities; +import static java.util.Objects.requireNonNull; + /** * Entity that represents a pet from a person * @@ -8,9 +10,70 @@ package es.uvigo.esei.daa.entities; public class Pet { private int id; private String name; + private Person owner; // Constructor needed for the JSON conversion Pet() {} + /** + * Constructs a new instance of {@link Pet}. + * + * @param id identifier of the pet. + * @param name name of the pet. + * @param owner person who owns the pet. + */ + public Pet(int id, String name, Person owner) { + this.id = id; + this.setName(name); + this.setOwner(owner); + } + + /** + * Returns the identifier of the pet. + * + * @return the identifier of the pet. + */ + public int getId() { + return id; + } + + /** + * Returns the name of the pet. + * + * @return the name of the pet. + */ + public String getName() { + return name; + } + + /** + * Set the name of this person. + * + * @param name the new name of the person. + * @throws NullPointerException if the {@code name} is {@code null}. + */ + public void setName(String name) { + this.name = requireNonNull(name, "Name can't be null"); + } + /** + * Returns the owner of the pet. + * + * @return the owner of the pet. + */ + public Person getOwner() { + return owner; + } + + /** + * Set the owner of this pet. + * + * @param owner the owner of the pet. + * @throws NullPointerException if the {@code owner} is {@code null}. + */ + public void setOwner(Person owner) { + this.owner = requireNonNull(owner, "Owner can't be a null reference"); + } + + //TODO -------- ESTABA HACIENDO ESTO MIRAR PRACTICA 2 PARA ENUNCIADO }