1515 */
1616package org .javamoney .moneta ;
1717
18- import org .javamoney .moneta .internal .ConfigurableCurrencyUnitProvider ;
19-
2018import javax .money .*;
2119import javax .money .CurrencyContext ;
2220
23- import java .util .Locale ;
2421import java .util .Objects ;
2522
2623/**
27- * Implementation of {@link javax.money.CurrencyUnit} that allows to create new instances using a fluent API.
24+ * Implementation of {@link javax.money.CurrencyUnit} that allows to of new instances using a fluent API.
2825 * Instances created also can be added to the {@link org.javamoney.moneta.internal.ConfigurableCurrencyUnitProvider}
2926 * singleton, which publishes the instances, so they are visible from the {@link javax.money.MonetaryCurrencies}
3027 * singleton.
3128 */
32- public final class BuildableCurrencyUnit implements CurrencyUnit , Comparable <CurrencyUnit >{
29+ final class BuildableCurrencyUnit implements CurrencyUnit , Comparable <CurrencyUnit >{
3330
3431 /**
3532 * The unique currency code.
@@ -53,7 +50,7 @@ public final class BuildableCurrencyUnit implements CurrencyUnit, Comparable<Cur
5350 *
5451 * @param builder the builder, never null.
5552 */
56- private BuildableCurrencyUnit (Builder builder ){
53+ BuildableCurrencyUnit (CurrencyUnitBuilder builder ){
5754 Objects .requireNonNull (builder .currencyCode , "currencyCode required" );
5855 if (builder .numericCode < -1 ){
5956 throw new MonetaryException ("numericCode must be >= -1" );
@@ -129,130 +126,4 @@ public String toString(){
129126 }
130127
131128
132- /**
133- * Builder for constructing new instances o{@link org.javamoney.moneta.BuildableCurrencyUnit} using a fluent
134- * API.
135- */
136- public static final class Builder {
137- /**
138- * The currency code.
139- */
140- private String currencyCode ;
141- /**
142- * The (optional) numeric code.
143- */
144- private int numericCode = -1 ;
145- /**
146- * The default fraction digits.
147- */
148- private int defaultFractionDigits = 2 ;
149- /**
150- * THe currency's context.
151- */
152- private javax .money .CurrencyContext currencyContext ;
153-
154- /**
155- * Creats a new Builder.
156- *
157- * @param currencyCode the (unique) and identifying currency code, not null.
158- */
159- public Builder (String currencyCode , javax .money .CurrencyContext currencyContext ){
160- Objects .requireNonNull (currencyCode , "currencyCode required" );
161- this .currencyCode = currencyCode ;
162- Objects .requireNonNull (currencyContext , "currencyContext required" );
163- this .currencyContext = currencyContext ;
164- }
165-
166- /**
167- * Allows to set the currency code, for creating multiple instances, using one Builder.
168- *
169- * @param currencyCode the (unique) and identifying currency code, not null.
170- * @return the Builder, for chaining.
171- * @see javax.money.CurrencyUnit#getCurrencyCode()
172- */
173- public Builder setCurrencyCode (String currencyCode ){
174- Objects .requireNonNull (currencyCode , "currencyCode required" );
175- this .currencyCode = currencyCode ;
176- this .currencyContext = CurrencyContextBuilder .create (getClass ().getSimpleName ()).build ();
177- return this ;
178- }
179-
180- /**
181- * Set the numeric code (optional).
182- *
183- * @param numericCode The numeric currency code, >= -1. .1 hereby means <i>undefined</i>.
184- * @return the Builder, for chaining.
185- * @see javax.money.CurrencyUnit#getNumericCode()
186- */
187- public Builder setNumericCode (int numericCode ){
188- if (numericCode < -1 ){
189- throw new IllegalArgumentException ("numericCode must be >= -1" );
190- }
191- this .numericCode = numericCode ;
192- return this ;
193- }
194-
195- /**
196- * Set the default fraction digits.
197- *
198- * @param defaultFractionDigits the default fraction digits, >= 0.
199- * @return the Builder, for chaining.
200- * @see javax.money.CurrencyUnit#getDefaultFractionDigits()
201- */
202- public Builder setDefaultFractionDigits (int defaultFractionDigits ){
203- if (defaultFractionDigits < 0 ){
204- throw new IllegalArgumentException ("defaultFractionDigits must be >= 0" );
205- }
206- this .defaultFractionDigits = defaultFractionDigits ;
207- return this ;
208- }
209-
210- /**
211- * Returns a new instance of {@link org.javamoney.moneta.BuildableCurrencyUnit}.
212- *
213- * @return the new CurrencyUnit instance.
214- * @throws MonetaryException if creation fails
215- */
216- public BuildableCurrencyUnit build (){
217- return build (false );
218- }
219-
220- /**
221- * Returns a new instance of {@link org.javamoney.moneta.BuildableCurrencyUnit} and publishes it so it is
222- * accessible from the {@code MonetaryCurrencies} singleton.
223- *
224- * @param register if {@code true} the instance created is published so it is accessible from
225- * the {@code MonetaryCurrencies} singleton.
226- * @return the new CurrencyUnit instance.
227- * @see javax.money.MonetaryCurrencies#getCurrency(String, String...)
228- */
229- public BuildableCurrencyUnit build (boolean register ){
230- BuildableCurrencyUnit cu = new BuildableCurrencyUnit (this );
231- if (register ){
232- ConfigurableCurrencyUnitProvider .registerCurrencyUnit (cu );
233- }
234- return cu ;
235- }
236-
237- /**
238- * Returns a new instance of {@link org.javamoney.moneta.BuildableCurrencyUnit} and publishes it so it is
239- * accessible from the {@code MonetaryCurrencies} singleton.
240- *
241- * @param register if {@code true} the instance created is published so it is accessible from
242- * the {@code MonetaryCurrencies} singleton.
243- * @param locale country Locale for making the currency for the given country.
244- * @return the new CurrencyUnit instance.
245- * @see javax.money.MonetaryCurrencies#getCurrency(String, String...)
246- * @see javax.money.MonetaryCurrencies#getCurrency(Locale, String...)
247- */
248- public BuildableCurrencyUnit build (boolean register , Locale locale ){
249- BuildableCurrencyUnit cu = new BuildableCurrencyUnit (this );
250- if (register ){
251- ConfigurableCurrencyUnitProvider .registerCurrencyUnit (cu );
252- ConfigurableCurrencyUnitProvider .registerCurrencyUnit (cu , locale );
253- }
254- return cu ;
255- }
256- }
257-
258129}
0 commit comments