Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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();
}
}

Expand Down