diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java index 6ac9ca8..1fd15cd 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Random; import javafx.event.ActionEvent; import javafx.fxml.FXML; @@ -162,7 +163,10 @@ public void handleFrontSearch(ActionEvent event) { * This method is used to filter the charities based on the selected filters. * *

The filters are whether the charity was pre-verified, or if it falls under one (or more) of - * the given categories. + * the given categories.

+ * + *

The check checks whether the given charity has ALL filters. If one does not apply, + * the charity is rejected.

* * @return a list of filtered charities. */ @@ -178,21 +182,18 @@ private List getFilteredCharities() { if (!selectedCategories.isEmpty()) { - boolean hasMatch = false; - - for (String cat : charity.getCategory()) { - if (cat == null) continue; + boolean hasAll = + charity.getCategory().stream() + .filter(Objects::nonNull) + .map(c -> c.toLowerCase().trim()) + .collect(java.util.stream.Collectors.toSet()) + .containsAll(selectedCategories); - if (selectedCategories.contains(cat.toLowerCase().trim())) { - hasMatch = true; - break; - } - } - - if (!hasMatch) { + if (!hasAll) { continue; } } + filtered.add(charity); }