I'm having trouble finding the intersection of an Array of Hashed Sets that contain a data Class (where I want to intersect by identifier):
class Protein(val id: String, val score: Double, val molw: Double, val spc: Int)
I've pulled in some data from a .csv file into this type of structure:
ArrayList<HashSet<Protein>>
So I have six array lists [1 for each csv], each containing one hashed set that contains thousands of Protein structures. Here's what I've tried so far to get an intersection HashSet based off of common Protein.id:
fun intersection(data: ArrayList<HashSet<Protein>>): HashSet<Protein> {
val intersectionSet = HashSet<Protein>(data[0])
for (i in 1..data.size) {
intersectionSet.retainAll(data[i])
}
return intersectionSet
}
This returns an empty list, which makes sense given that it's trying to intersect Protein objects and match each criteria as a whole.
How do I call data[i].id as my intersection criteria? I'm fairly new to Kotlin and data classes :)