package models.dataFlowModel;
import java.util.HashSet;
import java.util.Set;
import models.Node;
public class ChannelNode extends Node {
protected ChannelNode parent = null;
protected Set<ChannelNode> children = null;
protected DataTransferChannel channel = null;
public ChannelNode(ChannelNode parent, DataTransferChannel channel) {
this.parent = parent;
this.channel = channel;
this.children = new HashSet<>();
}
public ChannelNode getParent() {
return parent;
}
public Set<ChannelNode> getChildren() {
return children;
}
public Set<ChannelNode> getAncestors(){
if (parent == null) {
return new HashSet<>();
}
Set<ChannelNode> ancestors = parent.getAncestors();
ancestors.add(parent);
return ancestors;
}
public Set<ChannelNode> getDescendants() {
if (children == null) {
return new HashSet<>();
}
Set<ChannelNode> descendants = new HashSet<>();
for (ChannelNode child: children) {
descendants.addAll(child.getDescendants());
descendants.add(child);
}
return descendants;
}
public void addChild(ChannelNode child) {
children.add(child);
child.parent = this;
}
public DataTransferChannel getChannel() {
return channel;
}
public void setChannel(DataTransferChannel channel) {
this.channel = channel;
}
}