Storyboard StudyRightObjectModelNavigationAndQueries
Extend the class model:
Full class model from code:
How to navigate and query an object model.
Start: Example object structure:
Step 1: Simple set based navigation:
double assignmentPoints = university.getRooms().getAssignments().getPoints().sum(); double donePoints = university.getStudents().getDone().getPoints().sum();
Results in:
Sum of assignment points: 23.0. Sum of points of assignments that have been done by at least one students: 15.0.
Check: Assignment points: 23.0 actual 23.0
Check: donePoints: 15.0 actual 15.0
Step 2: Rooms with assignments not yet done by Karli:
AssignmentSet availableAssignments = university.getRooms().getAssignments().minus(karli.getDone()); RoomSet rooms = availableAssignments.getRoom();
Results in:
(senate math 17, gymnasium sports 25)
Check: rooms.size(): 2 actual 2
RoomSet rooms17 = university.getRooms().filterCredits(17); RoomSet roomsGE20 = university.getRooms().filterCredits(20, Integer.MAX_VALUE);
Results in:
rooms17: (senate math 17) roomsGE20: (gymnasium sports 25, 7422 Software Engineering 42)
Step 4: Filter for attribute greater than:
// Java 8: // (Room elem) -> elem.getCredits() > 20 RoomSet roomsEven = university.getRooms().filter(value -> value.getCredits() % 2 == 0);
Results in:
(7522 arts 16, The End exam 0, 7422 Software Engineering 42)
TeachingAssistantSet taStudents = university.getRooms().getStudents().instanceOfTeachingAssistant();
(Karli 4242 0 0 0)
Step 6: Write operations on sets:
university.getStudents().withMotivation(42);
Step 7: Rooms with two students that are friends (and need supervision):
RoomPO roomPO = university.getRooms().createRoomPO(); StudentPO stud1PO = roomPO.createStudentsPO(); roomPO.createStudentsPO().createMotivationCondition(42).createFriendsLink(stud1PO); rooms = roomPO.allMatches();
Results in:
(gymnasium sports 25)
Step 8: Rooms with two students with low motivation that are friends (and need supervision):
roomPO = university.getRooms().createRoomPO(); stud1PO = roomPO.createStudentsPO(); final StudentPO stud2PO = roomPO.createStudentsPO().createMotivationCondition(0, 50); stud2PO.createFriendsLink(stud1PO); rooms = roomPO.allMatches();
Results in:
(gymnasium sports 25)
Step 9: Rooms with two students without supervision that are friends and add teaching assistance:
UniversityPO uniPO = new UniversityPO(university); roomPO = uniPO.createRoomsPO(); stud1PO = roomPO.createStudentsPO().createMotivationCondition(0, 42); roomPO.createStudentsPO().createFriendsLink(stud1PO); roomPO.createTasLink(null); roomPO.createTasPO(CREATE); rooms = roomPO.allMatches();
Results in:
(gymnasium sports 25)
Step 10: TAs as students in a room:
roomPO = university.getRooms().createRoomPO(); stud1PO = roomPO.createStudentsPO(); TeachingAssistantPO taPO = stud1PO.instanceOf(new TeachingAssistantPO()); TeachingAssistantSet taSet = taPO.allMatches();
Step 11: Double motivation of all students:
roomPO = university.getRooms().createRoomPO(); stud1PO = roomPO.createStudentsPO(); for (Match match : (Iterable<Match>) roomPO.getPattern()) { Student currentMatch = stud1PO.getCurrentMatch(); currentMatch.withMotivation(currentMatch.getMotivation() * 2); // or more simple: stud1PO.withMotivation(stud1PO.getMotivation() * 2); Room assertMatch = roomPO.getCurrentMatch(); if (match.number == 1) { Assert.assertEquals("Karli", currentMatch.getName()); Assert.assertEquals("senate", assertMatch.getName()); Assert.assertEquals("math", assertMatch.getTopic()); Assert.assertEquals(17, assertMatch.getCredits()); } else if (match.number == 2) { Assert.assertEquals("Abu", currentMatch.getName()); Assert.assertEquals("gymnasium", assertMatch.getName()); Assert.assertEquals("sports", assertMatch.getTopic()); Assert.assertEquals(25, assertMatch.getCredits()); } else if (match.number == 3) { Assert.assertEquals("Alice", currentMatch.getName()); Assert.assertEquals("gymnasium", assertMatch.getName()); Assert.assertEquals("sports", assertMatch.getTopic()); Assert.assertEquals(25, assertMatch.getCredits()); } // System.out.println("match " + match.number + ": " + currentMatch + " // in room " + roomPO.getCurrentMatch()); }
Step 12: lure students from other rooms into math room:
roomPO = new RoomPO(mathRoom); stud1PO = roomPO.createPath(r -> ((Room) r).getDoors().getStudents(), new StudentPO()); stud1PO.startCreate(); stud1PO.createInLink(roomPO); stud1PO.allMatches();
Check: New students in math room: 3 actual 3