Skip to content

Commit

Permalink
Optimized equals() implementation of KeyStroke and Mode classes
Browse files Browse the repository at this point in the history
  • Loading branch information
bwRavencl committed Nov 9, 2023
1 parent 15faeb6 commit a81fead
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
11 changes: 3 additions & 8 deletions src/main/java/de/bwravencl/controllerbuddy/input/KeyStroke.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,9 @@ public Object clone() throws CloneNotSupportedException {

@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final var other = (KeyStroke) obj;
return Arrays.equals(keyCodes, other.keyCodes) && Arrays.equals(modifierCodes, other.modifierCodes);
return obj instanceof final KeyStroke keyStroke
&& Arrays.equals(keyCodes, keyStroke.keyCodes)
&& Arrays.equals(modifierCodes, keyStroke.modifierCodes);
}

public ScanCode[] getKeyCodes() {
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/de/bwravencl/controllerbuddy/input/Mode.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,7 @@ public Object clone() throws CloneNotSupportedException {

@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final var other = (Mode) obj;

return Objects.equals(uuid, other.uuid);
return obj instanceof final Mode mode && Objects.equals(uuid, mode.uuid);
}

public Set<IAction<?>> getAllActions() {
Expand Down

0 comments on commit a81fead

Please sign in to comment.