Category Enum for category of Car

This commit is contained in:
nikhilbarar
2018-08-29 22:02:17 +05:30
parent b23d8430af
commit 9daa3140e4
7 changed files with 50 additions and 18 deletions

View File

@ -66,7 +66,7 @@ public class FunctionalProgramming {
* @param cars {@link List} of {@link Car} to be used for grouping
* @return {@link Map} with category as key and cars belonging to that category as value
*/
public static Map<String, List<Car>> getGroupingOfCarsByCategory(List<Car> cars) {
public static Map<Category, List<Car>> getGroupingOfCarsByCategory(List<Car> cars) {
return cars.stream().collect(Collectors.groupingBy(Car::getCategory));
}
@ -78,7 +78,7 @@ public class FunctionalProgramming {
*/
public static List<Car> getSedanCarsOwnedSortedByDate(List<Person> persons) {
return persons.stream().map(Person::getCars).flatMap(List::stream)
.filter(car -> "Sedan".equals(car.getCategory()))
.filter(car -> Category.SEDAN.equals(car.getCategory()))
.sorted(Comparator.comparing(Car::getYear)).collect(Collectors.toList());
}
}