Skip to content

Commit

Permalink
Optimize the ConfigType.isValidType method (#5434)
Browse files Browse the repository at this point in the history
* fix #5432 Optimize the ConfigType.isValidType method

* code format
  • Loading branch information
xiaoheng1 committed Apr 23, 2021
1 parent 103e671 commit b1e78b6
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions api/src/main/java/com/alibaba/nacos/api/config/ConfigType.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import com.alibaba.nacos.api.utils.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
* Config data type.
*
Expand Down Expand Up @@ -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;
Expand All @@ -84,11 +95,6 @@ public static Boolean isValidType(String type) {
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;
}
}

0 comments on commit b1e78b6

Please sign in to comment.