diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2016-01-11 16:19:55 +0100 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2016-01-11 16:57:15 +0100 |
| commit | d70f8574208a47242ef9fe1a715b575ff078c9a2 (patch) | |
| tree | 671f0b3cb377a3f26e4fc21041923ed4c53c105a /src/de/fhswf/in | |
| parent | 48c08e5df63e42eccef488a821d60348f5f15a75 (diff) | |
| download | Projektthemenvergabe-d70f8574208a47242ef9fe1a715b575ff078c9a2.tar.gz Projektthemenvergabe-d70f8574208a47242ef9fe1a715b575ff078c9a2.zip | |
Enforce needed values via constructor
Diffstat (limited to 'src/de/fhswf/in')
7 files changed, 96 insertions, 24 deletions
diff --git a/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Ansprechpartner.java b/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Ansprechpartner.java index ce28c51..6a29db5 100644 --- a/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Ansprechpartner.java +++ b/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Ansprechpartner.java @@ -58,15 +58,44 @@ public class Ansprechpartner * Constructor of Ansprechpartner. * * @param organisation + * The {@link Organisation} of the {@link Ansprechpartner}. + * @param vorname + * The vorname of the {@link Ansprechpartner}. + * @param nachname + * The nachname of the {@link Ansprechpartner}. */ - public Ansprechpartner(Organisation organisation) + public Ansprechpartner(Organisation organisation, String vorname, + String nachname) { + if (vorname == null) + { + throw new IllegalArgumentException("Vorname can't be null."); + } + + if (nachname == null) + { + throw new IllegalArgumentException("Nachname can't be null."); + } + + if (vorname.isEmpty()) + { + throw new IllegalArgumentException("Vorname can't be empty."); + } + + if (nachname.isEmpty()) + { + throw new IllegalArgumentException("Nachname can't be empty."); + } + this.organisation.set(organisation); if (organisation != null) { this.organisation.get().addAnsprechpartner(this); } + + this.vorname.set(vorname); + this.nachname.set(nachname); } /** diff --git a/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Organisation.java b/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Organisation.java index b9a6da4..ab90403 100644 --- a/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Organisation.java +++ b/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Organisation.java @@ -34,6 +34,27 @@ public class Organisation } /** + * Constructor of {@link Organisation}. + * + * @param name + * The name of the {@link Organisation}. + */ + public Organisation(String name) + { + if (name == null) + { + throw new IllegalArgumentException("Name can't be null."); + } + + if (name.isEmpty()) + { + throw new IllegalArgumentException("Name can't be empty."); + } + + this.name.set(name); + } + + /** * Getter for property name. * * @return Returns the name. diff --git a/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Projekt.java b/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Projekt.java index 91fd89e..e52e2d8 100644 --- a/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Projekt.java +++ b/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Projekt.java @@ -75,6 +75,8 @@ public class Projekt * * Constructor of Project. * + * @param projektthema + * The name of the {@link Projekt}. * @param student1 * The first Student * @param student2 @@ -84,13 +86,20 @@ public class Projekt * @param ansprechpartner * The Ansprechpartner */ - public Projekt( - - Student student1, Student student2, - + public Projekt(String projektthema, Student student1, Student student2, Student student3, Ansprechpartner ansprechpartner) { + if (projektthema == null) + { + throw new IllegalArgumentException("Projektthema can't be null."); + } + + if (projektthema.isEmpty()) + { + throw new IllegalArgumentException("Projektthema can't be empty."); + } + if (student1 == null && student2 == null && student3 == null) { throw new IllegalArgumentException( @@ -123,6 +132,7 @@ public class Projekt this.ansprechpartner = ansprechpartner; this.ansprechpartner.addProjekt(this); + this.projektthema.set(projektthema); } /** diff --git a/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Student.java b/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Student.java index 6890714..1ba6ed5 100644 --- a/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Student.java +++ b/src/de/fhswf/in/inf/se/projektthemenvergabe/model/Student.java @@ -23,6 +23,17 @@ public class Student private Projekt projekt; /** + * Constructor of {@link Student}. + * + * @param matrikelnummer + * Matrikelnummer of the Student. + */ + public Student(int matrikelnummer) + { + this.matrikelnummer.set(matrikelnummer); + } + + /** * * Getter for the property vorname. * diff --git a/src/de/fhswf/in/inf/se/projektthemenvergabe/view/AnsprechpartnerListeController.java b/src/de/fhswf/in/inf/se/projektthemenvergabe/view/AnsprechpartnerListeController.java index 4aee813..f14f5a1 100644 --- a/src/de/fhswf/in/inf/se/projektthemenvergabe/view/AnsprechpartnerListeController.java +++ b/src/de/fhswf/in/inf/se/projektthemenvergabe/view/AnsprechpartnerListeController.java @@ -74,9 +74,9 @@ public class AnsprechpartnerListeController if (!data.getNewValue().trim().isEmpty()) { Ansprechpartner tmpAns = new Ansprechpartner( - data.getRowValue().getOrganisation()); - tmpAns.setNachname(data.getRowValue().getNachname()); - tmpAns.setVorname(data.getNewValue().trim()); + data.getRowValue().getOrganisation(), + data.getNewValue().trim(), + data.getRowValue().getNachname()); if (!main.getAnsprechpartner().contains(tmpAns)) { @@ -98,9 +98,8 @@ public class AnsprechpartnerListeController if (!data.getNewValue().trim().isEmpty()) { Ansprechpartner tmpAns = new Ansprechpartner( - data.getRowValue().getOrganisation()); - tmpAns.setVorname(data.getRowValue().getVorname()); - tmpAns.setNachname(data.getNewValue().trim()); + data.getRowValue().getOrganisation(), + data.getRowValue().getVorname(), data.getNewValue().trim()); if (!main.getAnsprechpartner().contains(tmpAns)) { @@ -134,7 +133,7 @@ public class AnsprechpartnerListeController }); return data.getValue().organisationProperty(); } - return new SimpleObjectProperty<Organisation>(new Organisation()); + return new SimpleObjectProperty<Organisation>(new Organisation("")); }); organisationsNameTableColumn.setOnEditCommit((data) -> { data.getRowValue().setOrganisation(data.getNewValue()); @@ -183,8 +182,8 @@ public class AnsprechpartnerListeController Optional<String> result = dialog.showAndWait(); if (result.isPresent() && !result.get().trim().isEmpty()) { - Organisation organisation = new Organisation(); - organisation.setName(result.get().trim()); + Organisation organisation = new Organisation(result.get().trim()); + if (!main.getOrganisation().contains(organisation)) { main.getOrganisation().add(organisation); @@ -211,8 +210,8 @@ public class AnsprechpartnerListeController Optional<String> result = dialog.showAndWait(); if (result.isPresent() && !result.get().trim().isEmpty()) { - Organisation tmpOrg = new Organisation(); - tmpOrg.setName(result.get().trim()); + Organisation tmpOrg = new Organisation(result.get().trim()); + if (!main.getOrganisation().contains(tmpOrg)) { organisation.setName(tmpOrg.getName()); @@ -300,9 +299,8 @@ public class AnsprechpartnerListeController && !result.get().getValue().trim().isEmpty()) { Ansprechpartner ansprechpartner = new Ansprechpartner( - organisation); - ansprechpartner.setVorname(result.get().getKey().trim()); - ansprechpartner.setNachname(result.get().getValue().trim()); + organisation, result.get().getKey().trim(), + result.get().getValue().trim()); if (!main.getAnsprechpartner().contains(ansprechpartner)) { diff --git a/src/de/fhswf/in/inf/se/projektthemenvergabe/view/ProjektHinzufuegenController.java b/src/de/fhswf/in/inf/se/projektthemenvergabe/view/ProjektHinzufuegenController.java index cd0c673..5613526 100644 --- a/src/de/fhswf/in/inf/se/projektthemenvergabe/view/ProjektHinzufuegenController.java +++ b/src/de/fhswf/in/inf/se/projektthemenvergabe/view/ProjektHinzufuegenController.java @@ -173,12 +173,16 @@ public class ProjektHinzufuegenController { if (projekt == null) { - projekt = new Projekt(student1ComboBox.getValue(), - student2ComboBox.getValue(), student3ComboBox.getValue(), + projekt = new Projekt(projektthemaTextField.getText().trim(), + student1ComboBox.getValue(), student2ComboBox.getValue(), + student3ComboBox.getValue(), ansprechpartnerComboBox.getValue()); } + else + { + projekt.setProjektthema(projektthemaTextField.getText().trim()); + } - projekt.setProjektthema(projektthemaTextField.getText().trim()); projekt.setSkizze(projektskizzeTextField.getText().trim()); projekt.setProjektbeschreibung( projekthintergrundTextField.getText().trim()); diff --git a/src/de/fhswf/in/inf/se/projektthemenvergabe/view/StudentenverwaltungsController.java b/src/de/fhswf/in/inf/se/projektthemenvergabe/view/StudentenverwaltungsController.java index 5950b0a..0037124 100644 --- a/src/de/fhswf/in/inf/se/projektthemenvergabe/view/StudentenverwaltungsController.java +++ b/src/de/fhswf/in/inf/se/projektthemenvergabe/view/StudentenverwaltungsController.java @@ -112,8 +112,7 @@ public class StudentenverwaltungsController Optional<String> result = dialog.showAndWait(); if (result.isPresent() && !result.get().trim().isEmpty()) { - Student student = new Student(); - student.setMatrikelnummer( + Student student = new Student( Integer.parseInt(result.get().trim(), 10)); main.getStudenten().add(student); } |
