completed Methods

created Config Class
This commit is contained in:
schrom01 2022-10-31 15:57:19 +01:00
parent d1d9d11b66
commit 0e4e207581
4 changed files with 35 additions and 19 deletions

View File

@ -0,0 +1,19 @@
package ch.zhaw.gartenverwaltung;
import ch.zhaw.gartenverwaltung.types.HardinessZone;
public class Config {
private static HardinessZone currentHardinessZone;
static {
currentHardinessZone = HardinessZone.ZONE_8A;
}
public static HardinessZone getCurrentHardinessZone() {
return currentHardinessZone;
}
public static void setCurrentHardinessZone(HardinessZone currentHardinessZone) {
Config.currentHardinessZone = currentHardinessZone;
}
}

View File

@ -1,19 +1,16 @@
package ch.zhaw.gartenverwaltung.taskList;
import ch.zhaw.gartenverwaltung.Config;
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
import ch.zhaw.gartenverwaltung.io.JsonTaskDatabase;
import ch.zhaw.gartenverwaltung.io.PlantDatabase;
import ch.zhaw.gartenverwaltung.io.TaskDatabase;
import ch.zhaw.gartenverwaltung.types.Crop;
import ch.zhaw.gartenverwaltung.types.HardinessZone;
import ch.zhaw.gartenverwaltung.types.Plant;
import ch.zhaw.gartenverwaltung.types.Task;
import ch.zhaw.gartenverwaltung.types.*;
import java.io.IOException;
import java.time.LocalDate;
import java.util.Comparator;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
public class TaskListModel {
@ -36,14 +33,15 @@ public class TaskListModel {
}
public void planTasksForCrop(Crop crop) throws PlantNotFoundException, HardinessZoneNotSetException, IOException {
Plant plant = plantDatabase.getPlantById(HardinessZone.ZONE_8A, crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
// TODO new exception
// TODO HArdiness Zone
return;
Plant plant = plantDatabase.getPlantById(Config.getCurrentHardinessZone(), crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
for (GrowthPhase growthPhase : plant.lifecycle()) {
for (TaskTemplate taskTemplate : growthPhase.taskTemplates()) {
addTask(taskTemplate.generateTask(crop.getStartDate(), crop.getCropId().orElse(0L)));
}
}
}
public void removeTasksForCrop(Crop crop) {
//TODO implement
taskDatabase.removeTasksForCrop(crop);
}

View File

@ -15,22 +15,24 @@ public class Task {
private final LocalDate startDate;
private Integer interval;
private LocalDate endDate;
private Crop cropId;
private long cropId;
/**
* default constructor
* (used by Json deserializer)
*/
public Task(){
public Task(long cropId){
name= "";
description= "";
startDate = LocalDate.now();
this.cropId = cropId;
}
public Task(String name, String description, LocalDate startDate) {
public Task(String name, String description, LocalDate startDate, long cropId) {
this.name = name;
this.description = description;
this.startDate = startDate;
this.cropId = cropId;
}
public Task(String name, String description, LocalDate startDate, LocalDate endDate, int interval) {
@ -56,10 +58,7 @@ public class Task {
}
public boolean isInTimePeriode(LocalDate searchStartDate, LocalDate searchEndDate){
if(startDate.isAfter(searchStartDate) &&startDate.isBefore(searchEndDate)){
return true;
}
return false;
return startDate.isAfter(searchStartDate) && startDate.isBefore(searchEndDate);
}
// Getters

View File

@ -44,8 +44,8 @@ public class TaskTemplate {
this.relativeStartDate = relativeStartDate;
}
public Task generateTask(LocalDate realStartDate) {
Task task = new Task(name, description, realStartDate.plusDays(relativeStartDate));
public Task generateTask(LocalDate realStartDate, long cropId) {
Task task = new Task(name, description, realStartDate.plusDays(relativeStartDate), cropId);
if (relativeEndDate != null) {
task.withEndDate(realStartDate.plusDays(relativeEndDate));
}