Class FrankfurterUtils

java.lang.Object
net.thauvin.erik.frankfurter.FrankfurterUtils

public final class FrankfurterUtils extends Object
Utility class for interacting with the Frankfurter API and performing related operations.
Since:
0.9.0
Author:
Erik C. Thauvin
  • Field Details

    • API_BASE_URL

      public static final String API_BASE_URL
      The base URL for the Frankfurter API.
      See Also:
    • EUR

      public static final String EUR
      The Euro currency code.
      See Also:
    • MIN_DATE

      public static final LocalDate MIN_DATE
      The minimum date supported by the Frankfurter API.
    • UNEXPECTED_ERROR

      public static final int UNEXPECTED_ERROR
      Unexpected error status code.
      See Also:
  • Method Details

    • calculateEasterMonday

      @NotNull public static @NotNull LocalDate calculateEasterMonday(int year)
      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

      @NotNull public static @NotNull LocalDate calculateEasterSunday(int year)
      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

      @NotNull public static @NotNull LocalDate calculateGoodFriday(int year)
      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

      @NotNull public static @NotNull List<LocalDate> closingDays(int year)
      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 LocalDate objects representing the closing days in the specified year
      See Also:
    • fetchUri

      public static String fetchUri(@NotNull @NotNull URI uri) throws HttpErrorException
      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 200
      NullPointerException - if the URI is null
    • isValidSymbol

      public 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).
      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

      public static boolean isWeekend(@NotNull @NotNull LocalDate date)
      Determines whether the given date falls on a weekend (Saturday or Sunday).
      Parameters:
      date - the LocalDate to evaluate
      Returns:
      true if the specified date is a Saturday or Sunday, false otherwise
    • 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.

      Parameters:
      date - the LocalDate to evaluate
      closingDays - a list of LocalDate objects representing non-working days
      Returns:
      true if the specified date is a working day, false otherwise
      See Also:
    • normalizeSymbol

      @NotNull public static @NotNull String normalizeSymbol(@NotNull @NotNull String symbol)
      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
      NullPointerException - if the provided symbol is null
    • uriBuilder

      @NotNull public static @NotNull URI uriBuilder(String path, Map<String,String> query) throws URISyntaxException
      Builds a URI by combining the API_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 null
      query - 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

      @NotNull public static @NotNull LocalDate validateDate(@NotNull @NotNull LocalDate date)
      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 than 1994-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 LocalDate objects 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