Something went wrong on our end
Forked from
Peter Wagenhuber / droplet-sequence-generator
1 commit behind the upstream repository.
-
Peter Wagenhuber authored
die coalesce funktion muss noch ueberarbeitet werden vorallem wenn der naechste channel ein modul ist und ein payload und ein header modul verglichen werden
Peter Wagenhuber authoreddie coalesce funktion muss noch ueberarbeitet werden vorallem wenn der naechste channel ein modul ist und ein payload und ein header modul verglichen werden
Position.java 2.59 KiB
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;
}
// create a new position object to be able to create a new dropletlist to
// avoid concurrent modification errors
public void increment(Droplet droplet) {
if (!droplet.isInSink()) {
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 = this.chan.getChildrenList();
if (!possibleChannels.isEmpty() && possibleChannels.size() == 1) {
//this.chan.removeDroplet(droplet);
this.chan = possibleChannels.get(0);
this.chan.addDroplet(droplet);
} else {
Channel temp = this.chan;
if (chan instanceof Pump) {
this.chan = droplet.getPumpOutlet();
} else {
this.chan = getFollowingChannel(possibleChannels);
}
//temp.removeDroplet(droplet);
this.chan.addDroplet(droplet);
}
}
}
}
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;
}
public static boolean isOccupied(List<Droplet> dropletList,
int currentPos) {
boolean occupied = false;
for (Droplet dr: dropletList) {
Position drPos = dr.getPosition();
if (currentPos == drPos.getSteps()) {
occupied = true;
}
}
return occupied;
}
}