-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContentCreator.java
More file actions
65 lines (53 loc) · 1.68 KB
/
ContentCreator.java
File metadata and controls
65 lines (53 loc) · 1.68 KB
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
package proiect;
import java.util.ArrayList;
import java.util.List;
//The Subject interface
interface Subject {
void follow(Follower observer);
void unfollow(Follower observer);
void notifyObservers();
}
public class ContentCreator implements Subject,Person {
private final String name; //numele canalului
private final List<Follower> followers; //lista tuturor abonatilor
private String lastContent; //numele continutului cel mai nou(videoclip etc.)
public ContentCreator(String name) {
this.name = name;
followers = new ArrayList<>();
}
public String getName() {
return name;
}
//posteaza continut nou
public void setContent(String content) {
this.lastContent = content;
notifyObservers();
}
//obtine cel mai nou continut
public String getContent() {
return lastContent;
}
//adauga la lista de abonati a creatorului
public void follow(Follower subscriber) {
followers.add(subscriber);
}
//elimina din lista de abonati a creatorului
public void unfollow(Follower subscriber) {
followers.remove(subscriber);
}
//trimite notificari abonatilor
@Override
public void notifyObservers() {
for (Follower subscriber : followers) {
subscriber.update(lastContent);
}
}
//lista abonati
public String [] getFollowers() {
String[] names = new String[followers.size()];
for (int i = 0; i < followers.size(); i++) {
names[i] = (followers.get(i)).getName();
}
return names;
}
}