-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRecipe.java
166 lines (145 loc) · 5.17 KB
/
Recipe.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package ProjectRF;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import com.google.common.base.MoreObjects;
public class Recipe {
public final String name;
public final List<String> ingredients;
//public final Nutrition nutrition;
public final ByteBuffer image;
public final Grade grade;
public final String url;
public final String urlId;
public final String prepTime;
public final String cookingTime;
public final String totalTime;
// public Recipe()
// {
// this.name = "";
// //this.nutrition = Objects.requireNonNull(nutrition);
// this.ingredients = new ArrayList<>();
// this.grade = new Grade(0, 0);
// this.image = null;
// this.url = "";
// this.urlId = "";
// this.prepTime = "";
// this.cookingTime = "";
// this.totalTime = "";
// }
public Recipe(String name, List<String> ingredients, double score,int count, ByteBuffer image, String url, String urlId, String prepTime, String cookingTime, String totalTime)
{
this.name = Objects.requireNonNull(name);
//this.nutrition = Objects.requireNonNull(nutrition);
this.ingredients = Objects.requireNonNull(ingredients);
this.grade = new Grade(score,count);
this.image = image;
this.url = url;
this.urlId = urlId;
this.prepTime = prepTime;
this.cookingTime = cookingTime;
this.totalTime = totalTime;
}
public Optional<ByteBuffer> getImage() {
return Optional.of(image);
}
public List<String> getIngredients() {
return Collections.unmodifiableList(ingredients);
}
public Nutrition getNutrition() {
return nutrition;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("name", name)
.add("ingredients", ingredients)
.add("nutrition", nutrition)
.add("image", image)
.add("grade", grade)
.toString();
}
/**
* A grade is composed of the number of reviews for the recipe
* as well as the rating of the recipe. This is used to create
* a "grading" system to rank recipes.
*/
public static class Grade {
public final double rating;
public final int numReviews;
public Grade(double rating, int numReviews) {
this.rating = Objects.requireNonNull(rating);
this.numReviews = Objects.requireNonNull(numReviews);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("rating", rating)
.add("numReviews", numReviews)
.toString();
}
}
/**
* Nutrition is the nutrition information of the recipe which includes
* the calories as well as the caloric breakdown. It also includes
* the amount of dietary cholesterol and the sodium level.
*
* Units are as follows (plans to update double type to unit class)
* calories : Calories
* fat : grams
* carbs : grams
* protein : grams
* cholesterol : milligrams
* sodium : milligrams
*
*/
public static class Nutrition {
private final double calories;
private final double fat;
private final double carbohydrates;
private final double protein;
private final double cholesterol;
private final double sodium;
public Nutrition(double calories, double fat, double carbohydrates, double protein, double cholesterol, double sodium) {
this.calories = Objects.requireNonNull(calories);
this.fat = Objects.requireNonNull(fat);
this.carbohydrates = Objects.requireNonNull(carbohydrates);
this.protein = Objects.requireNonNull(protein);
this.cholesterol = Objects.requireNonNull(cholesterol);
this.sodium = Objects.requireNonNull(sodium);
}
public double getCalories() {
return calories;
}
public double getFat() {
return fat;
}
public double getCarbohydrates() {
return carbohydrates;
}
public double getProtein() {
return protein;
}
public double getCholesterol() {
return cholesterol;
}
public double getSodium() {
return sodium;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("calories", calories)
.add("fat", fat)
.add("carbohydrates", carbohydrates)
.add("protein", protein)
.add("cholesterol", cholesterol)
.add("sodium", sodium)
.toString();
}
}
}