Class CsvObservanceLoader

java.lang.Object
org.holiday.calendar.util.CsvObservanceLoader

public final class CsvObservanceLoader extends Object
Utility for loading observance date tables from classpath CSV resources.

CSV format: year,YYYY-MM-DD[,comment]. Lines that are blank or start with # (after stripping leading/trailing whitespace) are ignored. Malformed data rows (unparseable year or date, fewer than two fields) are logged at WARN level and skipped; valid rows in the same file are still loaded.

Both methods accept a Class<?> anchor whose Class.getResourceAsStream(java.lang.String) is used to locate the resource. This follows JPMS resource-access semantics: pass the class that lives in the same module package as the resource file.

This class is stateless and thread-safe.

  • Method Details

    • loadSingle

      public static Map<Integer,LocalDate> loadSingle(Class<?> anchor, String classpathResource)
      Loads a CSV where each year maps to exactly one date.

      If the same year appears more than once, the last row wins (standard HashMap put semantics).

      Parameters:
      anchor - class used to resolve the classpath resource
      classpathResource - resource path, relative to anchor's package or absolute (starting with /)
      Returns:
      unmodifiable Map<Integer, LocalDate>, preserving CSV order
      Throws:
      IllegalStateException - if the resource is not found on the classpath
      ExceptionInInitializerError - wrapping IOException on read failure
    • loadMultiple

      public static Map<Integer,List<LocalDate>> loadMultiple(Class<?> anchor, String classpathResource)
      Loads a CSV where each year may map to multiple dates (insertion order preserved within each year's list).
      Parameters:
      anchor - class used to resolve the classpath resource
      classpathResource - resource path, relative to anchor's package or absolute (starting with /)
      Returns:
      unmodifiable Map<Integer, List<LocalDate>> with unmodifiable value lists
      Throws:
      IllegalStateException - if the resource is not found on the classpath
      ExceptionInInitializerError - wrapping IOException on read failure