Skip to content

Commit

Permalink
Optimize!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
raphkim authored and jamesonwilliams committed Apr 3, 2020
1 parent 8e4a498 commit c98ac18
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,36 @@ public enum LanguageType {
* @return An enum value of matching language code
*/
public static LanguageType from(String languageCode) {
// Micro-optimization... for fun :)
// https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers
switch (languageCode) {
case "zh":
return CHINESE_SIMPLIFIED;
case "zh-TW":
return CHINESE_TRADITIONAL;
case "es":
return SPANISH;
case "en":
return ENGLISH;
case "hi":
return HINDI;
case "bn":
return BENGALI;
case "pt":
return PORTUGUESE;
case "ru":
return RUSSIAN;
case "ja":
return JAPANESE;
case "pa":
return PUNJABI;
case "mr":
return MARATHI;
default:
// Move on... your language isn't popular
}

// Linear-search for rest
for (LanguageType language : values()) {
if (language.getLanguageCode().equals(languageCode)) {
return language;
Expand Down

0 comments on commit c98ac18

Please sign in to comment.