Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the ConfigType.isValidType method #5434

Merged
merged 2 commits into from
Apr 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}