mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8311170: Simplify and modernize equals and hashCode in security area
Reviewed-by: djelinski, rriggs, valeriep
This commit is contained in:
parent
e9f751ab16
commit
19ae62ae2c
96 changed files with 567 additions and 951 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -29,6 +29,7 @@ import java.io.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Objects;
|
||||
import java.util.Vector;
|
||||
import static java.util.Locale.ENGLISH;
|
||||
|
||||
|
@ -616,20 +617,17 @@ final class CryptoPolicyParser {
|
|||
* Calculates a hash code value for the object. Objects
|
||||
* which are equal will also have the same hashcode.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int retval = cryptoPermission.hashCode();
|
||||
if (alg != null) retval ^= alg.hashCode();
|
||||
if (exemptionMechanism != null) {
|
||||
retval ^= exemptionMechanism.hashCode();
|
||||
}
|
||||
retval ^= maxKeySize;
|
||||
if (checkParam) retval ^= 100;
|
||||
if (algParamSpec != null) {
|
||||
retval ^= algParamSpec.hashCode();
|
||||
}
|
||||
return retval;
|
||||
return cryptoPermission.hashCode()
|
||||
^ Objects.hashCode(alg)
|
||||
^ Objects.hashCode(exemptionMechanism)
|
||||
^ maxKeySize
|
||||
^ (checkParam ? 100 : 0)
|
||||
^ Objects.hashCode(algParamSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
@ -637,12 +635,8 @@ final class CryptoPolicyParser {
|
|||
if (!(obj instanceof CryptoPermissionEntry that))
|
||||
return false;
|
||||
|
||||
if (this.cryptoPermission == null) {
|
||||
if (that.cryptoPermission != null) return false;
|
||||
} else {
|
||||
if (!this.cryptoPermission.equals(
|
||||
that.cryptoPermission))
|
||||
return false;
|
||||
if (!Objects.equals(this.cryptoPermission, that.cryptoPermission)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.alg == null) {
|
||||
|
@ -652,15 +646,11 @@ final class CryptoPolicyParser {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!(this.maxKeySize == that.maxKeySize)) return false;
|
||||
if (this.maxKeySize != that.maxKeySize) return false;
|
||||
|
||||
if (this.checkParam != that.checkParam) return false;
|
||||
|
||||
if (this.algParamSpec == null) {
|
||||
return that.algParamSpec == null;
|
||||
} else {
|
||||
return this.algParamSpec.equals(that.algParamSpec);
|
||||
}
|
||||
return Objects.equals(this.algParamSpec, that.algParamSpec);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue