2016-09-13 11:52:27 -04:00
|
|
|
package models;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2016-10-03 15:06:01 -04:00
|
|
|
import java.util.Set;
|
2016-09-13 11:52:27 -04:00
|
|
|
|
|
|
|
public class StudentStore {
|
|
|
|
private static StudentStore instance;
|
|
|
|
private Map<Integer, Student> students = new HashMap<>();
|
|
|
|
|
|
|
|
public static StudentStore getInstance() {
|
|
|
|
if (instance == null)
|
|
|
|
instance = new StudentStore();
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Student addStudent(Student student) {
|
|
|
|
int id = students.size() + 1;
|
|
|
|
student.setId(id);
|
|
|
|
students.put(id, student);
|
|
|
|
return student;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Student getStudent(int id) {
|
2016-10-03 15:06:01 -04:00
|
|
|
return students.get(id);
|
2016-09-13 11:52:27 -04:00
|
|
|
}
|
|
|
|
|
2016-10-03 15:06:01 -04:00
|
|
|
public Set<Student> getAllStudents() {
|
|
|
|
return (Set<Student>)students.values();
|
2016-09-13 11:52:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public Student updateStudent(Student student) {
|
|
|
|
int id=student.getId();
|
|
|
|
if (students.containsKey(id)) {
|
|
|
|
students.put(id, student);
|
|
|
|
return student;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean deleteStudent(int id) {
|
2016-10-03 15:06:01 -04:00
|
|
|
Student student=students.remove(id);
|
|
|
|
if (student == null)
|
2016-09-13 11:52:27 -04:00
|
|
|
return false;
|
2016-10-03 15:06:01 -04:00
|
|
|
else
|
|
|
|
return true;
|
2016-09-13 11:52:27 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|