class AttachmentAwareDatabaseHandler {

    public Set<Attachment> getAllAttachmentsToKeep(Set<Attachment> originalAttachments, Set<Attachment> changedAttachments) {
        Set <Attachment> attachmentsToKeep = new HashSet<>();
        attachmentsToKeep.addAll(nullToEmptySet(changedAttachments));
        Set<String> alreadyPresentIdsInAttachmentsToKeep = nullToEmptyCollection(attachmentsToKeep).stream().map(Attachment::getAttachmentContentId).collect(Collectors.toSet());

        // prevent deletion of already accepted attachments
        Set<Attachment> acceptedAttachmentsNotYetToKeep = nullToEmptySet(originalAttachments).stream().filter(a -> (a.getCheckStatus() == CheckStatus.ACCEPTED && !alreadyPresentIdsInAttachmentsToKeep.contains(a.getAttachmentContentId()))).collect(Collectors.toSet());
        attachmentsToKeep.addAll(acceptedAttachmentsNotYetToKeep);

        return attachmentsToKeep;
    }

    public  AttachmentAwareDatabaseHandler();

}