File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
src/main/java/com/flowingcode/vaadin/addons/localecombobox Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 2727import com .vaadin .flow .data .renderer .LitRenderer ;
2828import java .util .Collection ;
2929import java .util .Locale ;
30+ import java .util .Optional ;
3031
3132/**
3233 * Vaadin ComboBox extension that allows to choose between multiple locales.
@@ -76,7 +77,7 @@ public enum DisplayMode {
7677 }
7778
7879 private DisplayMode displayMode = DisplayMode .DEFAULT ;
79- private Locale customDisplayLocale = Locale . getDefault () ;
80+ private Locale customDisplayLocale ;
8081
8182 /**
8283 * Indicates whether the flags should be displayed alongside the locale names.
@@ -124,7 +125,7 @@ public void setDisplayMode(DisplayMode displayMode) {
124125 * @param displayLocale the {@code Locale} to use for formatting.
125126 */
126127 public void setDisplayLocale (Locale displayLocale ) {
127- this .customDisplayLocale = displayLocale == null ? Locale . getDefault () : displayLocale ;
128+ this .customDisplayLocale = displayLocale ;
128129 }
129130
130131 /**
@@ -178,13 +179,13 @@ private Locale getLocaleForDisplay() {
178179 switch (displayMode ) {
179180
180181 case CUSTOM :
181- return customDisplayLocale ;
182+ return Optional . ofNullable ( customDisplayLocale ). orElseGet ( this :: getLocale ) ;
182183
183184 case SELECTED :
184- return this .getValue () == null ? Locale . getDefault () : this . getValue ( );
185+ return Optional . ofNullable ( this .getValue ()). orElseGet ( this :: getLocale );
185186
186187 default :
187- return Locale . getDefault ();
188+ return this . getLocale ();
188189 }
189190 }
190191
You can’t perform that action at this time.
0 commit comments