1
edit
Changes
→Add Model Provider
==== Add Model Provider ====
"ModelProvider" class creates and maintains an ArrayList of Student objects and helps us find an student by it's id from the list of students.<br/>
<code>Student.java </code>
<source lang=java>
package cs.ecl.rcp.simplercp.model;
import java.util.ArrayList;
import java.util.List;
public enum ModelProvider {
INSTANCE;
private List<Student> students;
private ModelProvider() {
students = new ArrayList<Student>();
// Data could be retrieved here from database
students.add(new Student("01234567","Ladan", "Zahiroleslam", "CPA"));
students.add(new Student("09876543", "Anastasia", "Semionova", "CPA"));
students.add(new Student("01122334", "Minoo", "Ziaei", "CPA"));
students.add(new Student("02233445", "Sergiu", "Ecob", "CPA"));
}
public Student getPersonById(String id) {
for (Student student : students) {
if (student.getId() == id) {
return student;
}
}
return null;
}
public List<Student> getStudents() {
return students;
}
}
</source>