Newer
Older
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
package nloc;
import java.util.List;
import java.util.ArrayList;
import java.util.ListIterator;
public class Position {
private Channel chan;
private int step;
public Position (Channel chan, int step) {
this.chan = chan;
this.step = step;
}
public int getSteps() {
return step;
}
public Channel getChannel() {
return chan;
}
public void setSteps(int step) {
this.step = step;
}
public void setChannel(Channel chan) {
this.chan = chan;
}
public void increment(Droplet droplet) {
int chansteps = 0;
if (droplet.getType() == DropletType.PAYLOAD) {
chansteps = chan.getPSteps();
} else {
chansteps = chan.getHSteps();
}
if (this.step < chansteps) {
this.step++;
} else {
this.step = 1;
List<Channel> possibleChannels = chan.getChildrenList();
if (!possibleChannels.isEmpty() && possibleChannels.size() == 1) {
this.chan = possibleChannels.get(0);
} else {
this.chan = getFollowingChannel(possibleChannels);
}
}
}
private Channel getFollowingChannel(List<Channel> possibleChannels) {
/**
* If possibleChannels.size() > 1 we are at a bifurcation.
* The droplet takes the first Channel that doesn't contain a droplet.
* The list of channels is already ordered by length and thus the
* priority.
*/
Channel following = null;
for (Channel ch : possibleChannels) {
if (!ch.containsDroplets()) {
following = ch;
}
}
if (following == null) {
ListIterator<Channel> iter = possibleChannels.listIterator();
following = iter.next();
while (iter.hasNext()) {
Channel temp = iter.next();
if (following.getLastDropletDistance() < temp.getLastDropletDistance())
{
following = temp;
}
}
}
return following;
}
}