Class FrankfurterExchangeRates
java.lang.Object
com.eqixiac.equinix.design.cost.FrankfurterExchangeRates
- All Implemented Interfaces:
CurrencyConverter
Live ECB reference rates from the Frankfurter API (no key): one
GET <baseUrl>/latest?base=<target>
per converter, made on the first conversion that needs it and cached for the converter's life; never
retried. The request carries only the currency code and a generic User-Agent. Shape observed 2026-11-12:
{"amount":1.0,"base":"USD","date":"2026-11-11","rates":{"EUR":0.89871,"GBP":0.75149,...}} (no AED).
When the call fails, times out (3 s connect, 5 s overall) or returns another shape, or a currency is
absent, rate(String, String) is empty so the chain falls back to the bundled table; fallbackNote() says
why. Never throws. Rates are reference mid rates, not dealing rates, so converted ranges are widened by
2.0% either side.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFetches a URL's body; injectable so tests never reach the internet.Nested classes/interfaces inherited from interface CurrencyConverter
CurrencyConverter.Converted, CurrencyConverter.Kind, CurrencyConverter.RateModifier 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. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleWidening for live ECB reference rates, either side, in percent.static final StringThe default endpoint root. -
Constructor Summary
ConstructorsConstructorDescriptionFrankfurterExchangeRates(String target, String baseUrl, FrankfurterExchangeRates.Fetcher fetcher) -
Method Summary
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CurrencyConverter
convertModifier and TypeMethodDescriptiondefault Optional<CurrencyConverter.Converted> convert(BigDecimal amount, String from, String to) Converts an amount.
-
Field Details
-
DEFAULT_BASE_URL
-
BAND_PERCENT
public static final double BAND_PERCENTWidening for live ECB reference rates, either side, in percent.- See Also:
-
-
Constructor Details
-
FrankfurterExchangeRates
public FrankfurterExchangeRates(String target, String baseUrl, FrankfurterExchangeRates.Fetcher fetcher) - Parameters:
target- the currency rates are fetched for (the request'sbase)baseUrl- the endpoint root,nullforDEFAULT_BASE_URLfetcher- the HTTP fetch,nullforhttpFetcher()
-
-
Method Details
-
httpFetcher
- Returns:
- a java.net.http fetch with a 3 s connect and 5 s request timeout and a generic User-Agent
-
rate
- Specified by:
ratein interfaceCurrencyConverter- Parameters:
from- ISO 4217 codeto- ISO 4217 code- Returns:
- the rate, or empty when this converter has none for the pair
-
fallbackNote
-
attempted
public boolean attempted()- Returns:
- whether the single fetch has been attempted
-
name
- Specified by:
namein interfaceCurrencyConverter- Returns:
- a short name for reasons and diagnostics
-