1
私はこのようなクラスを持っている:複雑()メソッド
public static returnCode fromValue(String code) {
for (returnCode returnCode : returnCode.values()) {
if (returnCode .code.equals(code)) {
return returnCode ;
}
}
}
それので:私はちょうど複雑さの点で知りたい
public enum ReturnCode{
Code1(
"Code1",
"Return this code when there is an erreur"
),
Code2(
"Code2",
"Return this code when everything ok"
);
ReturnCode(final String code, final String detail) {
this.code = code;
this.detail = detail;
}
private static Map<String, ReturnCode> map =
new HashMap<String, ReturnCode>();
static {
for (ReturnCode returnCode : ReturnCode.values()) {
map.put(returnCode.code, returnCode);
}
}
public static ReturnCode fromValue(String code) {
return map.get(code);
}
、それがより優れています私たちは最初のメソッドからfromValueを呼び出すたびに、それはすべてO(n)であるので、マップを生成しますか?
ありがとうございました。