From 0c0cad9f14ff352237214aa0257d096b320b32ac Mon Sep 17 00:00:00 2001 From: cyanide4all Date: Sun, 12 Feb 2017 23:28:21 +0100 Subject: [PATCH] added the pet entity --- .../java/es/uvigo/esei/daa/entities/Pet.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) 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 98b9316..e3f7332 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 } -- 2.18.1