我想知道如何降低以下代码的循环复杂度,如果这甚至是我应该担心的事情。
请参考方法 ValuePojo.getSomething() (请不要担心变量命名,为了清楚起见,本问题已重新编写)
public class ValuePojo
{
private ValueTypeEnum type;
private BigDecimal value1;
private BigDecimal value2;
private BigDecimal value3;
public ValuePojo()
{
super();
}
/**
* This method reports as "HIGH Cyclomatic Complexity"
*
* @return
*/
public BigDecimal getSomething()
{
if (this.type == null)
{
return null;
}
switch (this.type)
{
case TYPE_A:
case TYPE_B:
case TYPE_C:
case TYPE_D:
return this.value1;
case TYPE_E:
case TYPE_F:
case TYPE_G:
case TYPE_H:
return this.value2;
case TYPE_I:
case TYPE_J:
return this.value3;
}
return null;
}
}