class StorageFileHelper {

    public void validateStorageUnitS3Files(StorageUnit storageUnit, List<String> actualS3Files, String s3KeyPrefix)
    {
        // Validate that all files match the expected S3 key prefix and build a list of registered S3 files.
        List<String> registeredS3Files = new ArrayList<>();
        if (!CollectionUtils.isEmpty(storageUnit.getStorageFiles()))
        {
            for (StorageFile storageFile : storageUnit.getStorageFiles())
            {
                Assert.isTrue(storageFile.getFilePath().startsWith(s3KeyPrefix), String
                    .format("Storage file S3 key prefix \"%s\" does not match the expected S3 key prefix \"%s\".", storageFile.getFilePath(), s3KeyPrefix));
                registeredS3Files.add(storageFile.getFilePath());
            }
        }

        // Validate that all files exist in S3 managed bucket.
        if (!actualS3Files.containsAll(registeredS3Files))
        {
            registeredS3Files.removeAll(actualS3Files);
            throw new IllegalStateException(
                String.format("Registered file \"%s\" does not exist in \"%s\" storage.", registeredS3Files.get(0), storageUnit.getStorage().getName()));
        }

        // Validate that no other files in S3 managed bucket have the same S3 key prefix.
        if (!registeredS3Files.containsAll(actualS3Files))
        {
            actualS3Files.removeAll(registeredS3Files);
            throw new IllegalStateException(String
                .format("Found S3 file \"%s\" in \"%s\" storage not registered with this business object data.", actualS3Files.get(0),
                    storageUnit.getStorage().getName()));
        }
    }

}