mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 23:05:50 +00:00
Update Owner.java
Shorter, concise, easier to read.
This commit is contained in:
parent
4e1f87407d
commit
209c1e60a3
1 changed files with 6 additions and 10 deletions
|
@ -125,17 +125,13 @@ public class Owner extends Person {
|
|||
* @return true if pet name is already in use
|
||||
*/
|
||||
public Pet getPet(String name, boolean ignoreNew) {
|
||||
name = name.toLowerCase();
|
||||
for (Pet pet : getPetsInternal()) {
|
||||
if (!ignoreNew || !pet.isNew()) {
|
||||
String compName = pet.getName();
|
||||
compName = compName.toLowerCase();
|
||||
if (compName.equals(name)) {
|
||||
return pet;
|
||||
Set<Pet> pets = getPetsInternal();
|
||||
if (ignoreNew) {
|
||||
// filter only pets that have id
|
||||
pets = getPetsInternal().stream().filter(pet -> pet.getId() != null).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
// Find pet with queried name
|
||||
return pets.stream().filter(pet -> pet.getName().equalsIgnoreCase(name)).findAny().orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue