-
Notifications
You must be signed in to change notification settings - Fork 0
/
Company.java
92 lines (73 loc) · 1.96 KB
/
Company.java
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
87
88
89
90
91
92
import java.util.ArrayList;
import java.util.List;
public class Company implements Subject {
private int id;
private String name;
private Person admin;
private final List<Person> members;
private final List<Career> careers;
private final List<Observer> observers;
public Company(int id, String name, Person admin) {
this.id = id;
this.name = name;
this.admin = admin;
members = new ArrayList<>();
careers = new ArrayList<>();
observers = new ArrayList<>();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Person getAdmin() {
return admin;
}
public void setAdmin(Person admin) {
this.admin = admin;
}
public List<Person> getMembers() {
return members;
}
public void addMember (Person person) {
members.add(person);
registerObserver(person);
}
public void addCareer (Career career) {
careers.add(career);
notifyObservers(career);
}
public List<Career> getCareers() {
return careers;
}
public void removeMember(Person person) {
members.remove(person);
removeObserver(person);
}
public List<Observer> getObservers() {
return observers;
}
@Override
public void registerObserver(Observer o) {
observers.add(o);
}
@Override
public void removeObserver(Observer o) {
observers.remove(o);
}
@Override
public void notifyObservers(Career career) {
observers.forEach(observer -> observer.update(career));
}
@Override
public String toString() {
return "Company{" + "id=" + id + ", name=" + name + ", members count=" + members.size() + ", careers count=" + careers.size() + '}';
}
}