Author:赵志乾
Date:2024-06-14
Declaration:All Right Reserved!!!
1. 类图
2. 原理解析
2.1 核心函数
FlowchartPort继承Port类,并定义了一系列抽象函数;核心函数如下:
函数 | 功能 |
FlowchartPort(FlowchartBlock owner) | 构造函数,入参指定Port所属的FlowchartBlock;FlowchartBlock继承自Agent; |
abstract long count() | 获取到目前为止通过该端口的Agent个数; |
abstrack void markError() abstract boolean isError() | 标注端口发生错误 判定端口是否发生错误 |
boolean isReadyToExit() boolean isCannotAccept() | 用于输出端口判定是否有Agent准备离开 用于输入端口判定此刻是否不能接收Agent |
FlowchartBlock getFlowchartBlockRepresentative() | 对于owner为内部block时,获取owner的owner;属于内部函数,不建议用户调用; |
2.2 代码解析
//******************核心字段************************
// 非内部block为null,内部block为owner的owner;
private FlowchartBlock representativeOwner;
//*******************构造函数************************
public FlowchartPort(FlowchartBlock owner) {
super(owner);
}
//*******************抽象方法,需由子类实现**************
public abstract long count();
public abstract void markError();
public abstract boolean isError();
//*******************默认实现,子类一般会覆写************
public boolean isReadyToExit() {
return false;
}
public boolean isCannotAccept() {
return false;
}
//*******************获取owner************************
//获取端口直接归属的owner
public FlowchartBlock getAgent() {
return (FlowchartBlock)super.getAgent();
}
//对于直接归属的owner为内部block时,获取owner的ownerBlock
public FlowchartBlock getFlowchartBlockRepresentative() {
if (this.representativeOwner == null) {
this.representativeOwner = this.getAgent().getFlowchartBlockRepresentative();
if (this.representativeOwner == null) {
this.markError();
this.getAgent().error("Internal error: this block has been set as 'internal block' but it has no 'not internal' owner");
}
}
return this.representativeOwner;
}
3. 应用场景
FlowchartPort是流图组件端口的基类,一般不会直接使用;如果需要自行封装组件库时会用到;