| 1 | package edu.ucsb.cs156.courses.documents; | |
| 2 | ||
| 3 | import java.util.ArrayList; | |
| 4 | import java.util.Comparator; | |
| 5 | import java.util.List; | |
| 6 | import lombok.AllArgsConstructor; | |
| 7 | import lombok.Builder; | |
| 8 | import lombok.Data; | |
| 9 | import lombok.NoArgsConstructor; | |
| 10 | import lombok.extern.slf4j.Slf4j; | |
| 11 | import org.springframework.data.mongodb.core.mapping.Document; | |
| 12 | ||
| 13 | @Slf4j | |
| 14 | @Data | |
| 15 | @Builder | |
| 16 | @NoArgsConstructor | |
| 17 | @AllArgsConstructor | |
| 18 | @Document(collection = "primaries") | |
| 19 | public class Primary { | |
| 20 | private String quarter; | |
| 21 | private String courseId; | |
| 22 | private String title; | |
| 23 | private String description; | |
| 24 | private Section primary; | |
| 25 | private List<Section> subRows; | |
| 26 | private List<GeneralEducation> generalEducation; | |
| 27 | ||
| 28 | /** | |
| 29 | * Convert a flat list of {@link ConvertedSection} objects into a list of Primary objects, where | |
| 30 | * each Primary contains a primary section (e.g. a lecture) and its secondary sections (e.g. | |
| 31 | * discussion sections) as subRows. The result is sorted by quarter descending, then by course id | |
| 32 | * (a search may match several courses, e.g. 130A and 130B), then by section number ascending, so | |
| 33 | * that secondary sections immediately follow their primary section. | |
| 34 | * | |
| 35 | * @param convertedSections a flat list of ConvertedSection objects | |
| 36 | * @return a list of Primary objects | |
| 37 | */ | |
| 38 | public static List<Primary> fromConvertedSections(List<ConvertedSection> convertedSections) { | |
| 39 | List<ConvertedSection> sorted = new ArrayList<>(convertedSections); | |
| 40 |
1
1. fromConvertedSections : removed call to java/util/List::sort → KILLED |
sorted.sort( |
| 41 | Comparator.comparing( | |
| 42 |
1
1. lambda$fromConvertedSections$0 : replaced return value with "" for edu/ucsb/cs156/courses/documents/Primary::lambda$fromConvertedSections$0 → KILLED |
(ConvertedSection cs) -> cs.getCourseInfo().getQuarter(), |
| 43 | Comparator.nullsLast(Comparator.reverseOrder())) | |
| 44 | .thenComparing( | |
| 45 |
1
1. lambda$fromConvertedSections$1 : replaced return value with "" for edu/ucsb/cs156/courses/documents/Primary::lambda$fromConvertedSections$1 → KILLED |
cs -> cs.getCourseInfo().getCourseId(), |
| 46 | Comparator.nullsLast(Comparator.naturalOrder())) | |
| 47 | .thenComparing( | |
| 48 |
1
1. lambda$fromConvertedSections$2 : replaced return value with "" for edu/ucsb/cs156/courses/documents/Primary::lambda$fromConvertedSections$2 → KILLED |
cs -> cs.getSection().getSection(), |
| 49 | Comparator.nullsLast(Comparator.naturalOrder()))); | |
| 50 | ||
| 51 | List<Primary> result = new ArrayList<>(); | |
| 52 | Primary current = null; | |
| 53 | for (ConvertedSection cs : sorted) { | |
| 54 | CourseInfo courseInfo = cs.getCourseInfo(); | |
| 55 | Section section = cs.getSection(); | |
| 56 |
1
1. fromConvertedSections : negated conditional → KILLED |
boolean sameCourse = |
| 57 | current != null | |
| 58 |
1
1. fromConvertedSections : negated conditional → KILLED |
&& java.util.Objects.equals(current.getQuarter(), courseInfo.getQuarter()) |
| 59 |
1
1. fromConvertedSections : negated conditional → KILLED |
&& java.util.Objects.equals(current.getCourseId(), courseInfo.getCourseId()); |
| 60 |
2
1. fromConvertedSections : negated conditional → KILLED 2. fromConvertedSections : negated conditional → KILLED |
if (section.isPrimary() || !sameCourse) { |
| 61 | current = | |
| 62 | Primary.builder() | |
| 63 | .quarter(courseInfo.getQuarter()) | |
| 64 | .courseId(courseInfo.getCourseId()) | |
| 65 | .title(courseInfo.getTitle()) | |
| 66 | .description(courseInfo.getDescription()) | |
| 67 | .primary(section) | |
| 68 | .subRows(new ArrayList<>()) | |
| 69 | .generalEducation(courseInfo.getGeneralEducation()) | |
| 70 | .build(); | |
| 71 | result.add(current); | |
| 72 | } else { | |
| 73 | current.getSubRows().add(section); | |
| 74 | } | |
| 75 | } | |
| 76 |
1
1. fromConvertedSections : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/documents/Primary::fromConvertedSections → KILLED |
return result; |
| 77 | } | |
| 78 | } | |
Mutations | ||
| 40 |
1.1 |
|
| 42 |
1.1 |
|
| 45 |
1.1 |
|
| 48 |
1.1 |
|
| 56 |
1.1 |
|
| 58 |
1.1 |
|
| 59 |
1.1 |
|
| 60 |
1.1 2.2 |
|
| 76 |
1.1 |