Class ExchangeRates
java.lang.Object
net.thauvin.erik.frankfurter.models.ExchangeRates
- All Implemented Interfaces:
RatesResult
Represents a list of exchange rates returned by the Frankfurter API.
The API returns a JSON array of rate objects. For time series or grouped queries, the same quote currency may appear multiple times with different dates.
- Since:
- 1.0
- Author:
- Erik C. Thauvin
- API Note:
- This class is immutable and thread-safe.
-
Constructor Summary
ConstructorsConstructorDescriptionExchangeRates(Collection<Rate> rates) Creates a new immutable container for the given list of rates. -
Method Summary
Modifier and TypeMethodDescriptionstatic ExchangeRatesempty()Returns an emptyExchangeRatesinstance.booleanFinds the first entry matching the given quote currency.find(CurrencyCode quote) Finds the first entry matching the given quote currency.Returns all rate entries matching the given quote currency.findAll(CurrencyCode quote) Returns all rate entries matching the given quote currency.inthashCode()booleanisEmpty()Returnstrueif there are no rate entries.Returns all distinct quote currencies asCurrencyCode, filtering out unknown codes.list()Returns an unmodifiable list of all rate entries.quotes()Returns all distinct quote currency codes in this result set.intsize()Returns the number of rate entries.toString()Returns a string representation showing size and preview some entries for debugging.
-
Constructor Details
-
ExchangeRates
Creates a new immutable container for the given list of rates.- Parameters:
rates- the list of rate entries- Throws:
NullPointerException- ifratesisnullor contains null elements
-
-
Method Details
-
hashCode
public int hashCode() -
equals
-
toString
Returns a string representation showing size and preview some entries for debugging. -
empty
Returns an emptyExchangeRatesinstance.- Returns:
- an empty instance
-
find
Finds the first entry matching the given quote currency.For time series data with multiple entries per currency, this returns the first match in iteration order, which matches API response order.
- Parameters:
quote- the ISO 4217 quote currency- Returns:
- an optional containing the first matching rate
- Throws:
NullPointerException- ifquoteisnull
-
find
Finds the first entry matching the given quote currency.For time series data with multiple entries per currency, this returns the first match in iteration order, which matches API response order.
- Parameters:
quote- the quote currency- Returns:
- an optional containing the first matching rate
- Throws:
NullPointerException- ifquoteisnull
-
findAll
Returns all rate entries matching the given quote currency.Useful for time series where the same currency appears multiple times with different dates.
- Parameters:
quote- the ISO 4217 quote currency- Returns:
- unmodifiable list of matching rates, empty if none found
- Throws:
NullPointerException- ifquoteisnull
-
findAll
Returns all rate entries matching the given quote currency.Useful for time series where the same currency appears multiple times with different dates.
- Parameters:
quote- the quote currency- Returns:
- unmodifiable list of matching rates, empty if none found
- Throws:
NullPointerException- ifquoteisnull
-
isEmpty
public boolean isEmpty()Returnstrueif there are no rate entries.- Returns:
trueif the list is empty,falseotherwise
-
knownQuotes
Returns all distinct quote currencies asCurrencyCode, filtering out unknown codes.- Returns:
- unmodifiable list of known currency codes
-
list
Returns an unmodifiable list of all rate entries.- Returns:
- the list of rates
-
quotes
Returns all distinct quote currency codes in this result set.- Returns:
- unmodifiable list of ISO 4217 codes
-
size
public int size()Returns the number of rate entries.- Returns:
- the number of entries
-