From cbecf482b8122755dc290542fda3a29c7ecd3d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Sat, 4 May 2024 09:26:17 +0200 Subject: [PATCH] #22: Setup Ingredient Model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dominik Säume --- .../hitec/nhplus/medication/Ingredient.java | 36 +++++++++++++++++++ .../hitec/nhplus/medication/Medication.java | 13 +++---- 2 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 src/main/java/de/hitec/nhplus/medication/Ingredient.java diff --git a/src/main/java/de/hitec/nhplus/medication/Ingredient.java b/src/main/java/de/hitec/nhplus/medication/Ingredient.java new file mode 100644 index 0000000..0ddca5a --- /dev/null +++ b/src/main/java/de/hitec/nhplus/medication/Ingredient.java @@ -0,0 +1,36 @@ +package de.hitec.nhplus.medication; + +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleStringProperty; + +public class Ingredient { + private SimpleIntegerProperty id; + private SimpleStringProperty name; + + public Ingredient(int id, String name) { + this.id = new SimpleIntegerProperty(id); + this.name = new SimpleStringProperty(name); + } + + public int getId() { + return id.get(); + } + + public SimpleIntegerProperty idProperty() { + return id; + } + + public String getName() { + return name.get(); + } + + public SimpleStringProperty nameProperty() { + return name; + } + + public void setName(String name) { + this.name.set(name); + } + + +} diff --git a/src/main/java/de/hitec/nhplus/medication/Medication.java b/src/main/java/de/hitec/nhplus/medication/Medication.java index 8ad6f9e..bf6046c 100644 --- a/src/main/java/de/hitec/nhplus/medication/Medication.java +++ b/src/main/java/de/hitec/nhplus/medication/Medication.java @@ -12,7 +12,7 @@ public class Medication { private SimpleIntegerProperty id; private final SimpleStringProperty name; private final SimpleStringProperty manufacturer; - private final SimpleListProperty ingredients; + private final SimpleListProperty ingredients; private final SimpleStringProperty possibleSideEffects; private final SimpleStringProperty administrationMethod; private final SimpleIntegerProperty currentStock; @@ -20,7 +20,7 @@ public class Medication { public Medication( String name, String manufacturer, - ObservableList ingredients, + ObservableList ingredients, String possibleSideEffects, String administrationMethod, int currentStock @@ -37,7 +37,7 @@ public class Medication { int id, String name, String manufacturer, - ObservableList ingredients, + ObservableList ingredients, String possibleSideEffects, String administrationMethod, int currentStock @@ -83,15 +83,15 @@ public class Medication { this.manufacturer.set(manufacturer); } - public ObservableList getIngredients() { + public ObservableList getIngredients() { return ingredients.get(); } - public SimpleListProperty ingredientsProperty() { + public SimpleListProperty ingredientsProperty() { return ingredients; } - public void setIngredients(ObservableList ingredients) { + public void setIngredients(ObservableList ingredients) { this.ingredients.set(ingredients); } @@ -140,6 +140,7 @@ public class Medication { .add("Manufacturer: " + this.getManufacturer()) .add("Ingredients: " + this.getIngredients() .stream() + .map(Ingredient::getName) .collect(Collectors.joining(", ", "[", "]"))) .add("Possible Side Effects: " + this.getPossibleSideEffects()) .add("Administration Method: " + this.getAdministrationMethod())