From 03d753e810556efff4b49770f92ffc4c56d4e332 Mon Sep 17 00:00:00 2001
From: Ada Turgut <a.turgut@student.tudelft.nl>
Date: Mon, 20 Nov 2023 14:25:11 +0100
Subject: [PATCH] Add better return types

---
 .../submit/service/StudentGroupService.java   | 26 +++++++++----------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/src/main/java/nl/tudelft/submit/service/StudentGroupService.java b/src/main/java/nl/tudelft/submit/service/StudentGroupService.java
index 07251a72..e9aba80f 100644
--- a/src/main/java/nl/tudelft/submit/service/StudentGroupService.java
+++ b/src/main/java/nl/tudelft/submit/service/StudentGroupService.java
@@ -275,17 +275,16 @@ public class StudentGroupService {
 	 * Checks if a person is already in a group in a given module. Throws GroupSwitchingException if there is
 	 * at least one person that is already in a group
 	 *
-	 * @param  personId the id of the person
-	 * @param  moduleId the id of the module
-	 * @return          false if there are no other groups the people are in
+	 * @param personId the id of the person
+	 * @param moduleId the id of the module
 	 */
-	private Boolean checkIfPersonIsAlreadyInAGroup(Long personId, Long moduleId, String message)
+	private void checkIfPersonIsAlreadyInAGroup(Long personId, Long moduleId, String message)
 			throws GroupSwitchingException {
 		Optional<StudentGroupDetailsDTO> currentGroup = getGroupForPersonInModule(personId, moduleId);
 
 		// person is not in any other groups in the module
 		if (currentGroup.isEmpty()) {
-			return false;
+			return;
 		}
 
 		String personName = personCache.get(personId).orElseThrow().getDisplayName();
@@ -297,16 +296,15 @@ public class StudentGroupService {
 	/**
 	 * Checks if at least one person in the given list is already a part of a group in the module
 	 *
-	 * @param  usernames list of usernames to be checked
-	 * @param  moduleId  the id of the module
-	 * @return           whether if there is a person that is already in a group in the same module
+	 * @param usernames list of usernames to be checked
+	 * @param moduleId  the id of the module
+	 *
 	 */
-	private Boolean arePeopleAlreadyInAGroup(Long moduleId, List<String> usernames, String message) {
-		return usernames
-				.stream()
-				.map(name -> personCache.get(name).getId())
-				.map(id -> checkIfPersonIsAlreadyInAGroup(id, moduleId, message))
-				.reduce(false, (x, y) -> x || y);
+	private void arePeopleAlreadyInAGroup(Long moduleId, List<String> usernames, String message) {
+		for (String name : usernames) {
+			Long id = personCache.get(name).getId();
+			checkIfPersonIsAlreadyInAGroup(id, moduleId, message);
+		}
 	}
 
 	/**
-- 
GitLab