From 2570ef20f91a60b03fe9b6ae54537fee8ae2eab0 Mon Sep 17 00:00:00 2001 From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:28:12 -0300 Subject: [PATCH] style: apply code formatter --- .../addons/localecombobox/LocaleComboBox.java | 63 +++++++++---------- .../LocaleCountryConverter.java | 10 +-- .../BaseLocaleComboBoxDemo.java | 3 +- .../localecombobox/DisplayModeDemo.java | 7 ++- .../addons/localecombobox/RenderingDemo.java | 6 +- 5 files changed, 41 insertions(+), 48 deletions(-) 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 706f205..ad2e6b0 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBox.java +++ b/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBox.java @@ -31,7 +31,7 @@ /** * Vaadin ComboBox extension that allows to choose between multiple locales. - * + * * @author Tomas Peiretti / Flowing Code */ @SuppressWarnings("serial") @@ -46,32 +46,32 @@ public class LocaleComboBox extends ComboBox { /** * Represents the built-in display modes for locale names in the {@link LocaleComboBox} component. - *

- * These enums can be used in {@link #setDisplayMode(DisplayMode)} to easily switch between the + * + *

These enums can be used in {@link #setDisplayMode(DisplayMode)} to easily switch between the * built-in display modes. */ public enum DisplayMode { /** * Default display mode. - *

- * In this mode, the Locale names are displayed using the default locale's display format. + * + *

In this mode, the Locale names are displayed using the default locale's display format. */ DEFAULT, /** * Selected display mode. - *

- * In this mode, the Locale names are displayed using the formatting of the currently selected - * locale. + * + *

In this mode, the Locale names are displayed using the formatting of the currently + * selected locale. */ SELECTED, /** * Custom display mode. - *

- * In this mode, the Locale names are displayed using the formatting of the specific locale set - * by {@link #setDisplayLocale(Locale)}. + * + *

In this mode, the Locale names are displayed using the formatting of the specific locale + * set by {@link #setDisplayLocale(Locale)}. */ CUSTOM; } @@ -79,14 +79,10 @@ public enum DisplayMode { private DisplayMode displayMode = DisplayMode.DEFAULT; private Locale customDisplayLocale; - /** - * Indicates whether the flags should be displayed alongside the locale names. - */ + /** Indicates whether the flags should be displayed alongside the locale names. */ private boolean hasFlags = true; - /** - * Creates a new instance of {@code LocaleComboBox}. - */ + /** Creates a new instance of {@code LocaleComboBox}. */ public LocaleComboBox() { setItemLabelGenerator(item -> item.getDisplayName(getLocaleForDisplay())); setRenderer(getLocaleRenderer()); @@ -95,7 +91,7 @@ public LocaleComboBox() { /** * Creates a new instance of {@code LocaleComboBox} with the desired locales - * + * * @param locales the {@code Collection} of {@code Locale} to include in the combobox */ public LocaleComboBox(Collection locales) { @@ -105,9 +101,8 @@ public LocaleComboBox(Collection locales) { /** * Sets the display mode of the LocaleComboBox. - * + * * @param displayMode the display mode to use - * * @see DisplayMode */ public void setDisplayMode(DisplayMode displayMode) { @@ -117,11 +112,11 @@ public void setDisplayMode(DisplayMode displayMode) { /** * Sets the locale used for formatting Locale names when {@link DisplayMode#CUSTOM} mode is * active. - *

- * This locale determines how Locale names are formatted when {@link DisplayMode#CUSTOM} is + * + *

This locale determines how Locale names are formatted when {@link DisplayMode#CUSTOM} is * selected as the display mode. If the display mode is any other than {@link DisplayMode#CUSTOM}, * this setting is ignored. - * + * * @param displayLocale the {@code Locale} to use for formatting. */ public void setDisplayLocale(Locale displayLocale) { @@ -139,10 +134,10 @@ public boolean hasFlags() { /** * Sets whether flags should be displayed alongside locale names. - *

- * This method updates the internal state to reflect whether flags should be displayed and updates - * the rendering based on the new state. - * + * + *

This method updates the internal state to reflect whether flags should be displayed and + * updates the rendering based on the new state. + * * @param hasFlags A {@code boolean} indicating whether flags should be displayed or not. */ public void setHasFlags(boolean hasFlags) { @@ -152,8 +147,7 @@ public void setHasFlags(boolean hasFlags) { } private LitRenderer getLocaleRenderer() { - return LitRenderer - .of( + return LitRenderer.of( """ @@ -167,17 +161,18 @@ private LitRenderer getLocaleRenderer() { } private LitRenderer getLocaleRendererWithoutFlags() { - return LitRenderer.of(""" + return LitRenderer.of( + """ ${item.displayName} - """).withProperty("layoutClass", loc -> ITEM_LAYOUT_CLASS_NAME) + """) + .withProperty("layoutClass", loc -> ITEM_LAYOUT_CLASS_NAME) .withProperty("displayName", loc -> loc.getDisplayName(getLocaleForDisplay())); } private Locale getLocaleForDisplay() { switch (displayMode) { - case CUSTOM: return Optional.ofNullable(customDisplayLocale).orElseGet(this::getLocale); @@ -191,7 +186,8 @@ private Locale getLocaleForDisplay() { private String getFlagCode(Locale locale) { String countryCode = locale.getCountry(); - return LocaleCountryConverter.convertToISO3166Code(countryCode).map(String::toLowerCase) + return LocaleCountryConverter.convertToISO3166Code(countryCode) + .map(String::toLowerCase) .orElse(DEFAULT_FLAG_CODE); } @@ -215,5 +211,4 @@ private void setPrefixFlag(Locale locale) { flagIcon.addClassNames("fi", "fi-" + this.getFlagCode(locale)); setPrefixComponent(flagIcon); } - } diff --git a/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleCountryConverter.java b/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleCountryConverter.java index 03c8495..23c72bb 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleCountryConverter.java +++ b/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleCountryConverter.java @@ -20,15 +20,13 @@ package com.flowingcode.vaadin.addons.localecombobox; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Optional; /** * Utility class for converting between different formats of country codes. * - *

- * The {@code LocaleCountryConverter} class provides methods to convert country codes from ISO + *

The {@code LocaleCountryConverter} class provides methods to convert country codes from ISO * 3166-1 alpha-2, alpha-3, and numeric-3 formats to the 3166-1 alpha-2 format. The class uses * static methods, so no instances are needed. * @@ -307,13 +305,11 @@ private static void add(String alpha2, String alpha3, int numeric) { * Converts a country code to its corresponding ISO 3166-1 alpha-2 code. * * @param countryCode The country code to be converted. This can be in ISO 3166-1 alpha-2 format - * (e.g., "AR"), ISO 3166-1 alpha-3 format (e.g., "ARG"), or numeric-3 format (e.g., - * "032"). + * (e.g., "AR"), ISO 3166-1 alpha-3 format (e.g., "ARG"), or numeric-3 format (e.g., "032"). * @return An {@code Optional} containing the ISO 3166-1 alpha-2 code if the conversion is - * successful. + * successful. */ public static Optional convertToISO3166Code(String countryCode) { return Optional.ofNullable(conversions.get(countryCode.toUpperCase())); } - } diff --git a/src/test/java/com/flowingcode/vaadin/addons/localecombobox/BaseLocaleComboBoxDemo.java b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/BaseLocaleComboBoxDemo.java index 3c65576..bb67604 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/localecombobox/BaseLocaleComboBoxDemo.java +++ b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/BaseLocaleComboBoxDemo.java @@ -23,9 +23,9 @@ import com.vaadin.flow.component.Text; import com.vaadin.flow.component.html.Div; import com.vaadin.flow.component.html.Span; -import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.orderedlayout.FlexComponent.Alignment; import com.vaadin.flow.component.orderedlayout.FlexComponent.JustifyContentMode; +import com.vaadin.flow.component.orderedlayout.HorizontalLayout; @SuppressWarnings("serial") public class BaseLocaleComboBoxDemo extends Div { @@ -45,5 +45,4 @@ protected HorizontalLayout createHorizontalContainer(Component component, Locale container.expand(combo); return container; } - } diff --git a/src/test/java/com/flowingcode/vaadin/addons/localecombobox/DisplayModeDemo.java b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/DisplayModeDemo.java index 8b1c1fb..bff5a4e 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/localecombobox/DisplayModeDemo.java +++ b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/DisplayModeDemo.java @@ -36,8 +36,10 @@ public class DisplayModeDemo extends BaseLocaleComboBoxDemo { public DisplayModeDemo() { List localeList = - Arrays.stream(Locale.getAvailableLocales()).filter(loc -> !loc.getDisplayName().isBlank()) - .sorted((l1, l2) -> l1.getDisplayName().compareTo(l2.getDisplayName())).toList(); + Arrays.stream(Locale.getAvailableLocales()) + .filter(loc -> !loc.getDisplayName().isBlank()) + .sorted((l1, l2) -> l1.getDisplayName().compareTo(l2.getDisplayName())) + .toList(); LocaleComboBox defaultDisplayLocale = new LocaleComboBox(localeList); LocaleComboBox koreanLocaleCombo = new LocaleComboBox(); @@ -63,5 +65,4 @@ public DisplayModeDemo() { // show-source add(koreanLocaleCombo); // show-source add(selectedLocaleCombo); } - } diff --git a/src/test/java/com/flowingcode/vaadin/addons/localecombobox/RenderingDemo.java b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/RenderingDemo.java index 2d74651..fbe8cd3 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/localecombobox/RenderingDemo.java +++ b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/RenderingDemo.java @@ -35,8 +35,10 @@ public class RenderingDemo extends BaseLocaleComboBoxDemo { public RenderingDemo() { List localeList = - Arrays.stream(Locale.getAvailableLocales()).filter(loc -> !loc.getDisplayName().isBlank()) - .sorted((l1, l2) -> l1.getDisplayName().compareTo(l2.getDisplayName())).toList(); + Arrays.stream(Locale.getAvailableLocales()) + .filter(loc -> !loc.getDisplayName().isBlank()) + .sorted((l1, l2) -> l1.getDisplayName().compareTo(l2.getDisplayName())) + .toList(); LocaleComboBox defaultLocaleCombo = new LocaleComboBox(localeList); LocaleComboBox flagsLocaleCombo = new LocaleComboBox(localeList);