Class CitationCountByYearValidator

java.lang.Object
eu.dnetlib.dhp.schema.solr.CitationCountByYearValidator

public class CitationCountByYearValidator extends Object
Validator and canonicalizer for yearly citation counts used in Result objects. Enforces schema-level constraints: - Year bounds: 1900 to current year - Count >= 0 - No nulls or empty entries - No duplicate years (with conflict resolution strategy) - Sorted ascending by year Usage in mappers:
 List<CitationCountByYear> raw = ...from upstream source...;
 List<CitationCountByYear> canonical = CitationCountByYearValidator.canonicalize(raw);
 result.setCitationCountByYear(canonical);
 
  • Constructor Details

    • CitationCountByYearValidator

      public CitationCountByYearValidator()
  • Method Details

    • canonicalize

      public static List<CitationCountByYear> canonicalize(List<CitationCountByYear> raw)
      Canonicalizes a list of citation-count entries: 1. Filters nulls 2. Validates year and count bounds 3. Deduplicates by year (summing counts for duplicates) 4. Sorts by year ascending
      Parameters:
      raw - Input list, may be null, empty, contain nulls, or have invalid entries.
      Returns:
      Canonical sorted list, or empty list if input is null/empty or all entries are invalid.
      Throws:
      IllegalArgumentException - if deduplication strategy is invalid (should not occur in practice).
    • isValidYear

      public static boolean isValidYear(Integer year)
      Validates a single year value against allowed bounds.
      Parameters:
      year - Year to validate, may be null.
      Returns:
      true if year is not null and in [MIN_YEAR, MAX_YEAR]; false otherwise.
    • isValidCount

      public static boolean isValidCount(Integer count)
      Validates a single count value (non-negative).
      Parameters:
      count - Count to validate, may be null.
      Returns:
      true if count is not null and >= 0; false otherwise.
    • isCanonical

      public static boolean isCanonical(List<CitationCountByYear> list)
      Validates an already-canonical list: sorted, unique years, valid bounds.
      Parameters:
      list - List to check.
      Returns:
      true if list is null/empty or forms a canonical entry (sorted, no duplicates, all valid).
    • getAllowedYearRange

      public static int[] getAllowedYearRange()
      Returns allowed year range for documentation/UI.
      Returns:
      Array [minYear, maxYear].