Package org.javamoney.moneta.convert
Class ExchangeRateBuilder
java.lang.Object
org.javamoney.moneta.convert.ExchangeRateBuilder
public class ExchangeRateBuilder extends Object
Builder for creating new instances of
ExchangeRate. Note that
instances of this class are not thread-safe.- Author:
- Anatole Tresch, Werner Keil
-
Constructor Summary
Constructors Constructor Description ExchangeRateBuilder(String provider, javax.money.convert.RateType rateType)Sets the exchange rate typeExchangeRateBuilder(javax.money.convert.ConversionContext context)Sets the exchange rate typeExchangeRateBuilder(javax.money.convert.ExchangeRate rate)Sets the exchange rate type -
Method Summary
Modifier and Type Method Description javax.money.convert.ExchangeRatebuild()Builds a new instance ofExchangeRate.ExchangeRateBuildersetBase(javax.money.CurrencyUnit base)Sets the baseCurrencyUnitExchangeRateBuildersetContext(javax.money.convert.ConversionContext conversionContext)Sets the provider to be applied.ExchangeRateBuildersetFactor(javax.money.NumberValue factor)Sets the conversion factor, as the factorbase * factor = target.ExchangeRateBuildersetRate(javax.money.convert.ExchangeRate rate)Initialize theExchangeRateBuilderwith anExchangeRate.ExchangeRateBuildersetRateChain(List<javax.money.convert.ExchangeRate> exchangeRates)Sets theExchangeRatechain.ExchangeRateBuildersetRateChain(javax.money.convert.ExchangeRate... exchangeRates)Sets theExchangeRatechain.ExchangeRateBuildersetTerm(javax.money.CurrencyUnit term)Sets the terminating (target)CurrencyUnitStringtoString()
-
Constructor Details
-
ExchangeRateBuilder
Sets the exchange rate type- Parameters:
rateType- theRateTypecontained
-
ExchangeRateBuilder
Sets the exchange rate type- Parameters:
context- theConversionContextto be applied
-
ExchangeRateBuilder
Sets the exchange rate type- Parameters:
rate- theExchangeRateto be applied
-
-
Method Details
-
setBase
Sets the baseCurrencyUnit- Parameters:
base- to base (source)CurrencyUnitto be applied- Returns:
- the builder instance
-
setTerm
Sets the terminating (target)CurrencyUnit- Parameters:
term- to terminatingCurrencyUnitto be applied- Returns:
- the builder instance
-
setRateChain
Sets theExchangeRatechain.- Parameters:
exchangeRates- theExchangeRatechain to be applied- Returns:
- the builder instance
-
setRateChain
Sets theExchangeRatechain.- Parameters:
exchangeRates- theExchangeRatechain to be applied- Returns:
- the builder instance
-
setFactor
Sets the conversion factor, as the factorbase * factor = target.- Parameters:
factor- the factor.- Returns:
- The builder instance.
-
setContext
Sets the provider to be applied.- Parameters:
conversionContext- theConversionContext, not null.- Returns:
- The builder.
-
build
Builds a new instance ofExchangeRate.- Returns:
- a new instance of
ExchangeRate. - Throws:
IllegalArgumentException- if the rate could not be built.
-
setRate
Initialize theExchangeRateBuilderwith anExchangeRate. This is useful for creating a new rate, reusing some properties from an existing one.- Parameters:
rate- the base rate- Returns:
- the Builder, for chaining.
-
toString
-