[英]Multimap of Multimap Java - Categorize timetable
I have parsed a HTML timetable and loaded every Subject to my class object. 我已经解析了HTML时间表,并将每个Subject都加载到了我的类对象中。 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.
所以我有我的Subject的arrayList,它具有名称,老师,...,HOUR和DAY的信息,现在我想重建该表,因此我需要首先对其进行分类。 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 of Multimap,但是在解析期间无法声明它。
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. 但它说HashMultimap具有私有accesin com.google.common ...我不知道如何正确编写此内容。 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.
我也在考虑使用Array,但是我必须预先声明它,我想在一个for循环中构建它。 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>>
,在这种情况下,您想要
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.