Alfred Samanga 5bce8b22a1 BAEL-3059: Update Play Framework (#7674)
* Implementation of Introduction to Play Framework in Java

* Implementation of Introduction to Play Framework in Java

* Implementation of Introduction to Play Framework in Java

* Implementation of the tutorial for Introduction to Play Framework.

* Updated code for Play Routing to 2.7.3

* Updated code for Play Routing to 2.7.3

* Initial Commit

* Added request object to create end point

* Finished implementing student-api

* Finished implementing student-api

* Implementation of the tutorial for Introduction to Play Framework.

* Updated test names

* Removed Lombok dependency

* Corrected isSuccessful spelling and removed the +1 on student ids
2019-09-06 09:39:18 -05:00

38 lines
937 B
Java

package store;
import model.Student;
import java.util.*;
public class StudentStore {
private Map<Integer, Student> students = new HashMap<>();
public Optional<Student> addStudent(Student student) {
int id = students.size();
student.setId(id);
students.put(id, student);
return Optional.ofNullable(student);
}
public Optional<Student> getStudent(int id) {
return Optional.ofNullable(students.get(id));
}
public Set<Student> getAllStudents() {
return new HashSet<>(students.values());
}
public Optional<Student> updateStudent(Student student) {
int id = student.getId();
if (students.containsKey(id)) {
students.put(id, student);
return Optional.ofNullable(student);
}
return Optional.empty();
}
public boolean deleteStudent(int id) {
return students.remove(id) != null;
}
}