@JsonIgnore public static LocalizedString of(final Locale locale, final String value) { return new LocalizedString(locale, value); }
/** * Creates an instance by supplying a map of {@link Locale} and {@link String}. Changes to the map won't affect the instance. * * {@include.example io.sphere.sdk.models.LocalizedStringTest#createByMap()} * * @param translations the key value pairs for the translation * @return a new instance which has the same key value pairs as {@code translation} at creation time */ @JsonIgnore public static LocalizedString of(final Map<Locale, String> translations) { requireNonNull(translations); return new LocalizedString(translations); }
/** * LocalizedString containing the given entries. * @param locale the additional locale of the new entry * @param value the value for the <code>locale</code> * @return a LocalizedString containing this data and the from the parameters. * @throws IllegalArgumentException if duplicate locales are provided */ public LocalizedString plus(final Locale locale, final String value) { final Map<Locale, String> newMap = new ImmutableMap.Builder<Locale, String>(). putAll(translations). put(locale, value). build(); return new LocalizedString(newMap); }
/** * Creates a new {@link LocalizedString} containing the given entries and the new one. * It is not allowed to override existing entries. * * {@include.example io.sphere.sdk.models.LocalizedStringTest#createANewLocalizedStringByAddingALocale()} * * @param locale the additional locale of the new entry * @param value the value for the <code>locale</code> * @return a LocalizedString containing this data and the from the parameters. * @throws IllegalArgumentException if duplicate locales are provided */ public LocalizedString plus(final Locale locale, final String value) { if (translations.containsKey(locale)) { throw new IllegalArgumentException(format("Duplicate keys (%s) for map creation.", locale)); } final Map<Locale, String> newMap = new HashMap<>(); newMap.putAll(translations); newMap.put(locale, value); return new LocalizedString(newMap); }