Skip to content

Commit

Permalink
Ensure upper case matric number input
Browse files Browse the repository at this point in the history
  • Loading branch information
yeekian committed Nov 11, 2024
1 parent 5c6870d commit 8de7ebe
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/tutorlink/lists/StudentList.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package tutorlink.lists;

import tutorlink.commons.Commons;
import tutorlink.exceptions.DuplicateMatricNumberException;
import tutorlink.exceptions.IllegalValueException;
import tutorlink.exceptions.StudentNotFoundException;
import tutorlink.exceptions.TutorLinkException;
import tutorlink.student.Student;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -65,6 +69,13 @@ public String toString() {

public StudentList findStudentByMatricNumber(String matricNumber) throws TutorLinkException {
StudentList filteredList = new StudentList();

Pattern pattern = Pattern.compile(Commons.MATRIC_NUMBER_REGEX);
Matcher matcher = pattern.matcher(matricNumber);
if (!matcher.find()) {
throw new IllegalValueException(Commons.ERROR_ILLEGAL_MATRIC_NUMBER);
}

filteredList.studentArrayList = studentArrayList
.stream()
.filter(student -> student.getMatricNumber().equals(matricNumber.toUpperCase()))
Expand Down

0 comments on commit 8de7ebe

Please sign in to comment.