Class ExchangeRates

java.lang.Object
net.thauvin.erik.frankfurter.models.ExchangeRates
All Implemented Interfaces:
RatesResult

@NullMarked public final class ExchangeRates extends Object implements 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 Details

    • ExchangeRates

      public ExchangeRates(Collection<Rate> rates)
      Creates a new immutable container for the given list of rates.
      Parameters:
      rates - the list of rate entries
      Throws:
      NullPointerException - if rates is null or contains null elements
  • Method Details

    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Returns a string representation showing size and preview some entries for debugging.
      Overrides:
      toString in class Object
      Returns:
      a string with class name, size, and preview of entries
    • empty

      public static ExchangeRates empty()
      Returns an empty ExchangeRates instance.
      Returns:
      an empty instance
    • find

      public Optional<Rate> find(String quote)
      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 - if quote is null
    • find

      public Optional<Rate> find(CurrencyCode quote)
      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 - if quote is null
    • findAll

      public List<Rate> findAll(String quote)
      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 - if quote is null
    • findAll

      public List<Rate> findAll(CurrencyCode quote)
      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 - if quote is null
    • isEmpty

      public boolean isEmpty()
      Returns true if there are no rate entries.
      Returns:
      true if the list is empty, false otherwise
    • knownQuotes

      public List<CurrencyCode> knownQuotes()
      Returns all distinct quote currencies as CurrencyCode, filtering out unknown codes.
      Returns:
      unmodifiable list of known currency codes
    • list

      public List<Rate> list()
      Returns an unmodifiable list of all rate entries.
      Returns:
      the list of rates
    • quotes

      public List<String> 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