if (minCapacity != null && maxCapacity != null) { if (students.size() < minCapacity || students.size() > maxCapacity) throw new DomainException(this.getClass().getName(), "error.invalidNumberOfStudents"); }  if (groupMaximumNumber != null) { if (shift == null) { List studentGroupsWithoutShift = this.getStudentGroupsWithoutShift(); if (studentGroupsWithoutShift != null && studentGroupsWithoutShift.size() == groupMaximumNumber) throw new DomainException(this.getClass().getName(), "error.invalidNumberOfStudentGroupsWithoutGroup"); } else { List studentGroupsWithShift = this.getStudentGroupsWithShift(shift); if (studentGroupsWithShift != null && studentGroupsWithShift.size() == groupMaximumNumber) throw new DomainException(this.getClass().getName(), "error.invalidNumberOfStudentGroups"); } }
IGroupEnrolmentStrategyFactory enrolmentStrategyFactory = GroupEnrolmentStrategyFactory.getInstance(); IGroupEnrolmentStrategy enrolmentStrategy = enrolmentStrategyFactory.getGroupEnrolmentStrategyInstance(this);  Integer result = null; if(students != null){ result = enrolmentStrategy.enrolmentPolicyNewGroup(this, students.size(), shift); if(result == -3) throw new DomainException(this.getClass().getName(), "error.invalidMaximunNumberOfStudents"); else if(result == -2) throw new DomainException(this.getClass().getName(), "error.invalidMinimumNumberOfStudents"); else if(result == -1) throw new DomainException(this.getClass().getName(), "error.invalidNumberOfStudentGroups"); }
    private void checkCapacities(IShift shift, List<IStudent> students, Integer minCapacity, Integer maxCapacity, Integer groupMaximumNumber) {        if (minCapacity != null && maxCapacity != null) {            if (students.size() < minCapacity || students.size() > maxCapacity)                throw new DomainException(this.getClass().getName(), "error.invalidNumberOfStudents");        }        if (groupMaximumNumber != null) {            if (shift == null) {                List studentGroupsWithoutShift = this.getStudentGroupsWithoutShift();                if (studentGroupsWithoutShift != null                        && studentGroupsWithoutShift.size() == groupMaximumNumber)                    throw new DomainException(this.getClass().getName(),                            "error.invalidNumberOfStudentGroupsWithoutGroup");            } else {                List studentGroupsWithShift = this.getStudentGroupsWithShift(shift);                if (studentGroupsWithShift != null                        && studentGroupsWithShift.size() == groupMaximumNumber)                    throw new DomainException(this.getClass().getName(),                            "error.invalidNumberOfStudentGroups");            }        }    }