Siemanko
Próbuję napisać coś swojego. Aplikacja ma umożliwiać dodawanie produktów spożywczych z parametrami, co już zrealizowałem, dalej celem jest sumowanie wartości odżywczych, porównywanie z dziennym zapotrzebowaniem etc..)
Problem leży w wybieraniu produktów, do połączenia w posiłek. Otóż zastanawiam się, czy jest jakaś alternatywa dla funkcji o określonej liczbie opcjonalnych parametrów, co z góry narzuca pewne ograniczenie na posiłek. Tutaj mam taką prowizorkę, ale nie podoba mi się to na tyle że póki co nie rozwijam jej dalej
@RequestMapping("/add")
public Integer adding(@RequestParam("i") Long index,
@RequestParam("i2") Long index2,
@RequestParam(value="i3", required = false, defaultValue = "0") Long index3,
@RequestParam(value="i4", required = false, defaultValue = "0") Long index4,
@RequestParam(value="i5", required = false, defaultValue = "0") Long index5,
@RequestParam(value="i6", required = false, defaultValue = "0") Long index6
){
Integer sum = null;
Integer i1 = productManager.findById(index).get().getCalories();
// Integer x = first.getCalories();
Products second = productManager.findById(index2).get();
Integer i2 = second.getCalories();
Integer i3,a,b,c;
if (index3==0){
i3=0;
} else {
Products thrid = productManager.findById(index3).get();
i3 = thrid.getCalories();
}
sum= i1+i2+i3;
return sum;
}
Ma ktoś jakąś inną, ładniejszą koncepcję..?