java - 模型类的圈复杂度
问题描述
任何人都可以帮助我理解为什么我的模型类的圈复杂度为 89。当我运行 PMD 时,它给了我“类 'GetResponse' 的总圈复杂度为 89(最高 1)”。
请找到代码片段:
public class GetResponse {
private String ewbNo;
private String ewayBillDate;
private String genMode;
private String userGstin;
private String supplyType;
private String subSupplyType;
private String docType;
private String docNo;
private String docDate;
private String fromGstin;
private String fromTrdName;
private String fromAddr1;
private String fromAddr2;
private String fromPlace;
private String fromPincode;
private String fromStateCode;
private String toGstin;
private String toTrdName;
private String toAddr1;
private String toAddr2;
private String toPlace;
private String toPincode;
private String toStateCode;
private Float totalValue;
private Float totInvValue;
private Float cgstValue;
private Float sgstValue;
private Float igstValue;
private Float cessValue;
private String transporterId;
private String transporterName;
private String transDocNo;
private String transMode;
private String transDocDate;
private String status;
private Integer actualDist;
private Integer noValidDays;
private String validUpto;
private Integer extendedTimes;
private String rejectStatus;
private String vehicleType;
private String actFromStateCode;
private String actToStateCode;
private Object itemList;
private Object VehiclListDetails;
//getters and setters
}
解决方案
根据维基百科页面:
[圈] 复杂度 M 是 [] 定义为
M = E − N + 2P,
在哪里
E = the number of edges of the graph. N = the number of nodes of the graph. P = the number of connected components.
据我统计,您的班级有 44 个字段,以及(我假设)每个字段的 getter 和 setter。
典型的 getter 如下所示:
public T getX() { return x; }
这具有圈复杂度1。
一个典型的 setter 如下所示:
public void setX(T x) { this.x = x; }
这也有圈复杂度1。
最后,如果我们将字段声明视为一系列语句,即具有 44 个节点和 43 条边(并且没有连通分量)的图,复杂度为 1。
因此,整个类的聚合圈复杂度为44 x 1 + 44 x 1 + 1 == 89
。
推荐阅读
- python - 在熊猫系列字符串中定位确切的术语
- excel - 将电子邮件功能添加到 Excel 搜索
- json - 按分钟生成时间戳并按每分钟计算唯一性总和
- sql-server - 有什么方法可以删除此“For XML Path”查询的重复项?
- c++ - 在字符串c ++中查找关键字
- gemfire - GemFire 查询在运行几个小时后逐渐变慢
- javascript - 即使有些没有空行,也可以在多张纸上删除行脚本
- entity-framework - 在多对多表中连接 Id - 实体框架
- javascript - 如何在 Javascript 中修改计算的字体大小
- c++ - 多线程函数性能比单线程差