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(); } }