Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing updated form of filterByType() method in DesignTacoController in chapter 3 in the book #11

Open
charlie39 opened this issue Aug 17, 2022 · 4 comments

Comments

@charlie39
Copy link

charlie39 commented Aug 17, 2022

After introducing IngredientRepository in chapter 3, the

filterByType(List<Ingredient>, Type type)

in DesignController.java should be updated to to take an
Iterable<Ingredient>
object instead of List<Ingredient> in given in the sample code. But snippet
for such change is missing from the book.
Should have listing showing the change right after Listing 3.7

@AndyLau223
Copy link

Yep, I also found the same issue that's not a big problem. Hence, I change the code as below snippet as work around
for (final Ingredient.Type type : types) {
model.addAttribute(type.toString().toLowerCase(),
filterByType((List) ingredients,type));
}

@charlie39
Copy link
Author

charlie39 commented Aug 26, 2022

@AndyLau223 there's another issue in page 76 with the saveIngredientRefs(long tacoId, List<IngredientRef> ingredientRefs)

While calling, saveIngredientRefs(tacoId, taco.Inredients()) ; is passed with a List<Ingredient> object while it actually accepts List<IngredientRefs> object.

@AndyLau223
Copy link

@charlie39 You need to change the Taco.class entity by making private List<Ingredient> ingredients = new ArrayList<>(); to private List<IngredientRef> ingredients = new ArrayList<>();

@KianYang-Lee
Copy link

Leaving below code to stream iterable for anyone that might need it:

    private Iterable<Ingredient> filterByType(Iterable<Ingredient> ingredients, Type type) {
        return StreamSupport.stream(ingredients.spliterator(), false).filter(x -> x.getType().equals(type))
                .collect(Collectors.toList());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants