Optimize the ConfigType.isValidType method (#5434)

* fix #5432 Optimize the ConfigType.isValidType method

* code format
This commit is contained in:
xiaoheng1 2021-04-23 09:48:45 +08:00 committed by GitHub
parent 103e671d90
commit b1e78b6f6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,9 @@ package com.alibaba.nacos.api.config;
import com.alibaba.nacos.api.utils.StringUtils;
import java.util.HashMap;
import java.util.Map;
/**
* Config data type.
*
@ -60,7 +63,15 @@ public enum ConfigType {
*/
UNSET("unset");
String type;
private final String type;
private static final Map<String, ConfigType> LOCAL_MAP = new HashMap<String, ConfigType>();
static {
for (ConfigType configType : values()) {
LOCAL_MAP.put(configType.getType(), configType);
}
}
ConfigType(String type) {
this.type = type;
@ -84,11 +95,6 @@ public enum ConfigType {
if (StringUtils.isBlank(type)) {
return false;
}
for (ConfigType value : values()) {
if (value.type.equals(type)) {
return true;
}
}
return false;
return null != LOCAL_MAP.get(type) ? true : false;
}
}