1 | package edu.ucsb.cs156.courses.documents; | |
2 | ||
3 | import java.util.ArrayList; | |
4 | import java.util.List; | |
5 | ||
6 | import com.fasterxml.jackson.core.JsonProcessingException; | |
7 | import com.fasterxml.jackson.databind.DeserializationFeature; | |
8 | import com.fasterxml.jackson.databind.ObjectMapper; | |
9 | ||
10 | import lombok.AllArgsConstructor; | |
11 | import lombok.Builder; | |
12 | import lombok.Data; | |
13 | import lombok.NoArgsConstructor; | |
14 | import lombok.extern.slf4j.Slf4j; | |
15 | ||
16 | @Data | |
17 | @NoArgsConstructor | |
18 | @Slf4j | |
19 | public class CoursePage { | |
20 | private int pageNumber; | |
21 | private int pageSize; | |
22 | private int total; | |
23 | private List<Course> classes; | |
24 | ||
25 | /** | |
26 | * Create a CoursePage object from json representation | |
27 | * | |
28 | * @param json String of json returned by API endpoint {@code /classes/search} | |
29 | * @return a new CoursePage object | |
30 | * @see <a href= | |
31 | * "https://developer.ucsb.edu/content/academic-curriculums">https://developer.ucsb.edu/content/academic-curriculums</a> | |
32 | */ | |
33 | public static CoursePage fromJSON(String json) { | |
34 | try { | |
35 | ObjectMapper objectMapper = new ObjectMapper(); | |
36 | objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | |
37 | ||
38 | CoursePage coursePage = objectMapper.readValue(json, CoursePage.class); | |
39 |
1
1. fromJSON : replaced return value with null for edu/ucsb/cs156/courses/documents/CoursePage::fromJSON → KILLED |
return coursePage; |
40 | } catch (JsonProcessingException jpe) { | |
41 | log.error("JsonProcessingException:" + jpe); | |
42 | return null; | |
43 | } | |
44 | } | |
45 | ||
46 | /** | |
47 | * Create a List of ConvertedSections from json representation | |
48 | * | |
49 | * @return a list of converted sections | |
50 | */ | |
51 | public List<ConvertedSection> convertedSections() { | |
52 | ||
53 | List<ConvertedSection> result = new ArrayList<ConvertedSection>(); | |
54 | ||
55 | for (Course c : this.getClasses()) { | |
56 | for (Section section : c.getClassSections()) { | |
57 |
1
1. convertedSections : Replaced integer division with multiplication → KILLED |
int lectureNum = Integer.parseInt(section.getSection()) / 100; |
58 | CourseInfo courseInfo = CourseInfo.builder() | |
59 | .quarter(c.getQuarter()) | |
60 | .courseId(c.getCourseId() + "-" + Integer.toString(lectureNum)) | |
61 | .title(c.getTitle()) | |
62 | .description(c.getDescription()) | |
63 | .build(); | |
64 | ConvertedSection cs = ConvertedSection.builder() | |
65 | .courseInfo(courseInfo) | |
66 | .section(section) | |
67 | .build(); | |
68 | result.add(cs); | |
69 | ||
70 | } | |
71 | } | |
72 |
1
1. convertedSections : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/documents/CoursePage::convertedSections → KILLED |
return result; |
73 | } | |
74 | ||
75 | } | |
Mutations | ||
39 |
1.1 |
|
57 |
1.1 |
|
72 |
1.1 |