gpt4 book ai didi

java - 模型类的循环复杂度

转载 作者:行者123 更新时间:2023-11-30 01:44:23 25 4
gpt4 key购买 nike

任何人都可以帮助我理解为什么我的模型类的圈复杂度为 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
}

最佳答案

根据Wikipedia page :

The [cyclomatic] complexity M is [] defined as

M = E − N + 2P,

where

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 条边的图(并且没有 connected components ),复杂度为 1。

因此,整个类的聚合圈复杂度为 44 x 1 + 44 x 1 + 1 == 89

关于java - 模型类的循环复杂度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58694444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com