Skip to content
Snippets Groups Projects
Channel.java 2.99 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(String name, int pSteps, int hSteps) {
    super(name);
    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 (dropletList.isEmpty()) {
      // Sort dropletlist accoring to droplet position (smallest position first)
      dropletList.sort((d1,d2) -> 
          d1.getPosition().getSteps() - d2.getPosition().getSteps());
      minDist = dropletList.get(0).getPosition().getSteps();

      //for (Droplet dr : dropletList) {
      //  int dist = dr.getPosition().getSteps();
      //  if (dist < minDist) {
      //    minDist = dist;
      //  }  
      //}
  public int getMinSteps() {
    int minsteps = 0;
    if (pSteps < hSteps) {
      minsteps = pSteps;
    } else {
      minsteps = hSteps;
    }
    return minsteps;
  }

  public List<Droplet> getNormalizedSortedDropletList() {
    dropletList.sort((d1,d2) -> 
        d1.getNormalizedSteps() - d2.getNormalizedSteps());
    return dropletList;
  }

  public List<Droplet> getDropletList() {
    return dropletList;
  }

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