Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 模型类的圈复杂度_Java_Static Analysis_Code Metrics_Cyclomatic Complexity - Fatal编程技术网

Java 模型类的圈复杂度

Java 模型类的圈复杂度,java,static-analysis,code-metrics,cyclomatic-complexity,Java,Static Analysis,Code Metrics,Cyclomatic Complexity,谁能帮助我理解为什么我的模型类的圈复杂度为89。 当我运行PMD时,它会告诉我“类“GetResponse”的总圈复杂度为89(最高1)” 请按以下方式查找代码段: public class GetResponse { private String ewbNo; private String ewayBillDate; private String genMode; private String userGstin; private String supplyType; private Str

谁能帮助我理解为什么我的模型类的圈复杂度为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
}
根据:

[cyclomatic]复杂性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; }
  public void setX(T x) { this.x = x; }
这有圈复杂度1

典型的setter如下所示:

  public T getX() { return x; }
  public void setX(T x) { this.x = x; }
这也有圈复杂度1

最后,如果我们把字段声明看作是一个语句序列,那就是一个图,它有44个节点和43个边(并且没有),使得复杂性为1。


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

@YCF\u L。谢谢你的回复。你能详细解释一下吗?实际上我对代码分析还不太熟悉。谢谢你这么好的解释。但我能减少它吗?当然。减少字段的数量。去掉任何不需要的setter。但是在你做这件事之前,问问你自己,通过减少圈复杂度,你将真正实现什么。请记住,CC只是一种启发式方法,用于识别可能存在可维护性问题的代码。