From b1e78b6f6d18cb9c8e7837a1ca370855b238ebab Mon Sep 17 00:00:00 2001 From: xiaoheng1 <2018154970@qq.com> Date: Fri, 23 Apr 2021 09:48:45 +0800 Subject: [PATCH] Optimize the ConfigType.isValidType method (#5434) * fix #5432 Optimize the ConfigType.isValidType method * code format --- .../alibaba/nacos/api/config/ConfigType.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/com/alibaba/nacos/api/config/ConfigType.java b/api/src/main/java/com/alibaba/nacos/api/config/ConfigType.java index cab303b35..4df813b29 100644 --- a/api/src/main/java/com/alibaba/nacos/api/config/ConfigType.java +++ b/api/src/main/java/com/alibaba/nacos/api/config/ConfigType.java @@ -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 LOCAL_MAP = new HashMap(); + + 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; } }