In groovy I have a list of files A and also another list of files B. I want to remove all the files from A that have a filename that also occurs in the list of files B. I wrote the following code:
List<File> removeByName(final List<File> files, final List<File> removalFiles) {
final Set<String> removalNames = removalFiles.collect { it.name }.toSet()
files.findAll { ! removalNames.contains(it.name) }
}
Unfortunately I cannot use the remove
method in the Collection
class because two files are not equal even if they have the same file name. Are there any methods that I am missing which could be used to make that code cleaner?