Can I use a utility class like this?
public final class ProfessorDirectory {
private static Map<String, Professor> directory = new HashMap<>();
private ProfessorDirectory() {
throw new IllegalStateException("Utility Class");
}
static void addProfessorsFromDescription(String description) {
String regex = "(?<=\\n).* .*(?=\\n)";
Matcher m = Pattern.compile(regex).matcher(description);
while (m.find()) {
String professorName = Professor.formater(m.group(0));
directory.put(professorName, new Professor(professorName));
}
}
public static Professor get(String firstName, String lastName) {
return directory.get(Professor.formater(firstName, lastName));
}
}
I used this to create a library in which you can retrieve a teacher's planning.
Exemple of utilisation:
Planning professorPlanning = schedules.getPlanningOf(ProfessorDirectory.get("Jack", "Sticky"));
The ProfessorDirectory
is initialized internally, and should never be initialized by the user.