public final class ConversionContext extends AbstractContext
ExchangeRate
is valid. It allows to define
different settings such as
RateType
, An instance of this class can be passed
ExchangeRateProvider.getExchangeRate(javax.money.CurrencyUnit, javax.money.CurrencyUnit, ConversionContext)
or .ExchangeRateProvider#getExchangeRate(String, String, ConversionContext)
.ExchangeRateProvider#getCurrencyConversion(javax.money.CurrencyUnit, ConversionContext)
or .convert.ExchangeRateProvider#getCurrencyConversion(String, ConversionContext)
MonetaryConversions.getConversion(javax.money.CurrencyUnit,
ConversionContext, String...)
or MonetaryConversions.getConversion(String,
ConversionContext, String...)
If multiple ExchangeRateProvider are participating in a provider chain, the ConversionContext is passed to each provider in the chain. As a consequence the context can have additional parameters that may be read by different rate providers within the chain.
Instances of this class are immutable and thread-safe.Modifier and Type | Class and Description |
---|---|
static class |
ConversionContext.Builder
Builder class to create
ConversionContext instances. |
AbstractContext.AbstractBuilder<B extends AbstractContext.AbstractBuilder<B>>
Modifier and Type | Field and Description |
---|---|
static ConversionContext |
ANY_CONVERSION
ConversionContext that queries any conversion available.
|
static ConversionContext |
DEFERRED_CONVERSION
ConversionContext quering for any deferred rates.
|
static ConversionContext |
HISTORIC_CONVERSION
ConversionContext quering for any historic rates.
|
static ConversionContext |
OTHER_CONVERSION
ConversionContext quering for any other rates.
|
static ConversionContext |
REALTIME_CONVERSION
ConversionContext quering for real-time rates.
|
attributes
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getProvider()
Get the provider of this rate.
|
RateType |
getRateType()
Get the deferred flag.
|
java.lang.Long |
getTimestamp()
Returns the UTC timestamp of this rate.
|
<T> T |
getTimestamp(java.lang.Class<T> type)
Returns the timestamp of this rate.
|
java.lang.Long |
getValidTo()
Returns the ending UTC timestamp of this rate, or
null . |
<T> T |
getValidTo(java.lang.Class<T> type)
Returns the ending date/time of this rate.
|
boolean |
isValid(long timestamp)
Method that determines if the rate is valid at the given UTC timestamp.
|
static ConversionContext |
of()
Simple factory method for
ConversionContext . |
static ConversionContext |
of(RateType rateType)
Creates a
ConversionContext for accessing rates of the given
type, without specifying the rate's provider. |
static ConversionContext |
of(java.lang.String provider,
RateType rateType)
Simple factory method for
ConversionContext . |
static ConversionContext |
of(java.lang.String provider,
RateType rateType,
java.lang.Long timestamp)
|
ConversionContext.Builder |
toBuilder()
Creates a
ConversionContext.Builder initialized with this instance's data. |
equals, getAttribute, getAttribute, getAttributeTypes, getNamedAttribute, getNamedAttribute, hashCode, set, set, toString
public static final ConversionContext ANY_CONVERSION
public static final ConversionContext DEFERRED_CONVERSION
public static final ConversionContext HISTORIC_CONVERSION
public static final ConversionContext OTHER_CONVERSION
public static final ConversionContext REALTIME_CONVERSION
public java.lang.String getProvider()
public RateType getRateType()
public final java.lang.Long getTimestamp()
null
.public final <T> T getTimestamp(java.lang.Class<T> type)
type
- the date/time type required.null
.public final java.lang.Long getValidTo()
null
.null
.public final <T> T getValidTo(java.lang.Class<T> type)
type
- the date/time type required.null
.public boolean isValid(long timestamp)
timestamp
- the timestamp in milliseconds.public static ConversionContext of()
ConversionContext
. For more
possibilities to initialize a ConversionContext
, please use a
ConversionContext.Builder
,ConversionContext
public static ConversionContext of(RateType rateType)
ConversionContext
for accessing rates of the given
type, without specifying the rate's provider.rateType
- the required rate type.ConversionContext
public static ConversionContext of(java.lang.String provider, RateType rateType)
ConversionContext
. For more
possibilities to initialize a ConversionContext
, please use a
ConversionContext.Builder
,provider
- the provider name, not null
rateType
- the required rate type.ConversionContext
public static ConversionContext of(java.lang.String provider, RateType rateType, java.lang.Long timestamp)
rateType
- the RateType
, not nulltimestamp
- the target timestampConversionContext
public ConversionContext.Builder toBuilder()
ConversionContext.Builder
initialized with this instance's data.ConversionContext.Builder
, not null
.