Newer
Older

Peter Joseph De Jonckheere CESM2014
committed
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
package com.example.stimulus;
import com.example.notification.Notification;
import com.example.notification.SedentaryNotification;
import com.example.stimulusStrategy.StimulusStrategy;
import java.util.Observable;
/**
* Created by pharmacy on 09/01/2018.
*/
class SedentaryStimulus implements Stimulus {
private StimulusStrategy strategy;
public SedentaryStimulus(){
chooseStrategy(null);
}
public SedentaryStimulus(StimulusStrategy s){
chooseStrategy(s);
}
public Notification createNotification() {
Notification notification = new SedentaryNotification();
//Either further define this notification here or change to one line;
return notification;
}
public void chooseStrategy(StimulusStrategy s) {
if(s != null){
strategy = s;
} else{
strategy = defaultStrategy;
}
strategy.addObserver(this);
}
@Override
//Called by notify and will create Notification if required then send
public void update(Observable observable, Object o) {
//If a condition - such as time elapsed since last notification or not night time
Notification notification = createNotification();
notification.send();
}
}