0

このようなユーティリティ クラスを使用できますか?

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));
    }

}

これを使用して、教師の計画を取得できるライブラリを作成しました。

利用例:

Planning professorPlanning = schedules.getPlanningOf(ProfessorDirectory.get("Jack", "Sticky"));

ProfessorDirectory内部で初期化されるため、ユーザーが初期化することはできません。

4

1 に答える 1