summaryrefslogtreecommitdiffstats
path: root/src/de/fhswf/in/inf/java1/aufgabe05/Person.java
blob: 18b619d9fe6b871b401909d76666da651f97027d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
 * 
 */
package de.fhswf.in.inf.java1.aufgabe05;

import java.util.ArrayList;
import java.util.List;

/**
 * A person which can own an account.
 *
 * @author $Author: $
 * @version $Revision: $, $Date: $ UTC
 */
public class Person
{
   private String vorname;

   private String nachname;

   private List<Konto> kontenliste = new ArrayList<>();

   /**
    * Creates a person with first and last name.
    *
    * @param vorname
    *           First name of the person
    * @param nachname
    *           Last name of the person
    */
   public Person(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.vorname = vorname;
      this.nachname = nachname;
   }

   /**
    * Just for getting the persons name.
    *
    * @return Returns the full name of the person
    */
   @Override
   public String toString()
   {
      return vorname + " " + nachname;
   }

   /**
    * For adding the back reference to the Konto.
    *
    * @param konto
    *           Konto that will be added to the person.
    */
   public void addKonto(Konto konto)
   {
      if (konto == null)
      {
         throw new IllegalArgumentException("Konto can't be empty");
      }
      if (konto.getBesitzer() != this)
      {
         throw new IllegalArgumentException("Person must be owner of Konto");
      }
      if (!kontenliste.contains(konto))
      {
         kontenliste.add(konto);
      }
   }

}