implemented Methods and tests:
getFilteredPlantListByHarvestSaison getFilteredPlantListByPlantingSaison #12
This commit is contained in:
@@ -3,10 +3,12 @@ package ch.zhaw.gartenverwaltung.plantList;
|
||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||
import ch.zhaw.gartenverwaltung.io.JsonPlantDatabase;
|
||||
import ch.zhaw.gartenverwaltung.io.PlantDatabase;
|
||||
import ch.zhaw.gartenverwaltung.types.GrowthPhaseType;
|
||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.MonthDay;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
@@ -118,4 +120,44 @@ public class PlantListModel {
|
||||
return getFilteredPlantList(zone, plant -> plant.name().contains(searchString) || plant.description().contains(searchString));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type GrowPhaseType to filter
|
||||
* @param zone selected hardiness zone
|
||||
* @param from the earliest date to for the filter
|
||||
* @param to the lastest date for the filter
|
||||
* @return List of Plants with selected saison
|
||||
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
||||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
private List<Plant> getFilteredPlantListBySaison(GrowthPhaseType type, HardinessZone zone, MonthDay from, MonthDay to) throws HardinessZoneNotSetException, IOException {
|
||||
return getFilteredPlantList(zone, plant -> plant.lifecycle().stream().anyMatch(growthPhase -> growthPhase.startDate().compareTo(from) >= 0 && (growthPhase.startDate().compareTo(to) <= 0) && growthPhase.type() == type));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param zone selected hardiness zone
|
||||
* @param from the earliest date to for the filter
|
||||
* @param to the lastest date for the filter
|
||||
* @return List of Plants with selected saison
|
||||
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
||||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public List<Plant> getFilteredPlantListByPlantingSaison(HardinessZone zone, MonthDay from, MonthDay to) throws HardinessZoneNotSetException, IOException {
|
||||
return getFilteredPlantListBySaison(GrowthPhaseType.PLANT, zone, from, to);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param zone selected hardiness zone
|
||||
* @param from the earliest date to for the filter
|
||||
* @param to the lastest date for the filter
|
||||
* @return List of Plants with selected saison
|
||||
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
||||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public List<Plant> getFilteredPlantListByHarvestSaison(HardinessZone zone, MonthDay from, MonthDay to) throws HardinessZoneNotSetException, IOException {
|
||||
return getFilteredPlantListBySaison(GrowthPhaseType.HARVEST, zone, from, to);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user