Commit e76c84d6 authored by Ådne Karstad's avatar Ådne Karstad

[minor] Add getCredits operations for semester and program

parent 35acb980
......@@ -12,5 +12,6 @@ Export-Package: tdt4250.spp,
tdt4250.spp.impl,
tdt4250.spp.util
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.emf.ecore;visibility:=reexport
org.eclipse.emf.ecore;visibility:=reexport,
org.eclipse.emf.ecore.xmi;bundle-version="2.16.0"
Bundle-ActivationPolicy: lazy
......@@ -18,8 +18,9 @@
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Program">
<eAnnotations source="http://www.eclipse.org/emf/2002/Ecore">
<details key="constraints" value="needsEnoughSemesters semestersNeedToBeUniqueByYearAndSeason"/>
<details key="constraints" value="needsEnoughSemesters"/>
</eAnnotations>
<eOperations name="getCredits" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFloat"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="duration" eType="#//LevelType"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="semesters" upperBound="-1"
......@@ -32,6 +33,10 @@
eType="#//ElectiveCourses" containment="true" eOpposite="#//ElectiveCourses/program"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Semester">
<eAnnotations source="http://www.eclipse.org/emf/2002/Ecore">
<details key="constraints" value="needsEnoughCredits"/>
</eAnnotations>
<eOperations name="getCredits" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFloat"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="season" eType="#//SeasonType"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="year" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EIntegerObject"
defaultValueLiteral="1"/>
......
......@@ -46,6 +46,7 @@
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute spp.ecore#//Semester/year"/>
<genFeatures property="None" notify="false" createChild="false" ecoreFeature="ecore:EReference spp.ecore#//Semester/program"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference spp.ecore#//Semester/selectedCourses"/>
<genOperations ecoreOperation="spp.ecore#//Semester/getCredits"/>
</genClasses>
<genClasses ecoreClass="spp.ecore#//Course">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute spp.ecore#//Course/code"/>
......
......@@ -24,7 +24,7 @@ import org.eclipse.emf.ecore.EObject;
* </ul>
*
* @see tdt4250.spp.SppPackage#getProgram()
* @model annotation="http://www.eclipse.org/emf/2002/Ecore constraints='needsEnoughSemesters semestersNeedToBeUniqueByYearAndSeason'"
* @model annotation="http://www.eclipse.org/emf/2002/Ecore constraints='needsEnoughSemesters'"
* @generated
*/
public interface Program extends EObject {
......@@ -141,4 +141,12 @@ public interface Program extends EObject {
*/
EList<ElectiveCourses> getElectiveCourses();
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @model kind="operation"
* @generated
*/
float getCredits();
} // Program
......@@ -22,7 +22,7 @@ import org.eclipse.emf.ecore.EObject;
* </ul>
*
* @see tdt4250.spp.SppPackage#getSemester()
* @model
* @model annotation="http://www.eclipse.org/emf/2002/Ecore constraints='needsEnoughCredits'"
* @generated
*/
public interface Semester extends EObject {
......@@ -110,4 +110,12 @@ public interface Semester extends EObject {
*/
EList<Course> getSelectedCourses();
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @model kind="operation"
* @generated
*/
float getCredits();
} // Semester
......@@ -5,6 +5,7 @@ package tdt4250.spp;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
......@@ -240,6 +241,15 @@ public interface SppPackage extends EPackage {
*/
int PROGRAM_FEATURE_COUNT = 6;
/**
* The operation id for the '<em>Get Credits</em>' operation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int PROGRAM___GET_CREDITS = 0;
/**
* The number of operations of the '<em>Program</em>' class.
* <!-- begin-user-doc -->
......@@ -247,7 +257,7 @@ public interface SppPackage extends EPackage {
* @generated
* @ordered
*/
int PROGRAM_OPERATION_COUNT = 0;
int PROGRAM_OPERATION_COUNT = 1;
/**
* The meta object id for the '{@link tdt4250.spp.impl.SemesterImpl <em>Semester</em>}' class.
......@@ -304,6 +314,15 @@ public interface SppPackage extends EPackage {
*/
int SEMESTER_FEATURE_COUNT = 4;
/**
* The operation id for the '<em>Get Credits</em>' operation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int SEMESTER___GET_CREDITS = 0;
/**
* The number of operations of the '<em>Semester</em>' class.
* <!-- begin-user-doc -->
......@@ -311,7 +330,7 @@ public interface SppPackage extends EPackage {
* @generated
* @ordered
*/
int SEMESTER_OPERATION_COUNT = 0;
int SEMESTER_OPERATION_COUNT = 1;
/**
* The meta object id for the '{@link tdt4250.spp.impl.CourseImpl <em>Course</em>}' class.
......@@ -726,6 +745,16 @@ public interface SppPackage extends EPackage {
*/
EReference getProgram_ElectiveCourses();
/**
* Returns the meta object for the '{@link tdt4250.spp.Program#getCredits() <em>Get Credits</em>}' operation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for the '<em>Get Credits</em>' operation.
* @see tdt4250.spp.Program#getCredits()
* @generated
*/
EOperation getProgram__GetCredits();
/**
* Returns the meta object for class '{@link tdt4250.spp.Semester <em>Semester</em>}'.
* <!-- begin-user-doc -->
......@@ -780,6 +809,16 @@ public interface SppPackage extends EPackage {
*/
EReference getSemester_SelectedCourses();
/**
* Returns the meta object for the '{@link tdt4250.spp.Semester#getCredits() <em>Get Credits</em>}' operation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for the '<em>Get Credits</em>' operation.
* @see tdt4250.spp.Semester#getCredits()
* @generated
*/
EOperation getSemester__GetCredits();
/**
* Returns the meta object for class '{@link tdt4250.spp.Course <em>Course</em>}'.
* <!-- begin-user-doc -->
......@@ -1131,6 +1170,14 @@ public interface SppPackage extends EPackage {
*/
EReference PROGRAM__ELECTIVE_COURSES = eINSTANCE.getProgram_ElectiveCourses();
/**
* The meta object literal for the '<em><b>Get Credits</b></em>' operation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
EOperation PROGRAM___GET_CREDITS = eINSTANCE.getProgram__GetCredits();
/**
* The meta object literal for the '{@link tdt4250.spp.impl.SemesterImpl <em>Semester</em>}' class.
* <!-- begin-user-doc -->
......@@ -1173,6 +1220,14 @@ public interface SppPackage extends EPackage {
*/
EReference SEMESTER__SELECTED_COURSES = eINSTANCE.getSemester_SelectedCourses();
/**
* The meta object literal for the '<em><b>Get Credits</b></em>' operation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
EOperation SEMESTER___GET_CREDITS = eINSTANCE.getSemester__GetCredits();
/**
* The meta object literal for the '{@link tdt4250.spp.impl.CourseImpl <em>Course</em>}' class.
* <!-- begin-user-doc -->
......
......@@ -2,6 +2,7 @@
*/
package tdt4250.spp.impl;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import org.eclipse.emf.common.notify.Notification;
......@@ -274,6 +275,21 @@ public class ProgramImpl extends MinimalEObjectImpl.Container implements Program
return electiveCourses;
}
/**
* <!-- begin-user-doc -->
* Get credits for all semesters
* <!-- end-user-doc -->
* @generated NOPE
*/
@Override
public float getCredits() {
float result = 0.0f;
for (Semester sem : this.getSemesters()) {
result += sem.getCredits();
}
return result;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......@@ -429,6 +445,20 @@ public class ProgramImpl extends MinimalEObjectImpl.Container implements Program
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException {
switch (operationID) {
case SppPackage.PROGRAM___GET_CREDITS:
return getCredits();
}
return super.eInvoke(operationID, arguments);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......
......@@ -2,6 +2,7 @@
*/
package tdt4250.spp.impl;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import org.eclipse.emf.common.notify.Notification;
......@@ -212,6 +213,21 @@ public class SemesterImpl extends MinimalEObjectImpl.Container implements Semest
return selectedCourses;
}
/**
* <!-- begin-user-doc -->
* Return the total amount of credits that are gained from the courses
* <!-- end-user-doc -->
* @generated NOPE
*/
@Override
public float getCredits() {
float result = 0.0f;
for (Course course : this.getSelectedCourses()) {
result += course.getCredits();
}
return result;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......@@ -346,6 +362,20 @@ public class SemesterImpl extends MinimalEObjectImpl.Container implements Semest
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException {
switch (operationID) {
case SppPackage.SEMESTER___GET_CREDITS:
return getCredits();
}
return super.eInvoke(operationID, arguments);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......
......@@ -5,6 +5,7 @@ package tdt4250.spp.impl;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
......@@ -331,6 +332,16 @@ public class SppPackageImpl extends EPackageImpl implements SppPackage {
return (EReference)programEClass.getEStructuralFeatures().get(5);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public EOperation getProgram__GetCredits() {
return programEClass.getEOperations().get(0);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......@@ -381,6 +392,16 @@ public class SppPackageImpl extends EPackageImpl implements SppPackage {
return (EReference)semesterEClass.getEStructuralFeatures().get(3);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public EOperation getSemester__GetCredits() {
return semesterEClass.getEOperations().get(0);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......@@ -617,12 +638,14 @@ public class SppPackageImpl extends EPackageImpl implements SppPackage {
createEReference(programEClass, PROGRAM__SPECIALISATION);
createEReference(programEClass, PROGRAM__MANDATORY_COURSES);
createEReference(programEClass, PROGRAM__ELECTIVE_COURSES);
createEOperation(programEClass, PROGRAM___GET_CREDITS);
semesterEClass = createEClass(SEMESTER);
createEAttribute(semesterEClass, SEMESTER__SEASON);
createEAttribute(semesterEClass, SEMESTER__YEAR);
createEReference(semesterEClass, SEMESTER__PROGRAM);
createEReference(semesterEClass, SEMESTER__SELECTED_COURSES);
createEOperation(semesterEClass, SEMESTER___GET_CREDITS);
courseEClass = createEClass(COURSE);
createEAttribute(courseEClass, COURSE__CODE);
......@@ -698,12 +721,16 @@ public class SppPackageImpl extends EPackageImpl implements SppPackage {
initEReference(getProgram_MandatoryCourses(), this.getMandatoryCourses(), this.getMandatoryCourses_Program(), "mandatoryCourses", null, 0, -1, Program.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getProgram_ElectiveCourses(), this.getElectiveCourses(), this.getElectiveCourses_Program(), "electiveCourses", null, 0, -1, Program.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEOperation(getProgram__GetCredits(), ecorePackage.getEFloat(), "getCredits", 0, 1, IS_UNIQUE, IS_ORDERED);
initEClass(semesterEClass, Semester.class, "Semester", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEAttribute(getSemester_Season(), this.getSeasonType(), "season", null, 0, 1, Semester.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getSemester_Year(), ecorePackage.getEIntegerObject(), "year", "1", 0, 1, Semester.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getSemester_Program(), this.getProgram(), this.getProgram_Semesters(), "program", null, 0, 1, Semester.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getSemester_SelectedCourses(), this.getCourse(), null, "selectedCourses", null, 0, -1, Semester.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEOperation(getSemester__GetCredits(), ecorePackage.getEFloat(), "getCredits", 0, 1, IS_UNIQUE, IS_ORDERED);
initEClass(courseEClass, Course.class, "Course", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEAttribute(getCourse_Code(), ecorePackage.getEString(), "code", null, 0, 1, Course.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getCourse_Name(), ecorePackage.getEString(), "name", null, 0, 1, Course.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
......@@ -761,7 +788,13 @@ public class SppPackageImpl extends EPackageImpl implements SppPackage {
(programEClass,
source,
new String[] {
"constraints", "needsEnoughSemesters semestersNeedToBeUniqueByYearAndSeason"
"constraints", "needsEnoughSemesters"
});
addAnnotation
(semesterEClass,
source,
new String[] {
"constraints", "needsEnoughCredits"
});
}
......
......@@ -5,6 +5,7 @@ package tdt4250.spp.util;
import java.util.Map;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.DiagnosticChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.ecore.EPackage;
......@@ -145,7 +146,6 @@ public class SppValidator extends EObjectValidator {
if (result || diagnostics != null) result &= validate_EveryKeyUnique(program, diagnostics, context);
if (result || diagnostics != null) result &= validate_EveryMapEntryUnique(program, diagnostics, context);
if (result || diagnostics != null) result &= validateProgram_needsEnoughSemesters(program, diagnostics, context);
if (result || diagnostics != null) result &= validateProgram_semestersNeedToBeUniqueByYearAndSeason(program, diagnostics, context);
return result;
}
......@@ -158,11 +158,12 @@ public class SppValidator extends EObjectValidator {
*/
public boolean validateProgram_needsEnoughSemesters(Program program, DiagnosticChain diagnostics, Map<Object, Object> context) {
int numberOfSemesters = 0;
for (Semester sem : program.getSemesters()) {
EList<Semester> semesters = program.getSemesters();
for (int i = 0; i < semesters.size(); i++) {
numberOfSemesters += 1;
}
if (numberOfSemesters != program.getDuration().getValue() * 2) {
if (numberOfSemesters < program.getDuration().getValue() * 2) {
if (diagnostics != null) {
diagnostics.add
(createDiagnostic
......@@ -180,17 +181,33 @@ public class SppValidator extends EObjectValidator {
}
/**
* Validates the semestersNeedToBeUniqueByYearAndSeason constraint of '<em>Program</em>'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean validateProgram_semestersNeedToBeUniqueByYearAndSeason(Program program, DiagnosticChain diagnostics, Map<Object, Object> context) {
// TODO implement the constraint
// -> specify the condition that violates the constraint
// -> verify the diagnostic details, including severity, code, and message
// Ensure that you remove @generated or mark it @generated NOT
if (false) {
public boolean validateSemester(Semester semester, DiagnosticChain diagnostics, Map<Object, Object> context) {
if (!validate_NoCircularContainment(semester, diagnostics, context)) return false;
boolean result = validate_EveryMultiplicityConforms(semester, diagnostics, context);
if (result || diagnostics != null) result &= validate_EveryDataValueConforms(semester, diagnostics, context);
if (result || diagnostics != null) result &= validate_EveryReferenceIsContained(semester, diagnostics, context);
if (result || diagnostics != null) result &= validate_EveryBidirectionalReferenceIsPaired(semester, diagnostics, context);
if (result || diagnostics != null) result &= validate_EveryProxyResolves(semester, diagnostics, context);
if (result || diagnostics != null) result &= validate_UniqueID(semester, diagnostics, context);
if (result || diagnostics != null) result &= validate_EveryKeyUnique(semester, diagnostics, context);
if (result || diagnostics != null) result &= validate_EveryMapEntryUnique(semester, diagnostics, context);
if (result || diagnostics != null) result &= validateSemester_needsEnoughCredits(semester, diagnostics, context);
return result;
}
/**
* Validates the needsEnoughCredits constraint of '<em>Semester</em>'.
* <!-- begin-user-doc -->
* To be able to have a valid semester the semester should at least have 30 credits.
* <!-- end-user-doc -->
* @generated NOPE
*/
public boolean validateSemester_needsEnoughCredits(Semester semester, DiagnosticChain diagnostics, Map<Object, Object> context) {
if (semester.getCredits() < 30.0f) {
if (diagnostics != null) {
diagnostics.add
(createDiagnostic
......@@ -198,8 +215,8 @@ public class SppValidator extends EObjectValidator {
DIAGNOSTIC_SOURCE,
0,
"_UI_GenericConstraint_diagnostic",
new Object[] { "semestersNeedToBeUniqueByYearAndSeason", getObjectLabel(program, context) },
new Object[] { program },
new Object[] { "needsEnoughCredits", getObjectLabel(semester, context) },
new Object[] { semester },
context));
}
return false;
......@@ -207,15 +224,6 @@ public class SppValidator extends EObjectValidator {
return true;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean validateSemester(Semester semester, DiagnosticChain diagnostics, Map<Object, Object> context) {
return validate_EveryDefaultConstraint(semester, diagnostics, context);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment