-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProjectManager.java
More file actions
46 lines (37 loc) · 1.14 KB
/
ProjectManager.java
File metadata and controls
46 lines (37 loc) · 1.14 KB
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
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Control object that manages the list of projects and delegates
* persistence to FileManager.
*/
public class ProjectManager {
private List<Project> projects;
private FileManager fileManager;
public ProjectManager() {
this.projects = new ArrayList<>();
this.fileManager = new FileManager("projects.dat");
}
public void addProject(Project p) {
projects.add(p);
}
public void updateProject(Project oldProject, Project newProject) {
int idx = projects.indexOf(oldProject);
if (idx >= 0) {
projects.set(idx, newProject);
}
}
public void deleteProject(Project p) {
projects.remove(p);
}
public List<Project> getProjects() {
// return a copy so GUI can’t accidentally mutate internal list
return new ArrayList<>(projects);
}
public void saveAll() throws IOException {
fileManager.write(projects);
}
public void loadAll() throws IOException, ClassNotFoundException {
this.projects = fileManager.read();
}
}