package net.sourceforge.fenixedu.domain; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import com.linkare.commons.metainfo.Linkare; public class GradeDistribution { private static final String A = "A"; private static final String B = "B"; private static final String C = "C"; private static final String D = "D"; private static final String E = "E"; @Linkare(author = "Paulo Zenida", comments = "Using a list instead of a single scale") private List gradeScales = new ArrayList(); private Map gradeDistribution; @Linkare(author = "Paulo Zenida", comments = "Added the second grade scale on the grade distribution constructor") static public GradeDistribution IST_SCALE_20 = new GradeDistribution(GradeScale.TYPE20, GradeScale.TYPE20_FULL_AP_RE_MISS_QUIT_NOTADMIT); static public GradeDistribution IST_SCALE_5 = new GradeDistribution(GradeScale.TYPE5); @Linkare(author = "Paulo Zenida", comments = "Added the second grade scale on the grade distribution constructor") static public GradeDistribution ECTS_SCALE_20 = new GradeDistribution(GradeScale.TYPE20, GradeScale.TYPE20_FULL_AP_RE_MISS_QUIT_NOTADMIT); static { IST_SCALE_20.addDistribution(Grade.createGrade("10", IST_SCALE_20.getGradeScale()), BigDecimal.valueOf(0), D); IST_SCALE_20.addDistribution(Grade.createGrade("11", IST_SCALE_20.getGradeScale()), BigDecimal.valueOf(0), D); IST_SCALE_20.addDistribution(Grade.createGrade("12", IST_SCALE_20.getGradeScale()), BigDecimal.valueOf(0), D); IST_SCALE_20.addDistribution(Grade.createGrade("13", IST_SCALE_20.getGradeScale()), BigDecimal.valueOf(0), D); IST_SCALE_20.addDistribution(Grade.createGrade("14", IST_SCALE_20.getGradeScale()), BigDecimal.valueOf(0), C); IST_SCALE_20.addDistribution(Grade.createGrade("15", IST_SCALE_20.getGradeScale()), BigDecimal.valueOf(0), C); IST_SCALE_20.addDistribution(Grade.createGrade("16", IST_SCALE_20.getGradeScale()), BigDecimal.valueOf(0), B); IST_SCALE_20.addDistribution(Grade.createGrade("17", IST_SCALE_20.getGradeScale()), BigDecimal.valueOf(0), B); IST_SCALE_20.addDistribution(Grade.createGrade("18", IST_SCALE_20.getGradeScale()), BigDecimal.valueOf(0), A); IST_SCALE_20.addDistribution(Grade.createGrade("19", IST_SCALE_20.getGradeScale()), BigDecimal.valueOf(0), A); IST_SCALE_20.addDistribution(Grade.createGrade("20", IST_SCALE_20.getGradeScale()), BigDecimal.valueOf(0), A); IST_SCALE_20.addDistribution(Grade.createGrade("10", IST_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(0), D); IST_SCALE_20.addDistribution(Grade.createGrade("11", IST_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(0), D); IST_SCALE_20.addDistribution(Grade.createGrade("12", IST_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(0), D); IST_SCALE_20.addDistribution(Grade.createGrade("13", IST_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(0), D); IST_SCALE_20.addDistribution(Grade.createGrade("14", IST_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(0), C); IST_SCALE_20.addDistribution(Grade.createGrade("15", IST_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(0), C); IST_SCALE_20.addDistribution(Grade.createGrade("16", IST_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(0), B); IST_SCALE_20.addDistribution(Grade.createGrade("17", IST_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(0), B); IST_SCALE_20.addDistribution(Grade.createGrade("18", IST_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(0), A); IST_SCALE_20.addDistribution(Grade.createGrade("19", IST_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(0), A); IST_SCALE_20.addDistribution(Grade.createGrade("20", IST_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(0), A); IST_SCALE_5.addDistribution(Grade.createGrade("3", IST_SCALE_5.getGradeScale()), BigDecimal.valueOf(0), C); IST_SCALE_5.addDistribution(Grade.createGrade("4", IST_SCALE_5.getGradeScale()), BigDecimal.valueOf(0), B); IST_SCALE_5.addDistribution(Grade.createGrade("5", IST_SCALE_5.getGradeScale()), BigDecimal.valueOf(0), A); ECTS_SCALE_20.addDistribution(Grade.createGrade("10", ECTS_SCALE_20.getGradeScale()), BigDecimal.valueOf(10), E); ECTS_SCALE_20.addDistribution(Grade.createGrade("11", ECTS_SCALE_20.getGradeScale()), BigDecimal.valueOf(10), E); ECTS_SCALE_20.addDistribution(Grade.createGrade("12", ECTS_SCALE_20.getGradeScale()), BigDecimal.valueOf(10), D); ECTS_SCALE_20.addDistribution(Grade.createGrade("13", ECTS_SCALE_20.getGradeScale()), BigDecimal.valueOf(20), C); ECTS_SCALE_20.addDistribution(Grade.createGrade("14", ECTS_SCALE_20.getGradeScale()), BigDecimal.valueOf(30), B); ECTS_SCALE_20.addDistribution(Grade.createGrade("15", ECTS_SCALE_20.getGradeScale()), BigDecimal.valueOf(40), B); ECTS_SCALE_20.addDistribution(Grade.createGrade("16", ECTS_SCALE_20.getGradeScale()), BigDecimal.valueOf(50), A); ECTS_SCALE_20.addDistribution(Grade.createGrade("17", ECTS_SCALE_20.getGradeScale()), BigDecimal.valueOf(60), A); ECTS_SCALE_20.addDistribution(Grade.createGrade("18", ECTS_SCALE_20.getGradeScale()), BigDecimal.valueOf(70), A); ECTS_SCALE_20.addDistribution(Grade.createGrade("19", ECTS_SCALE_20.getGradeScale()), BigDecimal.valueOf(80), A); ECTS_SCALE_20.addDistribution(Grade.createGrade("20", ECTS_SCALE_20.getGradeScale()), BigDecimal.valueOf(90), A); ECTS_SCALE_20.addDistribution(Grade.createGrade("10", ECTS_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(10), E); ECTS_SCALE_20.addDistribution(Grade.createGrade("11", ECTS_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(10), E); ECTS_SCALE_20.addDistribution(Grade.createGrade("12", ECTS_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(10), D); ECTS_SCALE_20.addDistribution(Grade.createGrade("13", ECTS_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(20), C); ECTS_SCALE_20.addDistribution(Grade.createGrade("14", ECTS_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(30), B); ECTS_SCALE_20.addDistribution(Grade.createGrade("15", ECTS_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(40), B); ECTS_SCALE_20.addDistribution(Grade.createGrade("16", ECTS_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(50), A); ECTS_SCALE_20.addDistribution(Grade.createGrade("17", ECTS_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(60), A); ECTS_SCALE_20.addDistribution(Grade.createGrade("18", ECTS_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(70), A); ECTS_SCALE_20.addDistribution(Grade.createGrade("19", ECTS_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(80), A); ECTS_SCALE_20.addDistribution(Grade.createGrade("20", ECTS_SCALE_20.getGradeScale(1)), BigDecimal.valueOf(90), A); } @Linkare(author = "Paulo Zenida", comments = "Changed from a single value argument to a vararg argument") private GradeDistribution(final GradeScale... gradeScales) { this.gradeScales = Arrays.asList(gradeScales); this.gradeDistribution = new ConcurrentHashMap(); } @Linkare(author = "Paulo Zenida", comments = "Changed the implementation to return the first grade scale on the list") public GradeScale getGradeScale() { return gradeScales.isEmpty() ? null : gradeScales.get(0); } @Linkare(author = "Paulo Zenida") public GradeScale getGradeScale(int index) { return index >= gradeScales.size() ? null : gradeScales.get(index); } public Distribution addDistribution(final Grade grade, final BigDecimal percentage, final String ectsScale) { final Distribution result = new Distribution(grade, percentage, ectsScale); this.gradeDistribution.put(grade, result); return result; } @Linkare(author = "Paulo Zenida", comments = "Used the method returning the first grade scale after the change from a single scale to a list") public Distribution getDistribution(final Integer value) { return getDistribution(Grade.createGrade(String.valueOf(value), getGradeScale())); } @Linkare(author = "Paulo Zenida", comments = "Used the method returning the first grade scale after the change from a single scale to a list") public Distribution getDistribution(final String value) { return getDistribution(Grade.createGrade(value, getGradeScale())); } @Linkare(author = "Paulo Zenida", comments = "Changed the logic to check for equivalent grade scales instead of checking for the exact same scale") public Distribution getDistribution(final Grade grade) { if (!gradeScales.contains(grade.getGradeScale())) { throw new DomainException("GradeDistribution.invalid.grade.scale"); } return gradeDistribution.get(grade); } public class Distribution { private Grade grade; private BigDecimal percentage; private String scale; public Distribution(Grade grade, BigDecimal percentage, String ectsScale) { this.grade = grade; this.percentage = percentage; this.scale = ectsScale; } public Grade getGrade() { return grade; } public BigDecimal getPercentage() { return percentage; } public String getScale() { return scale; } } }