class StorageFileHelper {

    public void validateRegisteredS3Files(List<StorageFile> expectedStorageFiles, List<S3ObjectSummary> s3ObjectSummaries, String storageName,
        BusinessObjectDataKey businessObjectDataKey)
    {
        // Get a set of actual S3 file paths.
        Set<String> actualS3FilePaths = new HashSet<>(getFilePathsFromS3ObjectSummaries(s3ObjectSummaries));

        // Validate existence and file size for all expected files.
        for (StorageFile expectedStorageFile : expectedStorageFiles)
        {
            if (!actualS3FilePaths.contains(expectedStorageFile.getFilePath()))
            {
                throw new ObjectNotFoundException(
                    String.format("Registered file \"%s\" does not exist in \"%s\" storage.", expectedStorageFile.getFilePath(), storageName));
            }
        }

        // Get a set of expected file paths.
        Set<String> expectedFilePaths = new HashSet<>(getFilePathsFromStorageFiles(expectedStorageFiles));

        // Create a JSON representation of the business object data key.
        String businessObjectDataKeyAsJson = jsonHelper.objectToJson(businessObjectDataKey);

        // Validate that no other files in S3 bucket except for expected storage files have the same S3 key prefix.
        // Please note that this validation ignores (does not fail on) any unregistered zero byte S3 files.
        for (S3ObjectSummary s3ObjectSummary : s3ObjectSummaries)
        {
            if (!expectedFilePaths.contains(s3ObjectSummary.getKey()))
            {
                // Ignore unregistered zero byte S3 files.
                if (s3ObjectSummary.getSize() == 0)
                {
                    LOGGER.info("Ignoring unregistered zero byte S3 file. s3Key=\"{}\" storageName=\"{}\" businessObjectDataKey={}", s3ObjectSummary.getKey(),
                        storageName, businessObjectDataKeyAsJson);
                }
                else
                {
                    throw new IllegalStateException(String
                        .format("Found unregistered non-empty S3 file \"%s\" in \"%s\" storage. Business object data {%s}", s3ObjectSummary.getKey(),
                            storageName, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
                }
            }
        }
    }

}