2016-09-13 18:52:27 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								package models;
							 | 
						
					
						
							
								
									
										
										
										
											2016-10-04 17:54:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-09-13 18:52:27 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import java.util.HashMap;
							 | 
						
					
						
							
								
									
										
										
										
											2016-10-04 17:29:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import java.util.HashSet;
							 | 
						
					
						
							
								
									
										
										
										
											2016-09-13 18:52:27 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import java.util.Map;
							 | 
						
					
						
							
								
									
										
										
										
											2016-10-03 22:06:01 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import java.util.Set;
							 | 
						
					
						
							
								
									
										
										
										
											2016-09-13 18:52:27 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public class StudentStore {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    private static StudentStore instance;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    private Map<Integer, Student> students = new HashMap<>();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    public static StudentStore getInstance() {
							 | 
						
					
						
							
								
									
										
										
										
											2016-10-04 17:54:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (instance == null) {
							 | 
						
					
						
							
								
									
										
										
										
											2016-09-13 18:52:27 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            instance = new StudentStore();
							 | 
						
					
						
							
								
									
										
										
										
											2016-10-04 17:54:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2016-09-13 18:52:27 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return instance;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    public Student addStudent(Student student) {
							 | 
						
					
						
							
								
									
										
										
										
											2016-10-04 17:54:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        int id = students.size();
							 | 
						
					
						
							
								
									
										
										
										
											2016-09-13 18:52:27 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        student.setId(id);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        students.put(id, student);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return student;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    public Student getStudent(int id) {
							 | 
						
					
						
							
								
									
										
										
										
											2016-10-03 22:06:01 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        return students.get(id);
							 | 
						
					
						
							
								
									
										
										
										
											2016-09-13 18:52:27 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-10-03 22:06:01 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    public Set<Student> getAllStudents() {
							 | 
						
					
						
							
								
									
										
										
										
											2016-10-04 17:29:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        return new HashSet<>(students.values());
							 | 
						
					
						
							
								
									
										
										
										
											2016-09-13 18:52:27 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    public Student updateStudent(Student student) {
							 | 
						
					
						
							
								
									
										
										
										
											2016-10-04 17:54:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        int id = student.getId();
							 | 
						
					
						
							
								
									
										
										
										
											2016-09-13 18:52:27 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (students.containsKey(id)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            students.put(id, student);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return student;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return null;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    public boolean deleteStudent(int id) {
							 | 
						
					
						
							
								
									
										
										
										
											2016-10-04 17:24:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        return students.remove(id) != null;
							 | 
						
					
						
							
								
									
										
										
										
											2016-09-13 18:52:27 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |