|
| 1 | +package com.telephone.coursetable; |
| 2 | + |
| 3 | +import androidx.annotation.NonNull; |
| 4 | + |
| 5 | +import com.telephone.coursetable.Clock.Clock; |
| 6 | +import com.telephone.coursetable.Database.ExamInfo; |
| 7 | +import com.telephone.coursetable.Database.ExamInfoDao; |
| 8 | + |
| 9 | +import java.util.HashMap; |
| 10 | +import java.util.LinkedList; |
| 11 | +import java.util.List; |
| 12 | +import java.util.Map; |
| 13 | +import java.util.Objects; |
| 14 | +import java.util.Set; |
| 15 | + |
| 16 | +public class ExamMap { |
| 17 | + |
| 18 | + static class key_exam{ |
| 19 | + @NonNull |
| 20 | + String courseno; |
| 21 | + long sts; |
| 22 | + long ets; |
| 23 | + |
| 24 | + public key_exam(@NonNull String courseno, long sts, long ets) { |
| 25 | + this.courseno = courseno; |
| 26 | + this.sts = sts; |
| 27 | + this.ets = ets; |
| 28 | + } |
| 29 | + |
| 30 | + @Override |
| 31 | + public boolean equals(Object o) { |
| 32 | + if (this == o) return true; |
| 33 | + if (o == null || getClass() != o.getClass()) return false; |
| 34 | + key_exam key_exam = (key_exam) o; |
| 35 | + return sts == key_exam.sts && |
| 36 | + ets == key_exam.ets && |
| 37 | + courseno.equals(key_exam.courseno); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public int hashCode() { |
| 42 | + return Objects.hash(courseno, sts, ets); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + |
| 47 | + public static List<Map.Entry<ExamInfo,String>> Generate_ExamList(){ |
| 48 | + |
| 49 | + ExamInfoDao edao = MyApp.getCurrentAppDB().examInfoDao(); |
| 50 | + List<ExamInfo> exam_list = edao.selectFromToday(Clock.nowTimeStamp()); |
| 51 | + Map<key_exam,List<ExamInfo>> exam_map = new HashMap<>(); |
| 52 | + |
| 53 | + for(ExamInfo e : exam_list){ |
| 54 | + key_exam key = new key_exam(e.courseno,e.sts,e.ets); |
| 55 | + if(exam_map.containsKey(key)){ |
| 56 | + exam_map.get(key).add(e); |
| 57 | + }else { |
| 58 | + exam_map.put(key, new LinkedList<ExamInfo>(){ |
| 59 | + { |
| 60 | + add(e); |
| 61 | + } |
| 62 | + }); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + Set<key_exam> ks = exam_map.keySet(); |
| 67 | + |
| 68 | + List<Map.Entry<ExamInfo,String>> res = new LinkedList<>(); |
| 69 | + |
| 70 | + for(key_exam k : ks){ |
| 71 | + List<ExamInfo> elist = exam_map.get(k); |
| 72 | + String str = MyApp.gson.toJson(elist); |
| 73 | + |
| 74 | + StringBuilder sb = new StringBuilder(elist.get(0).croomno); |
| 75 | + for(int i=1; i<elist.size(); i++){ |
| 76 | + sb.append(",").append(elist.get(i).croomno); |
| 77 | + } |
| 78 | + ExamInfo examInfo = elist.get(0); |
| 79 | + examInfo.croomno = sb.toString(); |
| 80 | + |
| 81 | + res.add(Map.entry(examInfo,str)); |
| 82 | + |
| 83 | + } |
| 84 | + |
| 85 | + return res; |
| 86 | + } |
| 87 | + |
| 88 | + |
| 89 | +} |
0 commit comments