diff --git a/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBox.java b/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBox.java index 645cc02..9992407 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBox.java +++ b/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBox.java @@ -27,6 +27,7 @@ import com.vaadin.flow.data.renderer.LitRenderer; import java.util.Collection; import java.util.Locale; +import java.util.Optional; /** * Vaadin ComboBox extension that allows to choose between multiple locales. @@ -76,7 +77,7 @@ public enum DisplayMode { } private DisplayMode displayMode = DisplayMode.DEFAULT; - private Locale customDisplayLocale = Locale.getDefault(); + private Locale customDisplayLocale; /** * Indicates whether the flags should be displayed alongside the locale names. @@ -124,7 +125,7 @@ public void setDisplayMode(DisplayMode displayMode) { * @param displayLocale the {@code Locale} to use for formatting. */ public void setDisplayLocale(Locale displayLocale) { - this.customDisplayLocale = displayLocale == null ? Locale.getDefault() : displayLocale; + this.customDisplayLocale = displayLocale; } /** @@ -178,13 +179,13 @@ private Locale getLocaleForDisplay() { switch (displayMode) { case CUSTOM: - return customDisplayLocale; + return Optional.ofNullable(customDisplayLocale).orElseGet(this::getLocale); case SELECTED: - return this.getValue() == null ? Locale.getDefault() : this.getValue(); + return Optional.ofNullable(this.getValue()).orElseGet(this::getLocale); default: - return Locale.getDefault(); + return this.getLocale(); } }