-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Development
: Replace if-else chains with pattern matching
#9303
Changes from all commits
8640ab2
4c01129
bae5a6e
ce46af4
16699ee
93b4a24
3350eb4
733d571
04c639e
53b5194
4bd1e24
67ae585
e4c93e6
8b028f6
93cf232
13dbf4f
b5997ff
11f9bac
886f8b5
b496140
aec2a5c
165ba41
4a139b7
ff47d77
3b48009
91c323d
e832686
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -156,18 +156,14 @@ public void setComplaintResponse(ComplaintResponse complaintResponse) { | |||||
* @param participant either a team or user | ||||||
*/ | ||||||
public void setParticipant(Participant participant) { | ||||||
if (participant instanceof User) { | ||||||
this.student = (User) participant; | ||||||
} | ||||||
else if (participant instanceof Team) { | ||||||
this.team = (Team) participant; | ||||||
} | ||||||
else if (participant == null) { | ||||||
this.student = null; | ||||||
this.team = null; | ||||||
} | ||||||
else { | ||||||
throw new Error("Unknown participant type"); | ||||||
switch (participant) { | ||||||
case User user -> this.student = user; | ||||||
case Team team1 -> this.team = team1; | ||||||
case null -> { | ||||||
this.student = null; | ||||||
this.team = null; | ||||||
} | ||||||
default -> throw new Error("Unknown participant type"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Throw an appropriate exception instead of 'Error' in the default case Throwing an Apply this diff to fix the issue: default -> throw new Error("Unknown participant type");
+ default -> throw new IllegalArgumentException("Unknown participant type"); 📝 Committable suggestion
Suggested change
|
||||||
} | ||||||
} | ||||||
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use consistent variable naming in switch-case patterns
In the switch statement, the variable
team1
is used incase Team team1 -> this.team = team1;
. For consistency and clarity, consider renamingteam1
toteam
, aligning it with the field namethis.team
and improving readability.Apply this diff to rename the variable:
📝 Committable suggestion