@@ -29,30 +29,31 @@ public static void main(String[] args) {
29
29
}
30
30
31
31
public static List <UserMealWithExcess > filteredByCycles (List <UserMeal > meals , LocalTime startTime , LocalTime endTime , int caloriesPerDay ) {
32
- Map <LocalDate , Integer > caloriesSumPerDate = new HashMap <>();
32
+ Map <LocalDate , Integer > caloriesSumPerDates = new HashMap <>();
33
33
for (UserMeal meal : meals ) {
34
- caloriesSumPerDate .merge (meal .getDateTime ().toLocalDate (), meal .getCalories (), Integer ::sum );
34
+ caloriesSumPerDates .merge (meal .getDateTime ().toLocalDate (), meal .getCalories (), Integer ::sum );
35
35
}
36
- List <UserMealWithExcess > userMealWithExcesses = new ArrayList <>();
36
+ List <UserMealWithExcess > userMealsWithExcesses = new ArrayList <>();
37
37
for (UserMeal meal : meals ) {
38
- LocalDateTime dateTime = meal .getDateTime ();
39
- if (TimeUtil .isBetweenHalfOpen (dateTime .toLocalTime (), startTime , endTime )) {
40
- userMealWithExcesses .add (createUserWithExcess (meal ,
41
- caloriesSumPerDate .get (meal .getDateTime ().toLocalDate ()) > caloriesPerDay ));
38
+ LocalDateTime dateTimeMeal = meal .getDateTime ();
39
+ if (TimeUtil .isBetweenHalfOpen (dateTimeMeal .toLocalTime (), startTime , endTime )) {
40
+ userMealsWithExcesses .add (createUserWithExcess (meal ,
41
+ caloriesSumPerDates .get (meal .getDateTime ().toLocalDate ()) > caloriesPerDay ));
42
42
}
43
43
}
44
- return userMealWithExcesses ;
44
+ return userMealsWithExcesses ;
45
45
}
46
46
47
47
public static List <UserMealWithExcess > filteredByStreams (List <UserMeal > meals , LocalTime startTime , LocalTime endTime , int caloriesPerDay ) {
48
- Map <LocalDate , Integer > caloriesSumPerDate = meals .stream ().collect (Collectors .groupingBy (meal -> meal .getDateTime ().toLocalDate (),
49
- Collectors .summingInt (UserMeal ::getCalories )));
50
- return meals .stream ().filter (meal -> TimeUtil .isBetweenHalfOpen (meal .getDateTime ().toLocalTime (), startTime , endTime ))
51
- .map (meal -> createUserWithExcess (meal , caloriesSumPerDate .get (meal .getDateTime ().toLocalDate ()) > caloriesPerDay ))
48
+ Map <LocalDate , Integer > caloriesSumPerDates = meals .stream ()
49
+ .collect (Collectors .groupingBy (meal -> meal .getDateTime ().toLocalDate (),Collectors .summingInt (UserMeal ::getCalories )));
50
+ return meals .stream ()
51
+ .filter (meal -> TimeUtil .isBetweenHalfOpen (meal .getDateTime ().toLocalTime (), startTime , endTime ))
52
+ .map (meal -> createUserWithExcess (meal , caloriesSumPerDates .get (meal .getDateTime ().toLocalDate ()) > caloriesPerDay ))
52
53
.collect (Collectors .toList ());
53
54
}
54
55
55
- public static UserMealWithExcess createUserWithExcess (UserMeal meal , boolean excess ) {
56
+ private static UserMealWithExcess createUserWithExcess (UserMeal meal , boolean excess ) {
56
57
return new UserMealWithExcess (meal .getDateTime (), meal .getDescription (), meal .getCalories (), excess );
57
58
}
58
59
}
0 commit comments