public final class ProviderContext extends AbstractContext
ExchangeRate
s a .ExchangeRateProvider
delivers, including the provider's name, rate type and additional data.
By default such a context supports the following attributes:
RateType
an ExchangeRateProvider supports
ExchangeRateProvider} implementation.
Instances of this class are immutable and thread-safe.Modifier and Type | Class and Description |
---|---|
static class |
ProviderContext.Builder
Builder class to create
ProviderContext instances. |
AbstractContext.AbstractBuilder<B extends AbstractContext.AbstractBuilder<B>>
attributes
Modifier and Type | Method and Description |
---|---|
static ProviderContext |
from(ConversionContext conversionContext) |
java.lang.String |
getProviderName()
Get the provider of this rate.
|
java.util.Set<RateType> |
getRateTypes()
Get the deferred flag.
|
<T> T |
getValidFrom(java.lang.Class<T> type)
Returns the starting date/time this rate is valid.
|
java.lang.Long |
getValidFromMillis()
Returns the UTC timestamp defining from what date/time this rate is
valid.
|
<T> T |
getValidTo(java.lang.Class<T> type)
Returns the ending date/time this rate is valid.
|
java.lang.Long |
getValidToMillis()
Get the data validity timestamp of this rate in milliseconds.
|
boolean |
hasLowerBound()
Method to easily check if the
getValidFromMillis() is not
null . |
boolean |
hasUpperBound()
Method to easily check if the
getValidToMillis() is not
null . |
boolean |
isInScope(long timestamp)
Method to quickly check if an
ExchangeRate is valid for a given
UTC timestamp. |
static ProviderContext |
of(java.lang.String provider)
Creates a new ProviderContext based on the provider id and rate type(s).
|
static ProviderContext |
of(java.lang.String provider,
RateType... rateTypes)
Creates a new ProviderContext based on the provider id and rate type(s).
|
ProviderContext.Builder |
toBuilder()
Creates a
ProviderContext.Builder initialized with this instance's data. |
equals, getAttribute, getAttribute, getAttributeTypes, getNamedAttribute, getNamedAttribute, hashCode, set, set, toString
public static ProviderContext from(ConversionContext conversionContext)
public java.lang.String getProviderName()
public java.util.Set<RateType> getRateTypes()
public <T> T getValidFrom(java.lang.Class<T> type)
null
, since it is possible, that an ExchangeRate
does not
have starting validity range. This also can be queried by calling
hasLowerBound()
.
Basically all date time types that are available on a platform must be
supported. On SE this includes Date, Calendar and the new 310 types
introduced in JDK8). Additionally calling this method with
Long.class
returns the POSIX/UTC timestamp in milliseconds.null
, if no starting validity constraint is set.public java.lang.Long getValidFromMillis()
Long
instead of long
, since it is
possible, that an ExchangeRate
does not have starting validity
range. This also can be queried by calling hasLowerBound()
.null
, if no starting validity constraint is set.public <T> T getValidTo(java.lang.Class<T> type)
null
, since it is possible, that an ExchangeRate
does not
have ending validity range. This also can be queried by calling
hasUpperBound()
.
Basically all date time types that are available on a platform must be
supported. On SE this includes Date, Calendar and the new 310 types
introduced in JDK8). Additionally calling this method with
Long.class
returns the POSIX/UTC timestamp in milliseconds.null
, if no ending validity constraint is set.public java.lang.Long getValidToMillis()
Long
instaed of long
, since it is
possible, that an ExchangeRate
does not have ending validity
range. This also can be queried by calling hasUpperBound()
.null
if no
ending validity constraint is set.public boolean hasLowerBound()
getValidFromMillis()
is not
null
.true
if getValidFromMillis()
is not null
.public boolean hasUpperBound()
getValidToMillis()
is not
null
.true
if getValidToMillis()
is not null
.public boolean isInScope(long timestamp)
ExchangeRate
is valid for a given
UTC timestamp.timestamp
- the UTC timestamp.true
, if the rate is valid.public static ProviderContext of(java.lang.String provider)
provider
- the provider id, not null.ProviderContext
instance.public static ProviderContext of(java.lang.String provider, RateType... rateTypes)
provider
- the provider id, not null.rateTypes
- the required RateType
s, not nullProviderContext
instance.public ProviderContext.Builder toBuilder()
ProviderContext.Builder
initialized with this instance's data.ProviderContext.Builder
, not null
.