Skip to content

Commit 55db3cc

Browse files
bazhukovsibazhukovsi
authored andcommitted
Apply prepare_to_HW0_patch.patch
1 parent 1407029 commit 55db3cc

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package ru.javawebinar.topjava.model;
2+
3+
import java.time.LocalDateTime;
4+
5+
public class UserMeal {
6+
private final LocalDateTime dateTime;
7+
8+
private final String description;
9+
10+
private final int calories;
11+
12+
public UserMeal(LocalDateTime dateTime, String description, int calories) {
13+
this.dateTime = dateTime;
14+
this.description = description;
15+
this.calories = calories;
16+
}
17+
18+
public LocalDateTime getDateTime() {
19+
return dateTime;
20+
}
21+
22+
public String getDescription() {
23+
return description;
24+
}
25+
26+
public int getCalories() {
27+
return calories;
28+
}
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package ru.javawebinar.topjava.model;
2+
3+
import java.time.LocalDateTime;
4+
5+
public class UserMealWithExcess {
6+
private final LocalDateTime dateTime;
7+
8+
private final String description;
9+
10+
private final int calories;
11+
12+
private final boolean excess;
13+
14+
public UserMealWithExcess(LocalDateTime dateTime, String description, int calories, boolean excess) {
15+
this.dateTime = dateTime;
16+
this.description = description;
17+
this.calories = calories;
18+
this.excess = excess;
19+
}
20+
21+
@Override
22+
public String toString() {
23+
return "UserMealWithExcess{" +
24+
"dateTime=" + dateTime +
25+
", description='" + description + '\'' +
26+
", calories=" + calories +
27+
", excess=" + excess +
28+
'}';
29+
}
30+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ru.javawebinar.topjava.util;
2+
3+
import java.time.LocalTime;
4+
5+
public class TimeUtil {
6+
public static boolean isBetweenHalfOpen(LocalTime lt, LocalTime startTime, LocalTime endTime) {
7+
return lt.compareTo(startTime) >= 0 && lt.compareTo(endTime) < 0;
8+
}
9+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package ru.javawebinar.topjava.util;
2+
3+
import ru.javawebinar.topjava.model.UserMeal;
4+
import ru.javawebinar.topjava.model.UserMealWithExcess;
5+
6+
import java.time.LocalDateTime;
7+
import java.time.LocalTime;
8+
import java.time.Month;
9+
import java.util.Arrays;
10+
import java.util.List;
11+
12+
public class UserMealsUtil {
13+
public static void main(String[] args) {
14+
List<UserMeal> meals = Arrays.asList(
15+
new UserMeal(LocalDateTime.of(2020, Month.JANUARY, 30, 10, 0), "Завтрак", 500),
16+
new UserMeal(LocalDateTime.of(2020, Month.JANUARY, 30, 13, 0), "Обед", 1000),
17+
new UserMeal(LocalDateTime.of(2020, Month.JANUARY, 30, 20, 0), "Ужин", 500),
18+
new UserMeal(LocalDateTime.of(2020, Month.JANUARY, 31, 0, 0), "Еда на граничное значение", 100),
19+
new UserMeal(LocalDateTime.of(2020, Month.JANUARY, 31, 10, 0), "Завтрак", 1000),
20+
new UserMeal(LocalDateTime.of(2020, Month.JANUARY, 31, 13, 0), "Обед", 500),
21+
new UserMeal(LocalDateTime.of(2020, Month.JANUARY, 31, 20, 0), "Ужин", 410)
22+
);
23+
24+
List<UserMealWithExcess> mealsTo = filteredByCycles(meals, LocalTime.of(7, 0), LocalTime.of(12, 0), 2000);
25+
mealsTo.forEach(System.out::println);
26+
27+
// System.out.println(filteredByStreams(meals, LocalTime.of(7, 0), LocalTime.of(12, 0), 2000));
28+
}
29+
30+
public static List<UserMealWithExcess> filteredByCycles(List<UserMeal> meals, LocalTime startTime, LocalTime endTime, int caloriesPerDay) {
31+
// TODO return filtered list with excess. Implement by cycles
32+
return null;
33+
}
34+
35+
public static List<UserMealWithExcess> filteredByStreams(List<UserMeal> meals, LocalTime startTime, LocalTime endTime, int caloriesPerDay) {
36+
// TODO Implement by streams
37+
return null;
38+
}
39+
}

0 commit comments

Comments
 (0)