My thought would be to have a class that handles the creation of areas (maybe your Application class).
In this case, the application can basically be held on the area map in some form of Area identifier. If you find an area that does not exist yet, you can create it at this point and save it on the map for other fragments that will be used later.
As regards the sorting of students, this is apparently not the task of the Area. Perhaps using something like that StudentManagerwould make more sense.
Here is how I imagine it (in a simplified form):
class Student {
String name;
}
class School {
List<Student> students;
boolean contains(Student) {
return students.contains(student);
}
}
class Area {
List<School> schools;
}
class StudentManager {
Map<School, Set<Student>> sortIntoSchools(Collection<Student> unsortedStudents) {
Map<School, Set<Student>> result = new HashMap<>();
for(Student student : unsortedStudents) {
for(Area area : areas) {
for(School school : area.schools) {
if(school.contains(student)){
result.get(school).add(student);
}
}
}
}
}
}
I'm sure you can improve the sorting of StudentManager classes, but this separation makes some sense to me ...
source
share