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