diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredHubRequest.java b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredHubRequest.java index 603d3c4..eb635d8 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredHubRequest.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredHubRequest.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Objects; /** * Fields common to all types of CredHub requests. @@ -135,18 +136,14 @@ public class CredHubRequest { if (additionalPermissions != null ? additionalPermissions.equals(that.additionalPermissions) : that.additionalPermissions == null) return false; if (details != null ? !details.equals(that.details) : that.details != null) return false; + if (mode != null ? !mode.equals(that.mode) : that.mode != null) return false; return true; } @Override public int hashCode() { - int result = (overwrite ? 1 : 0); - result = 31 * result + (name != null ? name.hashCode() : 0); - result = 31 * result + (credentialType != null ? credentialType.hashCode() : 0); - result = 31 * result + (additionalPermissions != null ? additionalPermissions.hashCode() : 0); - result = 31 * result + (details != null ? details.hashCode() : 0); - return result; + return Objects.hash(overwrite, name, credentialType, additionalPermissions, details, mode); } /** diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialDetails.java b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialDetails.java index 49c8f94..d2c3a94 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialDetails.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialDetails.java @@ -19,6 +19,8 @@ package org.springframework.credhub.support; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import java.util.Objects; + /** * The details of a credential that has been written to CredHub. Clients don't * typically instantiate objects of this type, but will receive them in response @@ -28,18 +30,21 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; * @author Scott Frederick */ public class CredentialDetails extends CredentialSummary { - private String id; + private final String id; @JsonProperty("type") - private CredentialType credentialType; + private final CredentialType credentialType; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type") - private T value; + private final T value; /** * Create a {@link CredentialDetails}. */ public CredentialDetails() { + this.id = null; + this.credentialType = null; + this.value = null; } /** @@ -107,13 +112,7 @@ public class CredentialDetails extends CredentialSummary { @Override public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (name != null ? name.hashCode() : 0); - result = 31 * result + (credentialType != null ? credentialType.hashCode() : 0); - result = 31 * result + (value != null ? value.hashCode() : 0); - result = 31 * result - + (versionCreatedAt != null ? versionCreatedAt.hashCode() : 0); - return result; + return Objects.hash(id, name, credentialType, value, versionCreatedAt); } @Override diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialDetailsData.java b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialDetailsData.java index 6f3ba6d..962d605 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialDetailsData.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialDetailsData.java @@ -20,6 +20,7 @@ package org.springframework.credhub.support; import java.util.Arrays; import java.util.List; +import java.util.Objects; /** * A collection of {@link CredentialDetails}. Clients don't typically instantiate @@ -29,12 +30,13 @@ import java.util.List; * @author Scott Frederick */ public class CredentialDetailsData { - private List> data; + private final List> data; /** * Create a {@link CredentialDetailsData}. */ public CredentialDetailsData() { + this.data = null; } /** @@ -74,9 +76,7 @@ public class CredentialDetailsData { @Override public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (data != null ? data.hashCode() : 0); - return result; + return Objects.hashCode(data); } @Override diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialName.java b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialName.java index dbe148c..3abdf87 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialName.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialName.java @@ -17,6 +17,7 @@ package org.springframework.credhub.support; import java.util.Arrays; +import java.util.Objects; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; @@ -32,7 +33,7 @@ import org.springframework.util.StringUtils; */ public class CredentialName { @JsonIgnore - protected final String[] segments; + final String[] segments; /** * Create a name from the provided value. The name must consist of segments @@ -93,6 +94,6 @@ public class CredentialName { @Override public int hashCode() { - return Arrays.hashCode(segments); + return Objects.hashCode(segments); } } diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialPath.java b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialPath.java index 68aa5bc..41ea4b5 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialPath.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialPath.java @@ -16,6 +16,8 @@ package org.springframework.credhub.support; +import java.util.Objects; + /** * The path to a credential that has been written to CredHub. Clients don't typically * instantiate objects of this type, but will receive them in response to requests. @@ -23,12 +25,14 @@ package org.springframework.credhub.support; * @author Scott Frederick */ public class CredentialPath { - protected String path; + private final String path; /** * Create a {@link CredentialPath}. Intended for internal use. */ - CredentialPath() { + @SuppressWarnings("unused") + private CredentialPath() { + this.path = null; } /** @@ -65,7 +69,7 @@ public class CredentialPath { @Override public int hashCode() { - return path != null ? path.hashCode() : 0; + return Objects.hashCode(path); } @Override diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialPathData.java b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialPathData.java index 18e1b15..80fc3b8 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialPathData.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialPathData.java @@ -18,6 +18,7 @@ package org.springframework.credhub.support; import java.util.Arrays; import java.util.List; +import java.util.Objects; /** * A collection of {@link CredentialPath}s. Clients don't typically instantiate @@ -26,12 +27,14 @@ import java.util.List; * @author Scott Frederick */ public class CredentialPathData { - private List paths; + private final List paths; /** * Create a {@link CredentialPathData}. */ - CredentialPathData() { + @SuppressWarnings("unused") + private CredentialPathData() { + this.paths = null; } /** @@ -71,9 +74,7 @@ public class CredentialPathData { @Override public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (paths != null ? paths.hashCode() : 0); - return result; + return Objects.hashCode(paths); } @Override diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialPermissions.java b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialPermissions.java index ea550df..3337cc3 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialPermissions.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialPermissions.java @@ -22,6 +22,7 @@ import org.springframework.credhub.support.permissions.CredentialPermission; import java.util.Arrays; import java.util.List; +import java.util.Objects; /** * A collection of {@link CredentialPermission}s. Clients don't typically instantiate @@ -31,13 +32,16 @@ import java.util.List; * @author Scott Frederick */ public class CredentialPermissions { - private CredentialName credentialName; - private List permissions; + private final CredentialName credentialName; + private final List permissions; /** * Create a {@link CredentialPermissions}. */ - public CredentialPermissions() { + @SuppressWarnings("unused") + private CredentialPermissions() { + this.credentialName = null; + this.permissions = null; } /** @@ -93,8 +97,6 @@ public class CredentialPermissions { @Override public int hashCode() { - int result = credentialName != null ? credentialName.hashCode() : 0; - result = 31 * result + (permissions != null ? permissions.hashCode() : 0); - return result; + return Objects.hash(credentialName, permissions); } } diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialSummary.java b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialSummary.java index f21e2d1..0fda702 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialSummary.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialSummary.java @@ -17,6 +17,7 @@ package org.springframework.credhub.support; import java.util.Date; +import java.util.Objects; /** * A summary of a credential that has been written to CredHub. Clients don't typically @@ -26,13 +27,15 @@ import java.util.Date; * @author Scott Frederick */ public class CredentialSummary { - protected CredentialName name; - protected Date versionCreatedAt; + protected final CredentialName name; + protected final Date versionCreatedAt; /** * Create a {@link CredentialSummary}. Intended for internal use. */ CredentialSummary() { + this.name = null; + this.versionCreatedAt = null; } /** @@ -82,10 +85,7 @@ public class CredentialSummary { @Override public int hashCode() { - int result = name != null ? name.hashCode() : 0; - result = 31 * result - + (versionCreatedAt != null ? versionCreatedAt.hashCode() : 0); - return result; + return Objects.hash(name, versionCreatedAt); } @Override diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialSummaryData.java b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialSummaryData.java index 6bcbee4..d4f03da 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialSummaryData.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/support/CredentialSummaryData.java @@ -18,6 +18,7 @@ package org.springframework.credhub.support; import java.util.Arrays; import java.util.List; +import java.util.Objects; /** * A collection of {@link CredentialSummary}s. Clients don't typically instantiate @@ -27,12 +28,14 @@ import java.util.List; * @author Scott Frederick */ public class CredentialSummaryData { - private List credentials; + private final List credentials; /** * Create a {@link CredentialSummaryData}. */ - CredentialSummaryData() { + @SuppressWarnings("unused") + private CredentialSummaryData() { + this.credentials = null; } /** @@ -72,9 +75,7 @@ public class CredentialSummaryData { @Override public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (credentials != null ? credentials.hashCode() : 0); - return result; + return Objects.hashCode(credentials); } @Override diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/support/StringCredential.java b/spring-credhub-core/src/main/java/org/springframework/credhub/support/StringCredential.java index a770199..5c9691d 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/support/StringCredential.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/support/StringCredential.java @@ -18,6 +18,8 @@ package org.springframework.credhub.support; import org.springframework.util.Assert; +import java.util.Objects; + /** * A base type for a credential that contains a single string value. * @@ -50,7 +52,7 @@ public class StringCredential { @Override public int hashCode() { - return value != null ? value.hashCode() : 0; + return Objects.hashCode(value); } @Override diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Actor.java b/spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Actor.java index a119300..624d47b 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Actor.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Actor.java @@ -22,6 +22,8 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; import org.springframework.util.Assert; +import java.util.Objects; + import static org.springframework.credhub.support.permissions.ActorType.APP; import static org.springframework.credhub.support.permissions.ActorType.OAUTH_CLIENT; import static org.springframework.credhub.support.permissions.ActorType.USER; @@ -32,8 +34,8 @@ import static org.springframework.credhub.support.permissions.ActorType.USER; * @author Scott Frederick */ public class Actor { - private ActorType authType; - private String primaryIdentifier; + private final ActorType authType; + private final String primaryIdentifier; /** * Create a new {@literal Actor}. @@ -168,8 +170,6 @@ public class Actor { @Override public int hashCode() { - int result = authType.hashCode(); - result = 31 * result + primaryIdentifier.hashCode(); - return result; + return Objects.hash(authType, primaryIdentifier); } } diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/CredentialPermission.java b/spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/CredentialPermission.java index a678136..a5aa935 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/CredentialPermission.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/CredentialPermission.java @@ -26,6 +26,7 @@ import org.springframework.util.Assert; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; /** * Permissions applied to a credential in CredHub. If provided when a @@ -38,14 +39,15 @@ import java.util.List; * @author Scott Frederick */ public class CredentialPermission { - private Actor actor; + private final Actor actor; @JsonProperty - private List operations; + private final List operations; /** * Create a {@literal CredentialPermission}. */ + @SuppressWarnings("unused") private CredentialPermission() { this.actor = null; this.operations = null; @@ -129,9 +131,7 @@ public class CredentialPermission { @Override public int hashCode() { - int result = actor != null ? actor.hashCode() : 0; - result = 31 * result + (operations != null ? operations.hashCode() : 0); - return result; + return Objects.hash(actor, operations); } @Override