-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBot.java
More file actions
59 lines (43 loc) · 1.32 KB
/
Copy pathBot.java
File metadata and controls
59 lines (43 loc) · 1.32 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
package y2016.d10;
public class Bot implements Receiver {
private int number;
private Receiver highReceiver;
private Receiver lowReceiver;
private Integer value1;
private Integer value2;
public Bot(int number) {
this.number = number;
}
public void setHighReceiver(Receiver highReceiver) {
this.highReceiver = highReceiver;
passOnValues();
}
public void setLowReceiver(Receiver lowReceiver) {
this.lowReceiver = lowReceiver;
passOnValues();
}
public void setValue(Integer value) {
if (null == this.value1) {
this.value1 = value;
return;
}
if (null == this.value2) {
this.value2 = value;
} else {
throw new RuntimeException("we already have two values!");
}
passOnValues();
}
private void passOnValues() {
if (null == highReceiver || null == lowReceiver || null == value1 || null == value2) {
return; // not ready!
}
int max = Math.max(value1, value2);
int min = Math.min(value1, value2);
if (max == 61 && min == 17) {
System.out.println("Exit condition, bot number: " + number);
}
this.highReceiver.setValue(max);
this.lowReceiver.setValue(min);
}
}