diff options
author | Ola Aunrønning <olaa@verizonmedia.com> | 2020-01-02 16:49:22 +0100 |
---|---|---|
committer | Ola Aunrønning <olaa@verizonmedia.com> | 2020-01-02 16:49:22 +0100 |
commit | d4f8597e4d159f41639721c201594bf811f5ec8a (patch) | |
tree | 9c68016487a073be064f8004225971d9e728e230 /controller-api | |
parent | bbfffa7f5bb5a2f6d8ac388b16aac7ab2796de8e (diff) |
Override hashCode and equals for ResourceAllocation/Snapshot
Diffstat (limited to 'controller-api')
2 files changed, 37 insertions, 0 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java index bea34567752..1643d836113 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java @@ -1,6 +1,8 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.resource; +import java.util.Objects; + /** * An allocation of node resources. * @@ -46,5 +48,23 @@ public class ResourceAllocation { return new ResourceAllocation(cpuCores * multiplicand, memoryGb * multiplicand, diskGb * multiplicand); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ResourceAllocation)) return false; + + ResourceAllocation other = (ResourceAllocation) o; + double epsilon = 0.001; + return Math.abs(this.cpuCores - other.cpuCores) < epsilon && + Math.abs(this.memoryGb - other.memoryGb) < epsilon && + Math.abs(this.diskGb - other.diskGb) < epsilon; + + } + + @Override + public int hashCode() { + return Objects.hash(cpuCores, memoryGb, diskGb); + } + } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java index cfe0f18260a..70aaf5de112 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java @@ -8,6 +8,7 @@ import com.yahoo.vespa.hosted.controller.api.integration.configserver.Node; import java.time.Instant; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @@ -70,4 +71,20 @@ public class ResourceSnapshot { return zoneId; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ResourceSnapshot)) return false; + + ResourceSnapshot other = (ResourceSnapshot) o; + return this.applicationId.equals(other.applicationId) && + this.resourceAllocation.equals(other.resourceAllocation) && + this.timestamp.equals(other.timestamp) && + this.zoneId.equals(other.zoneId); + } + + @Override + public int hashCode(){ + return Objects.hash(applicationId, resourceAllocation, timestamp, zoneId); + } } |