Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
web-page-modelling
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Uy Tuan Huynh
web-page-modelling
Commits
1dbc65da
Commit
1dbc65da
authored
6 years ago
by
uyth
Browse files
Options
Downloads
Patches
Plain Diff
Updated validation for checking hours for programs
parent
2732ee12
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src-gen/tdt4250_assignment/util/Tdt4250_assignmentValidator.java
+66
-11
66 additions, 11 deletions
.../tdt4250_assignment/util/Tdt4250_assignmentValidator.java
with
66 additions
and
11 deletions
src-gen/tdt4250_assignment/util/Tdt4250_assignmentValidator.java
+
66
−
11
View file @
1dbc65da
...
@@ -2,6 +2,11 @@
...
@@ -2,6 +2,11 @@
*/
*/
package
tdt4250_assignment.util
;
package
tdt4250_assignment.util
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
org.eclipse.emf.common.util.Diagnostic
;
import
org.eclipse.emf.common.util.Diagnostic
;
...
@@ -216,24 +221,74 @@ public class Tdt4250_assignmentValidator extends EObjectValidator {
...
@@ -216,24 +221,74 @@ public class Tdt4250_assignmentValidator extends EObjectValidator {
* Validates the validateHours constraint of '<em>Course Instance</em>'.
* Validates the validateHours constraint of '<em>Course Instance</em>'.
* <!-- begin-user-doc -->
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* <!-- end-user-doc -->
* @generated
* @generated
NOT
*/
*/
public
boolean
validateCourseInstance_validateHours
(
CourseInstance
courseInstance
,
DiagnosticChain
diagnostics
,
public
boolean
validateCourseInstance_validateHours
(
CourseInstance
instance
,
DiagnosticChain
diagnostics
,
Map
<
Object
,
Object
>
context
)
{
Map
<
Object
,
Object
>
context
)
{
// TODO implement the constraint
// -> specify the condition that violates the constraint
// set required hours for schedule types
// -> verify the diagnostic details, including severity, code, and message
int
requiredLab
=
instance
.
getLabHours
();
// Ensure that you remove @generated or mark it @generated NOT
int
requiredLecture
=
instance
.
getLectureHours
();
if
(
false
)
{
Collection
<
StudyProgramCode
>
studyProgramCodes
=
instance
.
getStudyPrograms
();
// initialize map to counters
Map
<
StudyProgramCode
,
Map
<
ScheduleSlotType
,
Integer
>>
programToCounterMap
;
programToCounterMap
=
new
HashMap
<>();
for
(
StudyProgramCode
program
:
studyProgramCodes
)
{
programToCounterMap
.
put
(
program
,
new
HashMap
<>());
programToCounterMap
.
get
(
program
).
put
(
ScheduleSlotType
.
LAB
,
0
);
programToCounterMap
.
get
(
program
).
put
(
ScheduleSlotType
.
LECTURE
,
0
);
}
TimeTable
timeTable
=
instance
.
getTimeTable
();
// add hours to counters
for
(
ScheduleSlot
slot
:
timeTable
.
getSchedule
())
{
int
hours
=
slot
.
getTo
()
-
slot
.
getFrom
();
for
(
StudyProgramCode
studyProgram
:
slot
.
getStudyPrograms
())
{
if
(
studyProgramCodes
.
contains
(
studyProgram
))
{
ScheduleSlotType
type
=
slot
.
getType
();
Map
<
ScheduleSlotType
,
Integer
>
counter
=
programToCounterMap
.
get
(
studyProgram
);
int
hoursForProgram
=
counter
.
get
(
type
);
counter
.
put
(
type
,
hoursForProgram
+
hours
);
programToCounterMap
.
put
(
studyProgram
,
counter
);
}
}
}
// validate hours
List
<
StudyProgramCode
>
invalidPrograms
;
invalidPrograms
=
new
ArrayList
<
StudyProgramCode
>();
for
(
StudyProgramCode
program
:
programToCounterMap
.
keySet
())
{
int
actualLab
=
programToCounterMap
.
get
(
program
).
get
(
ScheduleSlotType
.
LECTURE
);
int
actualLecture
=
programToCounterMap
.
get
(
program
).
get
(
ScheduleSlotType
.
EXERCISE
);
if
(
actualLab
<
requiredLab
||
actualLecture
<
requiredLecture
)
{
invalidPrograms
.
add
(
program
);
}
}
if
(!
invalidPrograms
.
isEmpty
())
{
if
(
diagnostics
!=
null
)
{
if
(
diagnostics
!=
null
)
{
diagnostics
.
add
(
for
(
StudyProgramCode
studyProgram
:
invalidPrograms
)
{
createDiagnostic
(
Diagnostic
.
ERROR
,
DIAGNOSTIC_SOURCE
,
0
,
"_UI_GenericConstraint_diagnostic"
,
diagnostics
.
add
(
createDiagnostic
(
new
Object
[]
{
"validateHours"
,
getObjectLabel
(
courseInstance
,
context
)
},
Diagnostic
.
ERROR
,
DIAGNOSTIC_SOURCE
,
0
,
new
Object
[]
{
courseInstance
},
context
));
"Too few hours per week for "
+
studyProgram
+
"."
,
new
Object
[]
{
"validateHours"
,
getObjectLabel
(
instance
,
context
)
},
new
Object
[]
{
instance
},
context
));
}
}
}
return
false
;
return
false
;
}
}
return
true
;
return
true
;
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment