/** * Allows to set the currency code, for creating multiple instances, using one Builder. * * @param currencyCode the (unique) and identifying currency code, not null. * @return the Builder, for chaining. * @see javax.money.CurrencyUnit#getCurrencyCode() */ public CurrencyUnitBuilder setCurrencyCode(String currencyCode) { Objects.requireNonNull(currencyCode, "currencyCode required"); this.currencyCode = currencyCode; this.currencyContext = CurrencyContextBuilder.of(getClass().getSimpleName()).build(); return this; }
/** * Creates a new builder. * * @param provider the provider name, creating the corresponding {@link CurrencyUnit} containing * the final {@link CurrencyContext} created by this builder, not null. * @return a new {@link javax.money.CurrencyContextBuilder} instance, never null. */ public static CurrencyContextBuilder of(String provider) { return new CurrencyContextBuilder(provider); }
/** * Creates a new builder. * * @param context the {@link javax.money.CurrencyContext} to be used for initializing this builder. */ private CurrencyContextBuilder(CurrencyContext context) { Objects.requireNonNull(context); importContext(context); }
/** * Allows to convert a instance into the corresponding {@link javax.money.CurrencyContextBuilder}, which allows * to change the values and of another {@link javax.money.CurrencyContext} instance. * * @return a new Builder instance, preinitialized with the values from this instance. */ public CurrencyContextBuilder toBuilder(){ return CurrencyContextBuilder.of(this); }
/** * Creates a new builder. * * @param provider the provider name, creating the corresponding {@link CurrencyUnit} containing * the final {@link CurrencyContext} created by this builder, not null. */ private CurrencyContextBuilder(String provider) { Objects.requireNonNull(provider); setProviderName(provider); }
/** * Creates a new CurrencyUnitBuilder, creates a simple CurrencyContext using the given provider name. * * @param currencyCode the (unique) and identifying currency code, not null. * @param providerName the currency provider, not null. */ public static CurrencyUnitBuilder of(String currencyCode, String providerName) { return new CurrencyUnitBuilder(currencyCode, CurrencyContextBuilder.of(providerName).build()); }
/** * Creates a new builder. * * @param context the {@link javax.money.CurrencyContext} to be used for initializing this builder. * @return a new {@link javax.money.CurrencyContextBuilder} instance, never null. */ public static CurrencyContextBuilder of(CurrencyContext context) { return new CurrencyContextBuilder(context); }
public static void main(String[] args) { CurrencyUnit onTheFlyUnit = new CurrencyUnit() { private CurrencyContext context = CurrencyContextBuilder.of("GeeCon-onTheFly").build(); @Override public int compareTo(CurrencyUnit o) { return this.getCurrencyCode().compareTo(o.getCurrencyCode()); } @Override public String getCurrencyCode() { return "GeeCon-Special"; } @Override public int getNumericCode() { return 800; } @Override public int getDefaultFractionDigits() { return 0; } @Override public CurrencyContext getContext() { return context; } }; ConfigurableCurrencyUnitProvider.registerCurrencyUnit(onTheFlyUnit); ConsoleUtils.printDetails(Monetary.getCurrency("GeeCon-Special")); }