Skip to content

Commit

Permalink
perf: Add exception handling to increase robust code
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Marjoni committed Mar 2, 2026
1 parent 0db6023 commit 7c90b5b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/main/java/edu/group5/app/model/user/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,25 @@ public Customer(int userId,
String email,
String passwordHash) {

super(userId, "Customer", firstName, lastName, email, passwordHash);
this.preferences = new ArrayList<>();
super(userId, "Customer", firstName, lastName, email, passwordHash);
this.preferences = new ArrayList<>();
}

public List<Integer> getPreferences() {
return preferences;
}
public List<Integer> getPreferences() {
return preferences;
}

public void addPreference(int orgNumber) {
preferences.add(orgNumber);
public void addPreference(int orgNumber) {
if (!preferences.contains(orgNumber)) {
throw new IllegalArgumentException("Organization number already in preferences");
}
preferences.add(orgNumber);
}

public void removePreference(int orgNumber) {
preferences.remove(Integer.valueOf(orgNumber));
public void removePreference(int orgNumber) {
if (!preferences.contains(orgNumber)) {
throw new IllegalArgumentException("Organization number not found in preferences");
}
preferences.remove(Integer.valueOf(orgNumber));
}
}

0 comments on commit 7c90b5b

Please sign in to comment.