Use Java Streams to sort the Specialty objects by their name
Signed-off-by: Antoine Rey <antoine.rey@free.fr>
This commit is contained in:
@@ -15,14 +15,13 @@
|
||||
*/
|
||||
package org.springframework.samples.petclinic.vet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
import org.springframework.samples.petclinic.model.NamedEntity;
|
||||
import org.springframework.samples.petclinic.model.Person;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
@@ -59,9 +58,9 @@ public class Vet extends Person {
|
||||
|
||||
@XmlElement
|
||||
public List<Specialty> getSpecialties() {
|
||||
List<Specialty> sortedSpecs = new ArrayList<>(getSpecialtiesInternal());
|
||||
PropertyComparator.sort(sortedSpecs, new MutableSortDefinition("name", true, true));
|
||||
return Collections.unmodifiableList(sortedSpecs);
|
||||
return getSpecialtiesInternal().stream()
|
||||
.sorted(Comparator.comparing(NamedEntity::getName))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public int getNrOfSpecialties() {
|
||||
|
||||
Reference in New Issue
Block a user