Refactor equals method

Using the accessor method for fields instead of directly access
This commit is contained in:
Seongguk Jeong 2023-07-18 22:11:33 +09:00 committed by Josh Cummings
parent 8df8d4022e
commit bcd4dcc15c
4 changed files with 11 additions and 14 deletions

View File

@ -58,9 +58,8 @@ public final class JaasGrantedAuthority implements GrantedAuthority {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (obj instanceof JaasGrantedAuthority) { if (obj instanceof JaasGrantedAuthority jga) {
JaasGrantedAuthority jga = (JaasGrantedAuthority) obj; return this.role.equals(jga.getAuthority()) && this.principal.equals(jga.getPrincipal());
return this.role.equals(jga.role) && this.principal.equals(jga.principal);
} }
return false; return false;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -50,8 +50,8 @@ public final class SimpleGrantedAuthority implements GrantedAuthority {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (obj instanceof SimpleGrantedAuthority) { if (obj instanceof SimpleGrantedAuthority sga) {
return this.role.equals(((SimpleGrantedAuthority) obj).role); return this.role.equals(sga.getAuthority());
} }
return false; return false;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -113,14 +113,13 @@ public class LdapAuthority implements GrantedAuthority {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (!(obj instanceof LdapAuthority)) { if (!(obj instanceof LdapAuthority other)) {
return false; return false;
} }
LdapAuthority other = (LdapAuthority) obj; if (!this.dn.equals(other.getDn())) {
if (!this.dn.equals(other.dn)) {
return false; return false;
} }
return this.role.equals(other.role); return this.role.equals(other.getAuthority());
} }
@Override @Override

View File

@ -64,9 +64,8 @@ public final class SwitchUserGrantedAuthority implements GrantedAuthority {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (obj instanceof SwitchUserGrantedAuthority) { if (obj instanceof SwitchUserGrantedAuthority swa) {
SwitchUserGrantedAuthority swa = (SwitchUserGrantedAuthority) obj; return this.role.equals(swa.getAuthority()) && this.source.equals(swa.getSource());
return this.role.equals(swa.role) && this.source.equals(swa.source);
} }
return false; return false;
} }