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 @NotNull LocalDatecalculateEasterMonday(int year) Calculates Easter Monday for a given year.static @NotNull LocalDatecalculateEasterSunday(int year) Calculates Easter Sunday for a given year using the Western (Gregorian) calendar.static @NotNull 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(@NotNull LocalDate date, @NotNull Collection<LocalDate> closingDays) Determines whether the specified date is a working day.static @NotNull StringnormalizeSymbol(@NotNull String symbol) Formats a given currency symbol to uppercase if it matches the required format of three alphabetical characters.static @NotNull URIuriBuilder(String path, Map<String, String> query) Builds a URI by combining theAPI_BASE_URL base url, a specified path, and query parameters.static @NotNull LocalDatevalidateDate(@NotNull LocalDate date) Validates the provided date.workingDays(@NotNull LocalDate startDate, @NotNull LocalDate endDate) Calculates a list of working days between two given dates, excluding weekends (Saturdays and Sundays) and target closing days.yearsBetween(@NotNull LocalDate startDate, @NotNull 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:
-
MIN_DATE
The minimum date supported by the Frankfurter API. -
UNEXPECTED_ERROR
public static final int UNEXPECTED_ERRORUnexpected error status code.- See Also:
-
-
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)
- Labor 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
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 200NullPointerException- if the URI isnull
-
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
public static boolean isWorkingDay(@NotNull @NotNull LocalDate date, @NotNull @NotNull Collection<LocalDate> closingDays) 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 charactersNullPointerException- if the provided symbol isnull
-
uriBuilder
@NotNull public static @NotNull URI uriBuilder(String path, Map<String, String> query) throws URISyntaxExceptionBuilds 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- Returns:
- the validated date
- Throws:
IllegalArgumentException- if the date is null or earlier than1994-01-04
-
workingDays
@NotNull public static @NotNull List<LocalDate> workingDays(@NotNull @NotNull LocalDate startDate, @NotNull @NotNull LocalDate endDate) Calculates a list of working days between two given dates, excluding weekends (Saturdays and Sundays) and target closing days.The starting and ending dates do not have to be chronologically ordered; results are always returned in ascending order.
- 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
@NotNull public static @NotNull List<Integer> yearsBetween(@NotNull @NotNull LocalDate startDate, @NotNull @NotNull LocalDate endDate) Retrieves a list of all years in the range between the provided start date and end date, inclusive.The starting and ending dates do not have to be chronologically ordered; results are always returned in ascending order.
- 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
-