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
|
* @return true if pet name is already in use
|
||||||
*/
|
*/
|
||||||
public Pet getPet(String name, boolean ignoreNew) {
|
public Pet getPet(String name, boolean ignoreNew) {
|
||||||
name = name.toLowerCase();
|
Set<Pet> pets = getPetsInternal();
|
||||||
for (Pet pet : getPetsInternal()) {
|
if (ignoreNew) {
|
||||||
if (!ignoreNew || !pet.isNew()) {
|
// filter only pets that have id
|
||||||
String compName = pet.getName();
|
pets = getPetsInternal().stream().filter(pet -> pet.getId() != null).collect(Collectors.toSet());
|
||||||
compName = compName.toLowerCase();
|
|
||||||
if (compName.equals(name)) {
|
|
||||||
return pet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
// Find pet with queried name
|
||||||
|
return pets.stream().filter(pet -> pet.getName().equalsIgnoreCase(name)).findAny().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue