forked from JavaOPs/topjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
88 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ out | |
target | ||
*.iml | ||
log | ||
*.patch | ||
patch | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ru.javawebinar.topjava.model; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class MealTo { | ||
private final LocalDateTime dateTime; | ||
|
||
private final String description; | ||
|
||
private final int calories; | ||
|
||
private final boolean excess; | ||
|
||
public MealTo(LocalDateTime dateTime, String description, int calories, boolean excess) { | ||
this.dateTime = dateTime; | ||
this.description = description; | ||
this.calories = calories; | ||
this.excess = excess; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MealTo{" + | ||
"dateTime=" + dateTime + | ||
", description='" + description + '\'' + | ||
", calories=" + calories + | ||
", excess=" + excess + | ||
'}'; | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
src/main/java/ru/javawebinar/topjava/model/UserMealWithExceed.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ru.javawebinar.topjava.util; | ||
|
||
import ru.javawebinar.topjava.model.Meal; | ||
import ru.javawebinar.topjava.model.MealTo; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.time.Month; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class MealsUtil { | ||
public static void main(String[] args) { | ||
List<Meal> meals = Arrays.asList( | ||
new Meal(LocalDateTime.of(2015, Month.MAY, 30, 10, 0), "Завтрак", 500), | ||
new Meal(LocalDateTime.of(2015, Month.MAY, 30, 13, 0), "Обед", 1000), | ||
new Meal(LocalDateTime.of(2015, Month.MAY, 30, 20, 0), "Ужин", 500), | ||
new Meal(LocalDateTime.of(2015, Month.MAY, 31, 10, 0), "Завтрак", 1000), | ||
new Meal(LocalDateTime.of(2015, Month.MAY, 31, 13, 0), "Обед", 500), | ||
new Meal(LocalDateTime.of(2015, Month.MAY, 31, 20, 0), "Ужин", 510) | ||
); | ||
List<MealTo> mealsWithExcess = getFilteredWithExcess(meals, LocalTime.of(7, 0), LocalTime.of(12, 0), 2000); | ||
mealsWithExcess.forEach(System.out::println); | ||
} | ||
|
||
public static List<MealTo> getFilteredWithExcess(List<Meal> meals, LocalTime startTime, LocalTime endTime, int caloriesPerDay) { | ||
Map<LocalDate, Integer> caloriesSumByDate = meals.stream() | ||
.collect( | ||
Collectors.groupingBy(Meal::getDate, Collectors.summingInt(Meal::getCalories)) | ||
// Collectors.toMap(Meal::getDate, Meal::getCalories, Integer::sum) | ||
); | ||
|
||
return meals.stream() | ||
.filter(meal -> TimeUtil.isBetween(meal.getTime(), startTime, endTime)) | ||
.map(meal -> | ||
new MealTo(meal.getDateTime(), meal.getDescription(), meal.getCalories(), | ||
caloriesSumByDate.get(meal.getDate()) > caloriesPerDay)) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
31 changes: 0 additions & 31 deletions
31
src/main/java/ru/javawebinar/topjava/util/UserMealsUtil.java
This file was deleted.
Oops, something went wrong.