From e51da071bc4a0ff471e5c140016c01cb23b2c809 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Mon, 24 Oct 2022 12:44:11 +0200 Subject: [PATCH] updated method getFilteredPlantList --- .../gartenverwaltung/plantList/PlantListModel.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java b/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java index 913e2a5..22b7de2 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java @@ -4,7 +4,6 @@ import ch.zhaw.gartenverwaltung.types.Plant; import java.util.Comparator; import java.util.List; -import java.util.function.Function; import java.util.function.Predicate; public class PlantListModel { @@ -17,12 +16,6 @@ public class PlantListModel { public final Comparator getSortById = (Plant o1, Plant o2) -> Long.compare(o1.id(), o2.id()); public final Comparator sortBySpacing = (Plant o1, Plant o2) -> o1.spacing() - o2.spacing(); - /** - * Functions to get Plant Attribute as String - */ - public final Function filterByName = Plant::name; - public final Function filterById = plant -> Long.toString(plant.id()); - public PlantListModel(List plantList) { setPlantList(plantList); @@ -51,11 +44,10 @@ public class PlantListModel { /** * Method to get filtered Plant List with custom filter - * @param filterString String to search for plants - * @param filterFunction Function Object to get Plant attribute as String which must contain filter String + * @param predicate predicate for filter * @return filtered Plant List */ - public List getFilteredPlantListbyString(String filterString, Function filterFunction) { - return plantList.stream().filter(plant -> filterFunction.apply(plant).contains(filterString)).toList(); + public List getFilteredPlantList(Predicate predicate) { + return plantList.stream().filter(predicate).toList(); } }