mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-04-24 11:22:48 +00:00
Fix harmless bugs.
- <fix>: use `equals` to replace `==` to compare `Integer` variable. - <delete>: remove redundant 'toLowerCase()' method and simplify pet lookup logic. - <update>: rewrite method `getName()` comments.
This commit is contained in:
parent
a50bfb65bb
commit
fdc40a7048
2 changed files with 5 additions and 5 deletions
|
@ -101,7 +101,7 @@ public class Owner extends Person {
|
|||
/**
|
||||
* Return the Pet with the given name, or null if none found for this Owner.
|
||||
* @param name to test
|
||||
* @return a pet if pet name is already in use
|
||||
* @return the Pet with the given name, or null if no such Pet exists for this Owner
|
||||
*/
|
||||
public Pet getPet(String name) {
|
||||
return getPet(name, false);
|
||||
|
@ -110,7 +110,7 @@ public class Owner extends Person {
|
|||
/**
|
||||
* Return the Pet with the given id, or null if none found for this Owner.
|
||||
* @param id to test
|
||||
* @return a pet if pet id is already in use
|
||||
* @return the Pet with the given id, or null if no such Pet exists for this Owner
|
||||
*/
|
||||
public Pet getPet(Integer id) {
|
||||
for (Pet pet : getPets()) {
|
||||
|
@ -127,10 +127,10 @@ public class Owner extends Person {
|
|||
/**
|
||||
* Return the Pet with the given name, or null if none found for this Owner.
|
||||
* @param name to test
|
||||
* @return a pet if pet name is already in use
|
||||
* @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
|
||||
*/
|
||||
public Pet getPet(String name, boolean ignoreNew) {
|
||||
name = name.toLowerCase();
|
||||
for (Pet pet : getPets()) {
|
||||
String compName = pet.getName();
|
||||
if (compName != null && compName.equalsIgnoreCase(name)) {
|
||||
|
|
|
@ -138,7 +138,7 @@ class PetController {
|
|||
// checking if the pet name already exist for the owner
|
||||
if (StringUtils.hasText(petName)) {
|
||||
Pet existingPet = owner.getPet(petName.toLowerCase(), false);
|
||||
if (existingPet != null && existingPet.getId() != pet.getId()) {
|
||||
if (existingPet != null && !existingPet.getId().equals(pet.getId())) {
|
||||
result.rejectValue("name", "duplicate", "already exists");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue