3 major changes (#716)

* made changes to java reflection

* removed redundant method makeSound in Animal abstract class

* added project for play-framework article

* added project for regex

* changed regex project from own model to core-java

* added project for routing in play

* made changes to regex project

* refactored code for REST API with Play project
This commit is contained in:
Egima profile
2016-10-03 22:06:01 +03:00
committed by Grzegorz Piwowarek
parent 222c4b6a98
commit 455c71ae71
30 changed files with 1685 additions and 206 deletions
@@ -38,8 +38,8 @@ public class StudentController extends Controller {
return ok(Util.createResponse(jsonObjects,true));
}
public Result listStudents() {
List<Student> result=StudentStore.getInstance().getAllStudents();
ObjectMapper mapper = new ObjectMapper();
Set<Student> result=StudentStore.getInstance().getAllStudents();
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonData=mapper.convertValue(result, JsonNode.class);
return ok(Util.createResponse(jsonData,true));
@@ -3,6 +3,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class StudentStore {
private static StudentStore instance;
@@ -22,19 +23,16 @@ public class StudentStore {
}
public Student getStudent(int id) {
if (students.containsKey(id))
return students.get(id);
return null;
return students.get(id);
}
public List<Student> getAllStudents() {
return new ArrayList<Student>(students.values());
public Set<Student> getAllStudents() {
return (Set<Student>)students.values();
}
public Student updateStudent(Student student) {
int id=student.getId();
if (students.containsKey(id)) {
student.setId(id);
students.put(id, student);
return student;
}
@@ -42,11 +40,11 @@ public class StudentStore {
}
public boolean deleteStudent(int id) {
if (!students.containsKey(id))
Student student=students.remove(id);
if (student == null)
return false;
students.remove(id);
return true;
else
return true;
}
}