Interface CurrencyConverter
- All Known Implementing Classes:
BundledExchangeRates, CurrencyConverters.Chain, FrankfurterExchangeRates, PinnedExchangeRates
public interface CurrencyConverter
Restates an amount in another currency, so a design whose prices come back in several currencies
(the live Fabric price search quotes London in GBP, Frankfurt in EUR, Tokyo in JPY) is priced and
ranked in one. Implementations must be deterministic and pure: the same arguments give the same rate,
and no call reaches the network unless the implementation was supplied for that purpose.
The SDK resolves rates in this order (see com.eqixiac.equinix.design.cost.CurrencyConverters):
rates pinned in the spec's commercial.exchangeRates (part of the spec's fingerprint, never widened
unless the spec states a band), then a converter supplied by the caller or a DesignPlugin, then the
ECB reference rates fetched once per run from the Frankfurter API, then the bundled reference table. A currency absent from every source leaves the
line unpriced with that reason.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordAn amount restated in another currency.static enumWhere a rate came from, in precedence order.static final recordA rate between two currencies. -
Method Summary
Modifier and TypeMethodDescriptiondefault Optional<CurrencyConverter.Converted> convert(BigDecimal amount, String from, String to) Converts an amount.default Stringname()
-
Method Details
-
rate
- Parameters:
from- ISO 4217 codeto- ISO 4217 code- Returns:
- the rate, or empty when this converter has none for the pair
-
name
- Returns:
- a short name for reasons and diagnostics
-
convert
Converts an amount.- Parameters:
amount- the amount infromfrom- ISO 4217 codeto- ISO 4217 code- Returns:
- the converted amount (rounded half-up to cents) with the rate used, or empty when there is no rate
-