【发布时间】:2017-10-25 03:51:46
【问题描述】:
我有这个示例代码
public static ActionProcessable getActionProcessor(TaskType currentTaskType, UserAction userAction){
String actionKey;
if(userAction != null){
if(currentTaskType != null){
actionKey = buildKey(currentTaskType, userAction);
if(dossierActions.containsKey(actionKey)){
return dossierActions.get(actionKey);
}
}
actionKey = buildKey(anyTaskType(), userAction);
if(dossierActions.containsKey(actionKey)){
return dossierActions.get(actionKey);
}
}
return new NullActionProcessor();
}
在这个逻辑中,我有一个映射来通过组合键 TaskType 和 UserAction 存储 ActionProcessable。此方法将返回带有输入 taskType 和操作的 ActionProcessable。 TaskType 可以为 null,所以在这种情况下,我们只需要通过 userAction 获取。
当我通过声纳检查此代码时,它说第三个 if 是“嵌套 if-else 深度为 2(允许的最大值为 1)”
但我不知道如何让它变得更好。 有人给我建议吗?
【问题讨论】: