mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-29 18:55:49 +00:00
Changed to streams for getPet(Integer)
This commit is contained in:
parent
e8e37b35c3
commit
8a9e9c5032
1 changed files with 4 additions and 9 deletions
|
@ -113,15 +113,10 @@ public class Owner extends Person {
|
|||
* @return a pet if pet id is already in use
|
||||
*/
|
||||
public Pet getPet(Integer id) {
|
||||
for (Pet pet : getPets()) {
|
||||
if (!pet.isNew()) {
|
||||
Integer compId = pet.getId();
|
||||
if (compId.equals(id)) {
|
||||
return pet;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return getPets().stream()
|
||||
.filter(pet -> !pet.isNew() && pet.getId().equals(id))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue