-
Notifications
You must be signed in to change notification settings - Fork 0
/
CourseList.java
125 lines (113 loc) · 3.16 KB
/
CourseList.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* This is going to set up the list of courses
* @author word.exe
*/
import java.util.ArrayList;
import java.util.UUID;
public class CourseList {
private static CourseList courseList;
private ArrayList<Course> courses;
/**
* This is going to get the arraylist for course and set it to courses
*/
private CourseList() {
this.courses = new ArrayList<Course>();
}
/**
* This is going to get the instance of when the course list is used
* @return the course list is returned
*/
public static CourseList getInstance() {
if(courseList == null) {
courseList = new CourseList();
}
return courseList;
}
/**
* This is going to allow for search when looking for courses by name
* @param keyword the keyword of the word looking up for the course name
* @return the name of the course
*/
public ArrayList<Course> SearchCoursesByName(String keyword) {
ArrayList<Course> courseList = new ArrayList<Course>();
for(Course course: courses) {
if(course.getCourseName().contains(keyword)) {
courseList.add(course);
}
}
return courseList;
}
/**
* This is going to get the course by name
* @param keyword the keyword is the word looking up for the course name
* @return the name of the course
*/
public Course getCourseByName(String keyword) {
for(Course course: courses) {
if(course.getCourseName().equals(keyword)) {
return course;
}
}
return null;
}
/**
* Gets the course by the ID
* @param courseID the course ID
* @return the course based on the ID
*/
public Course getCourseByID(UUID courseID) {
for(Course course: courses) {
if(course.getCourseID().equals(courseID)) {
return course;
}
}
return null;
}
/**
* This is going to add in thnulle courses
*
* @param course the course being used
*/
public void addCourse(Course course) {
courses.add(course);
}
/**
* This is going to delete the course
* @param course the course being used
*/
public void deleteCourse(Course course) {
courses.remove(course);
}
/**
* This is going to read the courses from the JSON file
*/
public void readCoursesJSON() {
this.courses = DataLoader.loadCourses();
}
/**
* This is going to save the courses
*/
public void save() {
DataWriter.writeCourses(courses);
}
/**
* This is going to get the courses based on the list of courses
* @return the course
*/
public ArrayList<Course> getCourses() {
return this.courses;
}
/**
* This is a string to tell whether or not there are courses or if it is an empty string
*/
public String toString() {
if(this.courses.isEmpty()) {
return "NO COURSES";
}
String ret = "";
for(Course course : courses) {
ret += course.toString() + '\n';
}
return ret;
}
}