Skip to content
Snippets Groups Projects
Channel.java 2.3 KiB
Newer Older
package nloc;
import java.util.ArrayList;
import java.util.List;
Peter Wagenhuber's avatar
Peter Wagenhuber committed
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Arrays;

public class Channel extends NlocEntity implements Comparable<Channel> {
  private int pSteps, hSteps;
Peter Wagenhuber's avatar
Peter Wagenhuber committed
  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>();
Peter Wagenhuber's avatar
Peter Wagenhuber committed
    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;
  }

  public void removeDroplet(Droplet droplet) {
    dropletList.remove(droplet);
  }

  public void addDroplet(Droplet droplet) {
    dropletList.add(droplet);
  }

  public void setDropletList(List<Droplet> dropletList) {
    this.dropletList = dropletList;
  }

  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;
  }

Peter Wagenhuber's avatar
Peter Wagenhuber committed
  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;
    }
  }
}