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

@ -86,8 +86,8 @@ public class ImperativeProgramming {
* @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) {
Map<String, List<Car>> groupingByCategory = new HashMap<>();
public static Map<Category, List<Car>> getGroupingOfCarsByCategory(List<Car> cars) {
Map<Category, List<Car>> groupingByCategory = new HashMap<>();
for (Car car: cars) {
if (groupingByCategory.containsKey(car.getCategory())) {
groupingByCategory.get(car.getCategory()).add(car);
@ -114,7 +114,7 @@ public class ImperativeProgramming {
List<Car> sedanCars = new ArrayList<>();
for (Car car: cars) {
if ("Sedan".equals(car.getCategory())) {
if (Category.SEDAN.equals(car.getCategory())) {
sedanCars.add(car);
}
}