I have parsed a HTML timetable and loaded every Subject to my class object. So i have arrayList of my Subjects which has information of name, teacher,... ,HOUR, and DAY now i want to reconstruct the table and so I need to categorize it first. I think that best would be to have structure like this:
Monday: 1: Math, Czech, ...
2: History
...
Tuesday: 1: English, Geo
2...
...
There can be mutiple subjects in given hour, therefore I tried to used Multimap of Multimap, but I am not able to declare it during my for parsing.
Multimap<String, Multimap<String, Subject>> timetable = HashMultimap.create();
...
for ...
timetable.put(subject.den, new HashMultimap<>(subject.hod, subject));
but it says that HashMultimap has private accesin com.google.common... I dont know how to correctly write this. I was also thinking about using Array, but I would have to pre-declare it and I would like to build this during one for cycle. Any ideas? Thank you in advance
It looks like what you want is actually more of a Map<String, Multimap<String, Subject>>
, in which case you want
Map<String, Multimap<String, Subject>> timetable = new HashMap<>();
for ...
Multimap<String, Subject> multimap = timetable.get(subject.den);
if (multimap == null) {
multimap = HashMultimap.create();
timetable.put(subject.den, multimap);
}
multimap.put(subject.hod, subject);