package nloc; import java.util.ArrayList; import java.util.List; import java.util.SortedSet; import java.util.TreeSet; import java.util.Arrays; public class Channel extends NlocEntity implements Comparable<Channel> { private int pSteps, hSteps; private List<Channel> parents; private SortedSet<Channel> children; private List<Droplet> dropletList; public Channel(int pSteps, int hSteps) { super(); this.pSteps = pSteps; this.hSteps = hSteps; this.parents = new ArrayList<Channel>(); this.children = new TreeSet<Channel>(); this.dropletList = new ArrayList<Droplet>(); } public boolean containsDroplets() { return !dropletList.isEmpty(); } public int getLastDropletDistance() { int minDist = Integer.MAX_VALUE; if (!this.containsDroplets()) { minDist = -1; } else { for (Droplet dr : dropletList) { int dist = dr.getPosition().getSteps(); if (dist < minDist) { minDist = dist; } } } return minDist; } protected void setHSteps(int hSteps) { this.hSteps = hSteps; } protected void setPSteps(int pSteps) { this.pSteps = pSteps; } public int getPSteps() { return pSteps; } public int getHSteps() { return hSteps; } public void addChild(Channel child) { if (!children.contains(child)) { children.add(child); child.addParent(this); } } public void addParent(Channel parent) { if (!parents.contains(parent)) { parents.add(parent); parent.addChild(this); } } public List<Channel> getChildrenList() { return Arrays.asList(children.toArray(new Channel[0])); } public List<Channel> getParents() { return parents; } public boolean isBifurcation() { return children.size() > 1; } public boolean isTeeIntersect() { return parents.size() > 1; } public int compareTo(Channel other) { if (this.getPSteps() < other.getPSteps()) { return -1; } else if (this.getPSteps() == other.getPSteps()) { return 0; } else { return 1; } } }