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.
- Since:
- 0.9.0
- Author:
- Erik C. Thauvin
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic LocalDatecalculateEasterMonday(int year) Calculates Easter Monday for a given year.static LocalDatecalculateEasterSunday(int year) Calculates Easter Sunday for a given year using the Western (Gregorian) calendar.static LocalDatecalculateGoodFriday(int year) Calculates Good Friday for a given year.closingDays(int year) Calculates a list of target closing days for a given year.static StringSends an HTTP GET request to the specified URI and retrieves the response body as a string.static booleanisValidSymbol(String symbol) Validates whether the provided symbol is a non-null string consisting of exactly three alphabetical characters (either uppercase or lowercase).static booleanDetermines whether the given date falls on a weekend (Saturday or Sunday).static booleanisWorkingDay(LocalDate date, Collection<LocalDate> closingDays) Determines whether the specified date is a working day.static StringnormalizeSymbol(String symbol) Formats a given currency symbol to uppercase if it matches the required format of three alphabetical characters.static URIuriBuilder(String path, Map<String, String> query) Builds a URI by combining theAPI_BASE_URL base url, a specified path, and query parameters.static voidvalidateDate(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:
LocalDaterepresenting 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:
LocalDaterepresenting 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:
LocalDaterepresenting 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
LocalDateobjects representing the closing days in the specified year - See Also:
-
fetchUri
public static String fetchUri(URI uri) throws IOException, InterruptedException, IllegalArgumentException 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 requestInterruptedExceptionIllegalArgumentException
-
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:
trueif the symbol is non-null and matches the required format of three alphabetical characters,falseotherwise.
-
isWeekend
Determines whether the given date falls on a weekend (Saturday or Sunday).- Parameters:
date- theLocalDateto evaluate- Returns:
trueif the specified date is a Saturday or Sunday,falseotherwise
-
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
LocalDateobjects 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
-