dimanche 6 novembre 2016

Does using a map truly reduce cyclomatic complexity?

Suppose I have the original method below.

public String someMethod(String str) {
    String returnStr;
    if("BLAH".equals(str)) { 
       returnStr="ok";
    } else if ("BLING".equals(str)) {
       returnStr="not ok";
    } else if ("BONG".equals(str)) {
       returnStr="ok";
    }
    return returnStr;
}

Does converting to below truly reduce CC?

Map<String, String> validator = new HashMap<String,String>();
validator.put("BLAH","ok");
validator.put("BLING","not ok");
validator.put("BONG","ok");

public String someMethod(String str) {
  return validator.get(str);
}

Aucun commentaire:

Enregistrer un commentaire