77import org .jetbrains .annotations .Contract ;
88import org .jetbrains .annotations .Unmodifiable ;
99import org .jspecify .annotations .NullMarked ;
10+ import org .jspecify .annotations .Nullable ;
1011
1112import java .util .Locale ;
1213import java .util .Map ;
1314import java .util .Optional ;
1415import java .util .OptionalInt ;
16+ import java .util .function .Consumer ;
1517
1618/**
1719 * Represents a currency with support for localization, formatting, and symbolic representation.
@@ -34,39 +36,39 @@ public interface Currency {
3436 * If the audience does not specify a locale, {@link Locale#US} is used.
3537 *
3638 * @param audience the audience whose locale is used to determine the singular display name
37- * @return the singular display name as a {@code Component} for the audience's locale
39+ * @return an {@code Optional} containing the singular display name as a {@code Component} for the audience's locale, or empty
3840 */
39- default Component getDisplayNameSingular (Audience audience ) {
41+ default Optional < Component > getDisplayNameSingular (Audience audience ) {
4042 return getDisplayNameSingular (audience .getOrDefault (Identity .LOCALE , Locale .US ));
4143 }
4244
4345 /**
4446 * Retrieves the singular display name component of the currency for the specified locale.
4547 *
4648 * @param locale the locale for which the singular display name should be retrieved
47- * @return the singular display name as a {@code Component} for the specified locale
49+ * @return an {@code Optional} containing the singular display name as a {@code Component} for the specified locale, or empty
4850 */
49- Component getDisplayNameSingular (Locale locale );
51+ Optional < Component > getDisplayNameSingular (Locale locale );
5052
5153 /**
5254 * Retrieves the plural display name component of the currency based on the audience's locale.
5355 * <p>
5456 * If the audience does not specify a locale, {@link Locale#US} is used.
5557 *
5658 * @param audience the audience whose locale is used to determine the plural display name
57- * @return the plural display name as a {@code Component} for the audience's locale
59+ * @return an {@code Optional} containing the plural display name as a {@code Component} for the audience's locale, or empty
5860 */
59- default Component getDisplayNamePlural (Audience audience ) {
61+ default Optional < Component > getDisplayNamePlural (Audience audience ) {
6062 return getDisplayNamePlural (audience .getOrDefault (Identity .LOCALE , Locale .US ));
6163 }
6264
6365 /**
6466 * Retrieves the plural display name component of the currency for the specified locale.
6567 *
6668 * @param locale the locale for which the plural display name should be retrieved
67- * @return the plural display name as a {@code Component} for the specified locale
69+ * @return an {@code Optional} containing the plural display name as a {@code Component} for the specified locale, or empty
6870 */
69- Component getDisplayNamePlural (Locale locale );
71+ Optional < Component > getDisplayNamePlural (Locale locale );
7072
7173 /**
7274 * Retrieves the currency symbol.
@@ -104,12 +106,44 @@ default Component format(Number amount, Audience audience) {
104106 */
105107 int getFractionalDigits ();
106108
109+ /**
110+ * Modifies the current configuration of the currency using the provided builder.
111+ * The builder allows customization of various currency properties.
112+ *
113+ * @param consumer a {@code Consumer} that accepts a {@code Builder} instance to define customizations for the currency
114+ */
115+ void editCurrency (Consumer <Builder > consumer );
116+
117+ /**
118+ * Converts the current {@code Currency} instance into a {@code Builder} for modification or reconstruction.
119+ *
120+ * @return a {@code Builder} instance initialized with the properties of the current {@code Currency}
121+ */
122+ @ ApiStatus .OverrideOnly
123+ Builder toBuilder ();
124+
107125 /**
108126 * A builder interface for constructing instances of {@link Currency}.
109127 * The {@code Builder} allows for the configuration of currency properties such as
110128 * singular and plural display names, currency symbol, and fractional digits.
111129 */
112130 interface Builder {
131+ /**
132+ * Sets the name of the currency.
133+ *
134+ * @param name the name to be set
135+ * @return the builder instance for method chaining
136+ */
137+ @ Contract (value = "_ -> this" )
138+ Builder name (String name );
139+
140+ /**
141+ * Retrieves the name currently set on the builder.
142+ *
143+ * @return the name as a string, or {@code null} if not set
144+ */
145+ String name ();
146+
113147 /**
114148 * Retrieves a map containing the singular display names of the currency for various locales.
115149 *
@@ -122,12 +156,12 @@ interface Builder {
122156 /**
123157 * Sets the singular display name of the currency for a specific locale.
124158 *
159+ * @param locale the locale for which the singular display name is being set, or {@code null} to remove
125160 * @param name the singular display name component of the currency
126- * @param locale the locale for which the singular display name is being set
127161 * @return the builder instance for chaining
128162 */
129- @ Contract (value = "_, _ -> this" , pure = true )
130- Builder displayNameSingular (Component name , Locale locale );
163+ @ Contract (value = "_, _ -> this" )
164+ Builder displayNameSingular (Locale locale , @ Nullable Component name );
131165
132166 /**
133167 * Retrieves the singular display name component of the currency for the specified locale.
@@ -150,12 +184,12 @@ interface Builder {
150184 /**
151185 * Sets the plural display name of the currency for a specific locale.
152186 *
187+ * @param locale the locale for which the plural display name is being set, or {@code null} to remove
153188 * @param name the plural display name component of the currency
154- * @param locale the locale for which the plural display name is being set
155189 * @return the builder instance for chaining
156190 */
157- @ Contract (value = "_, _ -> this" , pure = true )
158- Builder displayNamePlural (Component name , Locale locale );
191+ @ Contract (value = "_, _ -> this" )
192+ Builder displayNamePlural (Locale locale , @ Nullable Component name );
159193
160194 /**
161195 * Retrieves the plural display name component of the currency for the specified locale.
@@ -169,11 +203,11 @@ interface Builder {
169203 /**
170204 * Sets the currency symbol as a {@code Component}.
171205 *
172- * @param symbol the symbol component to represent the currency
206+ * @param symbol the symbol component to represent the currency, or {@code null} to remove
173207 * @return the builder instance for chaining
174208 */
175- @ Contract (value = "_ -> this" , pure = true )
176- Builder symbol (Component symbol );
209+ @ Contract (value = "_ -> this" )
210+ Builder symbol (@ Nullable Component symbol );
177211
178212 /**
179213 * Retrieves the currency symbol set on the {@code Builder}.
@@ -189,12 +223,12 @@ interface Builder {
189223 * Fractional digits are generally used to specify the precision of the currency values,
190224 * for example, 2 fractional digits for most currencies such as USD (representing cents).
191225 *
192- * @param fractionalDigits the number of fractional digits to set (must be a non-negative integer)
226+ * @param fractionalDigits the number of fractional digits to set (must be a non-negative integer), or {@code null} to remove
193227 * @return the builder instance for chaining
194228 * @throws IllegalArgumentException if {@code fractionalDigits} is negative
195229 */
196230 @ Contract (value = "_ -> this" )
197- Builder fractionalDigits (int fractionalDigits ) throws IllegalArgumentException ;
231+ Builder fractionalDigits (@ Nullable Integer fractionalDigits ) throws IllegalArgumentException ;
198232
199233 /**
200234 * Retrieves the number of fractional digits set for the currency.
0 commit comments