Class Currencies

java.lang.Object
net.thauvin.erik.frankfurter.models.Currencies
All Implemented Interfaces:
CurrenciesResult

public final class Currencies extends Object implements CurrenciesResult
Represents the set of currencies returned by the Frankfurter API.
  • Constructor Details

    • Currencies

      public Currencies(@NonNull Collection<Currency> currencies)
      Creates a new immutable container for the given list of currencies.
      Parameters:
      currencies - the list of currency entries
      Throws:
      NullPointerException - if currencies is null or contains null elements
  • Method Details

    • hashCode

      public int hashCode()
      Returns a hash code value for this object.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value derived from the backing list
    • equals

      public boolean equals(Object o)
      Compares the specified object with this container for equality.
      Overrides:
      equals in class Object
      Parameters:
      o - the reference object with which to compare
      Returns:
      true if the specified object is equal to this one; false otherwise
    • toString

      public String toString()
      Returns a string representation of this container.
      Overrides:
      toString in class Object
      Returns:
      a string containing the class name and the currency list entries
    • fromJson

      @NonNull public static Currencies fromJson(@NonNull String json)
      Parses a JSON array of currency entries into a Currencies instance.
      Parameters:
      json - the JSON response
      Returns:
      the parsed currencies
      Throws:
      NullPointerException - if json is null
      IllegalArgumentException - if json is malformed or contains null elements
    • codes

      @NonNull public List<String> codes()
      Returns all ISO codes in this set.
      Returns:
      an unmodifiable list of distinct ISO 4217 codes
    • find

      Finds a currency by its CurrencyCode.
      Parameters:
      code - the currency code
      Returns:
      an optional containing the matching currency
      Throws:
      NullPointerException - if code is null
      API Note:
      Use find(String) for codes not in CurrencyCode
    • find

      Finds a currency by its ISO code.
      Parameters:
      iso - the ISO 4217 currency code
      Returns:
      an optional containing the matching currency
      Throws:
      NullPointerException - if iso is null
    • isEmpty

      public boolean isEmpty()
      Returns true if the list is empty.
      Returns:
      true if this container contains no currencies; false otherwise
    • knownCodes

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

      @NonNull public List<Currency> list()
      Returns all currency entries.
      Returns:
      an unmodifiable list of currencies
    • searchByName

      @NonNull public List<Currency> searchByName(@NonNull String name)
      Searches currencies by name substring.
      Parameters:
      name - the substring to match
      Returns:
      the list of matching currencies if any
      Throws:
      NullPointerException - if name is null
    • size

      public int size()
      Returns the number of currencies.
      Returns:
      the total count of currency elements in this container