Skip to content

Commit

Permalink
Fix harmless bugs.
Browse files Browse the repository at this point in the history
- <fix>: use `equals` to replace `==` to compare `Integer` variable.
- <delete>: remove redundant 'toLowerCase()' method and simplify pet lookup logic.
- <update>: rewrite method `getName()` comments.
  • Loading branch information
wickdynex authored and dsyer committed Nov 5, 2024
1 parent a50bfb6 commit fdc40a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void addPet(Pet pet) {
/**
* 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);
Expand All @@ -110,7 +110,7 @@ public Pet getPet(String name) {
/**
* 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()) {
Expand All @@ -127,10 +127,10 @@ public Pet getPet(Integer id) {
/**
* 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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public String processUpdateForm(@Valid Pet pet, BindingResult result, Owner owne
// 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");
}
}
Expand Down

0 comments on commit fdc40a7

Please sign in to comment.