From 5b0e472ec73978fa50e23682d2fb31561889c990 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 20 Oct 2022 21:33:42 +0200 Subject: [PATCH] implemented Methods to sort and filter PlantList --- .../plantList/PlantListModel.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java b/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java index 0327e59..913e2a5 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java @@ -23,6 +23,7 @@ public class PlantListModel { public final Function filterByName = Plant::name; public final Function filterById = plant -> Long.toString(plant.id()); + public PlantListModel(List plantList) { setPlantList(plantList); } @@ -31,15 +32,30 @@ public class PlantListModel { this.plantList = plantList; } + /** + * Method to get actual Plant List in alphabetic Order + * @return actual Plant List in alphabetic Order + */ public List getPlantList() { return getSortedPlantList(sortByName); } + /** + * Method to get actual Plant List sorted in custom order + * @param comparator comparator Object which is used to sort list + * @return actual Plant List in custom order + */ public List getSortedPlantList(Comparator comparator) { return plantList.stream().sorted(comparator).toList(); } - public List getFilteredList(String filterString, Function filterFunction) { + /** + * 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 + * @return filtered Plant List + */ + public List getFilteredPlantListbyString(String filterString, Function filterFunction) { return plantList.stream().filter(plant -> filterFunction.apply(plant).contains(filterString)).toList(); } }