-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed useless hardcoded Strings in
EnvUtils
. (#4007)
- Loading branch information
1 parent
44f4b8b
commit 2097301
Showing
2 changed files
with
58 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,31 +18,46 @@ | |
|
||
import com.ctrip.framework.apollo.core.utils.StringUtils; | ||
|
||
/** | ||
* A utility class for the {@link Env} enum. | ||
* <p> | ||
* The class provides simple functionalities that extend the capabilities of {@link Env} | ||
* | ||
* @author Diego Krupitza([email protected]) | ||
*/ | ||
public final class EnvUtils { | ||
|
||
|
||
/** | ||
* Transforms a given String to its matching {@link Env} | ||
* | ||
* @param envName the String to convert | ||
* @return the matching {@link Env} for the given String | ||
*/ | ||
public static Env transformEnv(String envName) { | ||
if (StringUtils.isBlank(envName)) { | ||
return Env.UNKNOWN; | ||
} | ||
switch (envName.trim().toUpperCase()) { | ||
case "LPT": | ||
return Env.LPT; | ||
case "FAT": | ||
case "FWS": | ||
return Env.FAT; | ||
case "UAT": | ||
return Env.UAT; | ||
case "PRO": | ||
case "PROD": //just in case | ||
return Env.PRO; | ||
case "DEV": | ||
return Env.DEV; | ||
case "LOCAL": | ||
return Env.LOCAL; | ||
case "TOOLS": | ||
return Env.TOOLS; | ||
default: | ||
return Env.UNKNOWN; | ||
|
||
String cleanedEnvName = envName.trim().toUpperCase(); | ||
|
||
// fix up in case there is a typo | ||
// like prod/pro | ||
if (cleanedEnvName.equals("PROD")) { | ||
return Env.PRO; | ||
} | ||
|
||
if (cleanedEnvName.equals("FWS")) { | ||
// special case that FAT & FWS | ||
// should return the same | ||
return Env.FAT; | ||
} | ||
|
||
try { | ||
return Env.valueOf(cleanedEnvName); | ||
} catch (IllegalArgumentException e) { | ||
// the name could not be found | ||
// or there is a typo we dont handle | ||
return Env.UNKNOWN; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters