private static void validatePresentAndRemovedOverlap(List<FileIndex> filesPresent, List<FileIndex> filesRemoved, List<DirIndex> subDirsPresent, List<DirIndex> subDirsRemoved) {
    Set<FileIndex> filesPresentSet = new HashSet<>(filesPresent);
    Set<FileIndex> filesRemovedSet = new HashSet<>(filesRemoved);

    Set<FileBlob> blobsPresentSet = filesPresent.stream()
        .flatMap(fileIndex -> fileIndex.getBlobs().stream())
        .collect(Collectors.toCollection(HashSet::new));

    Set<FileBlob> blobsRemovedSet = filesRemoved.stream()
        .flatMap(fileIndex -> fileIndex.getBlobs().stream())
        .collect(Collectors.toCollection(HashSet::new));

    // check within current subdir, since moving file to a different subDir should be OK.
    Sets.SetView<FileIndex> presentAndRemovedFilesSet = Sets.intersection(filesPresentSet, filesRemovedSet);
    Preconditions.checkState(presentAndRemovedFilesSet.isEmpty(),
        String.format("File(s) present in both filesPresent and filesRemoved set: %s", presentAndRemovedFilesSet));

    for (DirIndex subDirPresent: subDirsPresent) {
      addFilesAndBlobsForSubDir(subDirPresent, filesPresentSet, filesRemovedSet, blobsPresentSet, blobsRemovedSet);
    }

    for (DirIndex subDirRemoved: subDirsRemoved) {
      addFilesAndBlobsForSubDirRemoved(subDirRemoved, filesRemovedSet, blobsRemovedSet);
    }

    Sets.SetView<FileBlob> presentAndRemovedBlobsSet = Sets.intersection(blobsPresentSet, blobsRemovedSet);
    Preconditions.checkState(presentAndRemovedBlobsSet.isEmpty(),
        String.format("Blob(s) present in both blobsPresentSet and blobsRemovedSet set: %s", presentAndRemovedBlobsSet));
  }
Representation of a directory in the blob store
samza-core/src/main/java/org/apache/samza/storage/blobstore/index/DirIndex.java