updated method getFilteredPlantList
This commit is contained in:
parent
5b0e472ec7
commit
e51da071bc
|
@ -4,7 +4,6 @@ import ch.zhaw.gartenverwaltung.types.Plant;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class PlantListModel {
|
public class PlantListModel {
|
||||||
|
@ -17,12 +16,6 @@ public class PlantListModel {
|
||||||
public final Comparator<Plant> getSortById = (Plant o1, Plant o2) -> Long.compare(o1.id(), o2.id());
|
public final Comparator<Plant> getSortById = (Plant o1, Plant o2) -> Long.compare(o1.id(), o2.id());
|
||||||
public final Comparator<Plant> sortBySpacing = (Plant o1, Plant o2) -> o1.spacing() - o2.spacing();
|
public final Comparator<Plant> sortBySpacing = (Plant o1, Plant o2) -> o1.spacing() - o2.spacing();
|
||||||
|
|
||||||
/**
|
|
||||||
* Functions to get Plant Attribute as String
|
|
||||||
*/
|
|
||||||
public final Function<Plant, String> filterByName = Plant::name;
|
|
||||||
public final Function<Plant, String> filterById = plant -> Long.toString(plant.id());
|
|
||||||
|
|
||||||
|
|
||||||
public PlantListModel(List<Plant> plantList) {
|
public PlantListModel(List<Plant> plantList) {
|
||||||
setPlantList(plantList);
|
setPlantList(plantList);
|
||||||
|
@ -51,11 +44,10 @@ public class PlantListModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get filtered Plant List with custom filter
|
* Method to get filtered Plant List with custom filter
|
||||||
* @param filterString String to search for plants
|
* @param predicate predicate for filter
|
||||||
* @param filterFunction Function Object to get Plant attribute as String which must contain filter String
|
|
||||||
* @return filtered Plant List
|
* @return filtered Plant List
|
||||||
*/
|
*/
|
||||||
public List<Plant> getFilteredPlantListbyString(String filterString, Function<Plant, String> filterFunction) {
|
public List<Plant> getFilteredPlantList(Predicate<Plant> predicate) {
|
||||||
return plantList.stream().filter(plant -> filterFunction.apply(plant).contains(filterString)).toList();
|
return plantList.stream().filter(predicate).toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue