package net.sourceforge.fenixedu.domain.studentCurriculum; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Set; import net.sourceforge.fenixedu.domain.IEnrolment; import net.sourceforge.fenixedu.domain.student.curriculum.ICurriculumEntry; /** * * @author rjmvo * */ public final class ISCTEEnrolmentWrapperUtils { private ISCTEEnrolmentWrapperUtils() { } public static boolean hasEnrolmentWrappers(ICurriculumEntry entry, CurriculumGroup curriculumGroup) { return !getEnrolmentWrappers(entry, curriculumGroup).isEmpty(); } private static Set getEnrolmentWrappers(ICurriculumEntry entry, CurriculumGroup curriculumGroup) { final Set result = new HashSet(); for (final EnrolmentWrapper wrapper : getEnrolmentWrappers(entry)) { if (wrapper instanceof ISCTECurriculumEntryWrapper && wrapper.hasCredits() && !(wrapper.getCredits() instanceof ISCTETransitionCredits) && !wrapper.getCredits().isEquivalence() && wrapper.getCredits().hasAnyDismissalFor(curriculumGroup)) { result.add((ISCTECurriculumEntryWrapper) wrapper); } } return result; } public static BigDecimal getEnrolmentWrappersWeight(ICurriculumEntry entry, CurriculumGroup curriculumGroup) { BigDecimal credits = BigDecimal.ZERO; for (ISCTECurriculumEntryWrapper wrapper : getEnrolmentWrappers(entry, curriculumGroup)) { credits = credits.add(wrapper.getWeight()); } return credits.setScale(1, RoundingMode.HALF_EVEN); } public static BigDecimal getEnrolmentWrappersEctsCredits(ICurriculumEntry entry, CurriculumGroup curriculumGroup) { BigDecimal credits = BigDecimal.ZERO; for (ISCTECurriculumEntryWrapper wrapper : getEnrolmentWrappers(entry, curriculumGroup)) { credits = credits.add(wrapper.getEctsCredits()); } return credits.setScale(1, RoundingMode.HALF_EVEN); } private static Collection getEnrolmentWrappers(ICurriculumEntry entry) { if (entry instanceof IEnrolment) { return ((IEnrolment) entry).getEnrolmentWrappers(); } else if (entry instanceof Dismissal) { return ((Dismissal) entry).getDismissalWrappers(); } return Collections.emptySet(); } }