implemented Method getFilteredPlantListByString in PlantListModel
This commit is contained in:
@@ -20,8 +20,8 @@ public class PlantListModel {
|
||||
/**
|
||||
* Comparators to create sorted Plant List
|
||||
*/
|
||||
static final Comparator<Plant> sortByName = (Plant o1, Plant o2) -> o1.name().compareTo(o2.name());
|
||||
static final Comparator<Plant> SortById = (Plant o1, Plant o2) -> Long.compare(o1.id(), o2.id());
|
||||
static final Comparator<Plant> sortByName = Comparator.comparing(Plant::name);
|
||||
static final Comparator<Plant> SortById = Comparator.comparingLong(Plant::id);
|
||||
|
||||
/**
|
||||
* Constructor to create Database Object.
|
||||
@@ -98,4 +98,19 @@ public class PlantListModel {
|
||||
plantDatabase.getPlantById(zone, id).ifPresent(plantList::add);
|
||||
return plantList;
|
||||
}
|
||||
|
||||
|
||||
public List<Plant> getFilteredPlantListByString(HardinessZone zone, String searchString) throws HardinessZoneNotSetException, IOException {
|
||||
if(searchString.charAt(0) == '#') {
|
||||
try {
|
||||
return getFilteredPlantListById(zone, Long.parseLong(searchString.substring(1)));
|
||||
} catch (NumberFormatException e) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
} else {
|
||||
return getFilteredPlantList(zone, plant -> plant.name().contains(searchString) || plant.description().contains(searchString));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user