SEC-222: Improve hashCode() to use XOR.

This commit is contained in:
Ben Alex 2006-04-26 01:18:42 +00:00
parent e39bd43541
commit 8cff715599
1 changed files with 6 additions and 6 deletions

View File

@ -145,28 +145,28 @@ public abstract class AbstractAuthenticationToken implements Authentication {
}
public int hashCode() {
int code = 2305;
int code = 31;
if (this.getAuthorities() != null) {
for (int i = 0; i < this.getAuthorities().length; i++) {
code = code * (this.getAuthorities()[i].hashCode() % 7);
code ^= this.getAuthorities()[i].hashCode();
}
}
if (this.getPrincipal() != null) {
code = code * (this.getPrincipal().hashCode() % 7);
code ^= this.getPrincipal().hashCode();
}
if (this.getCredentials() != null) {
code = code * (this.getCredentials().hashCode() % 7);
code ^= this.getCredentials().hashCode();
}
if (this.getDetails() != null) {
code = code * (this.getDetails().hashCode() % 7);
code ^= this.getDetails().hashCode();
}
if (this.isAuthenticated()) {
code = code * -3;
code ^= -37;
}
return code;