Class DeletionChecker

java.lang.Object
com.marksayson.deletionchecker.DeletionChecker

public final class DeletionChecker extends Object
Local, exact deletion-state lookup over a packed, immutable binary dataset.

Answers whether an entity ID has been deleted without any runtime network call. The dataset is a set of packed binary files, one per entity type, plus a manifest describing the release. A consumer selects which entity types to load with load(java.nio.file.Path, java.util.Set<java.lang.String>); unselected types are never opened and incur no memory or startup cost.

The dataset is immutable for the lifetime of the instance — new deletions or a changed entity-type selection are picked up only by loading a new instance against an updated dataset. Lookups are exact: no false positives or negatives.

The mapped files are held for the life of the process; there is no close. Their pages are off-heap, file-backed memory that counts toward process RSS and container memory limits, not toward the Java heap.

Instances are thread-safe after load(java.nio.file.Path, java.util.Set<java.lang.String>) returns.

  • Method Details

    • load

      public static DeletionChecker load(Path datasetDirectory, Set<String> entityTypes) throws IOException
      Loads the requested entity types from the dataset in datasetDirectory.

      Reads and verifies manifest.json, confirms every requested entity type is listed in it, then for each requested type opens its packed file, checks its format version and header entity type, and verifies its checksum against the manifest. Any failure fails the load; partially loaded state is discarded. Entity types not requested are never opened.

      Parameters:
      datasetDirectory - the directory holding manifest.json and the packed files
      entityTypes - the entity types to load
      Returns:
      a checker over the loaded entity types
      Throws:
      NullPointerException - if datasetDirectory or entityTypes is null
      IOException - if the manifest or a requested type's file cannot be read
      IllegalArgumentException - if a requested entity type is not listed in the manifest
      InvalidManifestException - if the manifest is malformed or fails its checksum
      UnsupportedManifestVersionException - if the manifest's schema version is not the one this build reads
      CorruptDatasetException - if a requested type's file is corrupt, its header entity type does not match the manifest, or its checksum does not match the manifest
      UnsupportedFormatVersionException - if a requested type's file has a binary format version this build does not read
    • isDeleted

      public boolean isDeleted(String entityType, String id)
      Returns whether id is recorded as deleted for entityType.

      The result is exact — true only if this identifier is present in the loaded dataset for this entity type. Comparison is on the identifier's raw UTF-8 bytes; no hashing and no Unicode normalization is performed, so the caller must supply the identifier exactly as issued by the authoritative source.

      Parameters:
      entityType - the entity type to query; must have been requested when this instance was loaded
      id - the identifier to check
      Returns:
      true if the identifier is deleted for this entity type, false otherwise
      Throws:
      IllegalArgumentException - if entityType was not requested when this instance was loaded, or if id is null, empty, exceeds 64 bytes when UTF-8 encoded, or contains an unpaired surrogate
    • filter

      public <T> List<T> filter(String entityType, List<T> items, Function<T,String> idExtractor)
      Returns the items whose extracted identifier is not recorded as deleted for entityType, in their original order.

      Equivalent to calling isDeleted(java.lang.String, java.lang.String) on each item's extracted identifier and keeping those that are not deleted, but resolves entityType once for the whole batch.

      Type Parameters:
      T - the item type
      Parameters:
      entityType - the entity type to query; must have been requested when this instance was loaded
      items - the items to filter
      idExtractor - maps an item to the identifier to check
      Returns:
      a new list containing only the items that are not deleted, in input order
      Throws:
      NullPointerException - if items or idExtractor is null
      IllegalArgumentException - if entityType was not requested when this instance was loaded, or if an extracted identifier is null, empty, exceeds 64 bytes when UTF-8 encoded, or contains an unpaired surrogate
    • datasetVersion

      public String datasetVersion()
      Returns the loaded release's datasetVersion — the ISO-8601 timestamp identifying which generation run's deletion data this instance holds.
      Returns:
      the dataset version string
    • loadedAt

      public Instant loadedAt()
      Returns the instant load(java.nio.file.Path, java.util.Set<java.lang.String>) completed, i.e. when this instance's dataset became active. Operators use it with datasetVersion() to spot instances running a stale release.
      Returns:
      the load-completion instant