Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot understand why this method is unresolved

Tags:

java

spring

I am studying Spring with Spring In Action book, i have the code from the book where it works fine:

@Slf4j
@Controller
@RequestMapping("/design")
public class DesignTacoController {
    @GetMapping
    public String showDesignForm(Model model) {
        List<Ingredient> ingredients = Arrays.asList(
                new Ingredient("FLTO", "Flour Tortilla", Type.WRAP),
                new Ingredient("COTO", "Corn Tortilla", Type.WRAP),
                new Ingredient("GRBF", "Ground Beef", Type.PROTEIN),
        );

        Type[] types = Ingredient.Type.values();
        for (Type type : types) {
            model.addAttribute(type.toString().toLowerCase(),
                    filterByType(ingredients, type));
        }

        model.addAttribute("design", new Taco());
        return "design";
    }
} 

but when i typed it in my IDEA it says that method filterByType cannot be resolved, but there is no such problem in the book, and no any comment about this problem. I am new in the Spring, tried google a lot, but couldn't find any information about this problem and it source. Could you help me with this problem, a cannot move further because of it. screenshot from IDEA

like image 644
Roman Avatar asked Jan 15 '19 16:01

Roman


People also ask

How do I find all unresolved elements in a model?

Select the Only unresolved/unloaded radio button. Then, click the Find button. You see a list of all unresolved and unloaded elements in the model. Delete the reference to the missing element from the model for each search result or restore the element in question.

How do you correct for unresolved and unloaded references in Rhapsody?

How do you correct for unresolved and unloaded references in an IBM Rational Rhapsody model? When an element is removed from a model, Rhapsody cannot delete any read-only references to that element. Upon removal of the original model element, these lingering references appear with a (U) symbol.

Why does the equals method not reflect the newly added attributes?

But then a bug is discovered that either might be related to the equals method not reflecting the newly added attributes that could potentially lead to overwriting data entities in collections or a crucial log message does not give a programmer the values of the added attributes because the toString method has not been updated.


1 Answers

It looks like this book just contains an error, it does not list the filterByType() method. It's not a Spring method. Here you go:

private List<Ingredient> filterByType(List<Ingredient> ingredients, Type type) {

    return ingredients.stream()
            .filter(x -> x.getType().equals(type))
            .collect(Collectors.toList());

}

Source: Manning Publications

like image 179
Benoit Avatar answered Oct 26 '22 20:10

Benoit