Package net.thauvin.erik.frankfurter
Class FrankfurterUtils
java.lang.Object
net.thauvin.erik.frankfurter.FrankfurterUtils
Utility class for interacting with the Frankfurter API and performing related operations.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic LocalDate
calculateEasterMonday
(int year) Calculates Easter Monday for a given year.static LocalDate
calculateEasterSunday
(int year) Calculates Easter Sunday for a given year using the Western (Gregorian) calendar.static LocalDate
calculateGoodFriday
(int year) Calculates Good Friday for a given year.closingDays
(int year) Calculates a list of target closing days for a given year.static String
Sends an HTTP GET request to the specified URI and retrieves the response body as a string.static String
formatCurrency
(String symbol, Double amount) Formats a currency amount based on the provided ISO currency symbol and amount.static String
formatCurrency
(String symbol, Double amount, boolean rounded) Formats a currency amount based on the provided ISO currency symbol, amount, and rounding preference.static boolean
isValidSymbol
(String symbol) Validates whether the provided symbol is a non-null string consisting of exactly three alphabetical characters (either uppercase or lowercase).static boolean
Determines whether the given date falls on a weekend (Saturday or Sunday).static boolean
isWorkingDay
(LocalDate date, List<LocalDate> closingDays) Determines whether the specified date is a working day.static String
normalizeSymbol
(String symbol) Formats a given currency symbol to uppercase if it matches the required format of three alphabetical characters.static URI
uriBuilder
(String path, Map<String, String> query) Builds a URI by combining theAPI_BASE_URL base url
, a specified path, and query parameters.static void
validateDate
(LocalDate date) Validates the provided date.workingDays
(LocalDate startDate, LocalDate endDate) Calculates a list of working days between two given dates, excluding weekends (Saturdays and Sundays) and target closing days.yearsBetween
(LocalDate startDate, LocalDate endDate) Retrieves a list of all years in the range between the provided start date and end date, inclusive.
-
Field Details
-
API_BASE_URL
The base URL for the Frankfurter API.- See Also:
-
EUR
The Euro currency code.- See Also:
-
LOGGER
The logger for this class. -
MIN_DATE
The minimum date supported by the Frankfurter API.
-
-
Method Details
-
calculateEasterMonday
Calculates Easter Monday for a given year.Easter Monday is 1 day after Easter Sunday
- Parameters:
year
- The year for which to calculate Easter Monday- Returns:
LocalDate
representing Easter Monday- See Also:
-
calculateEasterSunday
Calculates Easter Sunday for a given year using the Western (Gregorian) calendar.Based on the algorithm by Jean Meeus.
- Parameters:
year
- The year for which to calculate Easter- Returns:
LocalDate
representing Easter Sunday
-
calculateGoodFriday
Calculates Good Friday for a given year.Good Friday is 2 days before Easter Sunday
- Parameters:
year
- The year for which to calculate Good Friday- Returns:
LocalDate
representing Good Friday- See Also:
-
closingDays
Calculates a list of target closing days for a given year.The target closing days are:
- New Year's Day (Jan 1)
- Good Friday (2 days before Easter)
- Easter Monday (1 day after Easter)
- Lobor Day (May 1)
- Christmas Day (Dec 25)
- Christmas Holiday (Dec 26)
- Parameters:
year
- the year for which to generate the list of closing days- Returns:
- a list of
LocalDate
objects representing the closing days in the specified year - See Also:
-
fetchUri
Sends an HTTP GET request to the specified URI and retrieves the response body as a string.The request is configured to accept JSON responses.
- Parameters:
uri
- the URI to which the GET request will be sent- Returns:
- the response body as a string
- Throws:
HttpErrorException
- if the response status code is not 200IOException
- if an I/O error occurs during the request
-
formatCurrency
Formats a currency amount based on the provided ISO currency symbol and amount.- Parameters:
symbol
- The 3-letter ISO currency symbol (e.g., "USD", "EUR")amount
- The monetary amount to format- Returns:
- A formatted currency string
- Throws:
IllegalArgumentException
- If the currency symbol is unknown or invalid
-
formatCurrency
Formats a currency amount based on the provided ISO currency symbol, amount, and rounding preference.- Parameters:
symbol
- The 3-letter ISO currency symbol (e.g., "USD", "EUR")amount
- The monetary amount to formatrounded
- Whether to round the amount- Returns:
- A formatted currency string
- Throws:
IllegalArgumentException
- If the currency symbol is unknown or invalid
-
isValidSymbol
Validates whether the provided symbol is a non-null string consisting of exactly three alphabetical characters (either uppercase or lowercase).- Parameters:
symbol
- The string to be validated- Returns:
true
if the symbol is non-null and matches the required format of three alphabetical characters,false
otherwise.
-
isWeekend
Determines whether the given date falls on a weekend (Saturday or Sunday).- Parameters:
date
- theLocalDate
to evaluate- Returns:
true
if the specified date is a Saturday or Sunday,false
otherwise
-
isWorkingDay
Determines whether the specified date is a working day.A working day is defined as a day that is not a weekend (Saturday or Sunday) and does not fall on a
closing day
. -
normalizeSymbol
Formats a given currency symbol to uppercase if it matches the required format of three alphabetical characters.- Parameters:
symbol
- The currency symbol to be formatted, which must consist of exactly three alphabetical characters- Returns:
- The normalized version of the currency symbol if it is valid
- Throws:
IllegalArgumentException
- If the provided symbol is not exactly three alphabetical characters
-
uriBuilder
Builds a URI by combining theAPI_BASE_URL base url
, a specified path, and query parameters.The path is appended to the base URL, and query parameters are appended as a query string.
- Parameters:
path
- the path to be appended to the base URL; can be nullquery
- a map of query parameter keys and values; can be null or empty- Returns:
- a URI constructed from the base URL, the path, and the query parameters
- Throws:
URISyntaxException
- if the resulting URI is invalid
-
validateDate
Validates the provided date.A valid date must be non-null and not earlier than
1994-01-04
.- Parameters:
date
- the date to be validated- Throws:
IllegalArgumentException
- if the date is null or earlier than1994-01-04
-
workingDays
Calculates a list of working days between two given dates, excluding weekends (Saturdays and Sundays) and target closing days.- Parameters:
startDate
- the starting date of the range (inclusive)endDate
- the ending date of the range (inclusive)- Returns:
- a list of
LocalDate
objects representing the working days - See Also:
-
yearsBetween
Retrieves a list of all years in the range between the provided start date and end date, inclusive.- Parameters:
startDate
- the starting date of the range (inclusive)endDate
- the ending date of the range (inclusive)- Returns:
- a list of integers representing all years in the specified date range
-