Record Class SeriesRates
java.lang.Object
java.lang.Record
net.thauvin.erik.frankfurter.models.SeriesRates
- Record Components:
amount- the amount to be converted or used in calculationsbase- the base currency for the time series of exchange ratesstartDate- the start date of the time series, formatted as a stringendDate- the end date of the time series, formatted as a stringrates- a map where the keys are dates (LocalDate) and the values are maps of currency codes to their respective exchange rates as doubles
public record SeriesRates(@NotNull Double amount, @NotNull String base, @NotNull String startDate, @NotNull String endDate, @NotNull Map<LocalDate,Map<String,Double>> rates)
extends Record
Represents exchange rates over a series of dates for multiple currencies.
- Since:
- 0.9.0
- Author:
- Erik C. Thauvin
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull Doubleamount()Returns the value of theamountrecord component.@NotNull Stringbase()Returns the value of thebaserecord component.dates()Retrieves the set of dates for which exchange rates are available in the time series.@NotNull StringendDate()Returns the value of theendDaterecord component.@NotNull LocalDateRetrieves the end date of the time series.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanhasRatesFor(@NotNull LocalDate date) Checks if exchange rates are available for the specified date.booleanhasSymbolFor(@NotNull LocalDate date, @NotNull String symbol) Checks if a currency symbol is available for a specified date in the exchange rate time series.Retrieves the exchange rate for a specific date and currency symbol from the time series.rates()Returns the value of theratesrecord component.Retrieves the exchange rates for all currencies on the specified date.@NotNull StringReturns the value of thestartDaterecord component.@NotNull LocalDateRetrieves the start date of the time series.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
SeriesRates
public SeriesRates(@NotNull @NotNull Double amount, @NotNull @NotNull String base, @NotNull @NotNull String startDate, @NotNull @NotNull String endDate, @NotNull @NotNull Map<LocalDate, Map<String, Double>> rates) Constructs an instance ofSeriesRatesusing the provided exchange rate time series.The
ratesmap and all inner currency maps are deep-copied into unmodifiable maps. BothstartDateandendDateare validated as parseableLocalDatevalues at construction time.- Parameters:
amount- the amount to be converted or used in calculationsbase- the base currency for the time series of exchange ratesstartDate- the start date of the time series, formatted as a stringendDate- the end date of the time series, formatted as a stringrates- a map where the keys are dates (LocalDate) and the values are maps of currency codes to their respective exchange rates as doubles; must not benull- Throws:
NullPointerException- ifratesisnullDateTimeParseException- ifstartDateorendDatecannot be parsed
-
-
Method Details
-
dates
Retrieves the set of dates for which exchange rates are available in the time series.- Returns:
- an unmodifiable copy of the set of dates
-
endLocalDate
Retrieves the end date of the time series.- Returns:
- the end date as a
LocalDate
-
hasRatesFor
Checks if exchange rates are available for the specified date.- Parameters:
date- the date for which to check the availability of exchange rates- Returns:
trueif exchange rates are available for the specified date,falseotherwise
-
hasSymbolFor
Checks if a currency symbol is available for a specified date in the exchange rate time series.- Parameters:
date- theLocalDatefor which to check the availability of the symbolsymbol- the currency symbol to check for availability- Returns:
trueif the symbol is available for the specified date,falseotherwise
-
rateFor
Retrieves the exchange rate for a specific date and currency symbol from the time series.It is recommended to call
hasRatesFor(LocalDate)andhasSymbolFor(LocalDate, String)before this method to avoid anullreturn value.- Parameters:
date- the date for which the exchange rate is to be retrievedsymbol- the currency symbol for which the exchange rate is to be retrieved- Returns:
- the exchange rate for the specified date and currency symbol,
or
nullif no rate is available
-
ratesFor
Retrieves the exchange rates for all currencies on the specified date.- Parameters:
date- the date for which the exchange rates are to be retrieved as aLocalDate- Returns:
- an unmodifiable map of currency symbols to their respective exchange rates on the specified date, or an empty map if no rates are available for the date
-
startLocalDate
Retrieves the start date of the time series.- Returns:
- the start date as a
LocalDate
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
amount
Returns the value of theamountrecord component.- Returns:
- the value of the
amountrecord component
-
base
Returns the value of thebaserecord component.- Returns:
- the value of the
baserecord component
-
startDate
Returns the value of thestartDaterecord component.- Returns:
- the value of the
startDaterecord component
-
endDate
Returns the value of theendDaterecord component.- Returns:
- the value of the
endDaterecord component
-
rates
Returns the value of theratesrecord component.- Returns:
- the value of the
ratesrecord component
-