Update Owner.java

Signed-off-by: AulaEmpresaLKS <129507941+AulaEmpresaLKS@users.noreply.github.com>
This commit is contained in:
AulaEmpresaLKS 2025-03-31 11:56:29 +02:00 committed by GitHub
parent 473c3a694e
commit 56b3b3148e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,3 +1,18 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.samples.petclinic.owner; package org.springframework.samples.petclinic.owner;
import java.util.ArrayList; import java.util.ArrayList;
@ -21,7 +36,12 @@ import jakarta.validation.constraints.NotBlank;
/** /**
* Simple JavaBean domain object representing an owner. * Simple JavaBean domain object representing an owner.
* *
* (Autores omitidos para mayor claridad) * @author Ken Krebs
* @author Juergen Hoeller
* @author Sam Brannen
* @author Michael Isvy
* @author Oliver Drotbohm
* @author Wick Dynex
*/ */
@Entity @Entity
@Table(name = "owners") @Table(name = "owners")
@ -81,7 +101,6 @@ public class Owner extends Person {
/** /**
* Return the Pet with the given name, or null if none found for this Owner. * Return the Pet with the given name, or null if none found for this Owner.
*
* @param name to test * @param name to test
* @return the Pet with the given name, or null if no such Pet exists for this Owner * @return the Pet with the given name, or null if no such Pet exists for this Owner
*/ */
@ -91,7 +110,6 @@ public class Owner extends Person {
/** /**
* Return the Pet with the given id, or null if none found for this Owner. * Return the Pet with the given id, or null if none found for this Owner.
*
* @param id to test * @param id to test
* @return the Pet with the given id, or null if no such Pet exists for this Owner * @return the Pet with the given id, or null if no such Pet exists for this Owner
*/ */
@ -109,7 +127,6 @@ public class Owner extends Person {
/** /**
* Return the Pet with the given name, or null if none found for this Owner. * Return the Pet with the given name, or null if none found for this Owner.
*
* @param name to test * @param name to test
* @param ignoreNew whether to ignore new pets (pets that are not saved yet) * @param ignoreNew whether to ignore new pets (pets that are not saved yet)
* @return the Pet with the given name, or null if no such Pet exists for this Owner * @return the Pet with the given name, or null if no such Pet exists for this Owner
@ -128,8 +145,7 @@ public class Owner extends Person {
@Override @Override
public String toString() { public String toString() {
return new ToStringCreator(this) return new ToStringCreator(this).append("id", this.getId())
.append("id", this.getId())
.append("new", this.isNew()) .append("new", this.isNew())
.append("lastName", this.getLastName()) .append("lastName", this.getLastName())
.append("firstName", this.getFirstName()) .append("firstName", this.getFirstName())
@ -138,4 +154,22 @@ public class Owner extends Person {
.append("telephone", this.telephone) .append("telephone", this.telephone)
.toString(); .toString();
} }
/**
* Adds the given {@link Visit} to the {@link Pet} with the given identifier.
* @param petId the identifier of the {@link Pet}, must not be {@literal null}.
* @param visit the visit to add, must not be {@literal null}.
*/
public void addVisit(Integer petId, Visit visit) {
Assert.notNull(petId, "Pet identifier must not be null!");
Assert.notNull(visit, "Visit must not be null!");
Pet pet = getPet(petId);
Assert.notNull(pet, "Invalid Pet identifier!");
pet.addVisit(visit);
}
} }