Does Realm for Java allows nested custom Class? I am trying to figure out how to use realm for the Directory class which has Map<String, School>.
Is the following class possible to convert to realm. If not, is there any alternative to use realm for the following?
I can see the potential of realm, and I hope I will be able to learn from it. Thanks.
My Sample data as followed:
school id: A1, "Point Grey"
Student name: "Kent", "Age": 43
Student name: "Jane", "Age": 18
Student name: "Winnie", "Age": 19
school id: B1, "Prince of Wales"
Student name: "Steven", "Age": 11
Student name: "Michelle", "Age": 30
Student name: "Ronald", "Age": 20
My Directory Class is as followed:
public class DIRECTORY {
private Map<String, SCHOOL> schools = new HashMap<String, SCHOOL>();
public void setSchools(Map<String, SCHOOL> schoolsMap) {
this.schools = schoolsMap;
}
public Map<String, SCHOOL> getSchools() {return this.schools;}
public void addSchool(String schoolId, String schoolName) {
SCHOOL school = new SCHOOL();
school.setSchoolId(schoolId);
school.setSchoolName(schoolName);
schools.put(schoolId,school);
}
public SCHOOL getSchoolById(String schoolId) {
return schools.get(schoolId);
}
}
My Class for School as followed:
public class SCHOOL {
private String schoolId;
private String schoolName;
private List<STUDENT> students = new ArrayList<>();
//Getter and setter for schooled and schoolname
public void setStudents(List<STUDENT> students) {
this.students = students;
}
public List<STUDENT> getStudents() {return this.students;}
public void addStudent(String names, String age) {
STUDENT student = new STUDENT();
student.setNames(names);
student.setAge(age);
students.add(student);
}
}
My student Class as followed:
public class STUDENT {
private String names;
private String age;
//getters and setters for names and age
}