diff options
author | Håkon Hallingstad <hakon@verizonmedia.com> | 2020-11-27 08:16:36 +0100 |
---|---|---|
committer | Håkon Hallingstad <hakon@verizonmedia.com> | 2020-11-27 08:16:36 +0100 |
commit | abe161b509cde53da37d87faa44981a5208e7b00 (patch) | |
tree | abc1b596e714eaaab332e7f8fd79fddd1ede6c8a /flags | |
parent | d6e727e30087e321911aa240fee03053cc22b1f4 (diff) |
Use OptionalDouble
Diffstat (limited to 'flags')
-rw-r--r-- | flags/src/main/java/com/yahoo/vespa/flags/custom/ClusterCapacity.java | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/flags/src/main/java/com/yahoo/vespa/flags/custom/ClusterCapacity.java b/flags/src/main/java/com/yahoo/vespa/flags/custom/ClusterCapacity.java index 8970d421681..9992d1f9a53 100644 --- a/flags/src/main/java/com/yahoo/vespa/flags/custom/ClusterCapacity.java +++ b/flags/src/main/java/com/yahoo/vespa/flags/custom/ClusterCapacity.java @@ -9,7 +9,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Objects; -import java.util.Optional; +import java.util.OptionalDouble; /** * @author freva @@ -22,7 +22,7 @@ public class ClusterCapacity { private final double vcpu; private final double memoryGb; private final double diskGb; - private final Optional<Double> bandwidthGbps; + private final OptionalDouble bandwidthGbps; @JsonCreator public ClusterCapacity(@JsonProperty("count") int count, @@ -34,19 +34,21 @@ public class ClusterCapacity { this.vcpu = requireNonNegative("vcpu", vcpu); this.memoryGb = requireNonNegative("memoryGb", memoryGb); this.diskGb = requireNonNegative("diskGb", diskGb); - this.bandwidthGbps = Optional.ofNullable(bandwidthGbps); + this.bandwidthGbps = bandwidthGbps == null ? OptionalDouble.empty() : OptionalDouble.of(bandwidthGbps); } /** Returns a new ClusterCapacity equal to {@code this}, but with the given count. */ public ClusterCapacity withCount(int count) { - return new ClusterCapacity(count, vcpu, memoryGb, diskGb, bandwidthGbps.orElse(null)); + return new ClusterCapacity(count, vcpu, memoryGb, diskGb, bandwidthGbpsOrNull()); } @JsonGetter("count") public int count() { return count; } @JsonGetter("vcpu") public double vcpu() { return vcpu; } @JsonGetter("memoryGb") public double memoryGb() { return memoryGb; } @JsonGetter("diskGb") public double diskGb() { return diskGb; } - @JsonGetter("bandwidthGbps") public Double bandwidthGbpsOrNull() { return bandwidthGbps.orElse(null); } + @JsonGetter("bandwidthGbps") public Double bandwidthGbpsOrNull() { + return bandwidthGbps.isPresent() ? bandwidthGbps.getAsDouble() : null; + } @JsonIgnore public double bandwidthGbps() { return bandwidthGbps.orElse(1.0); } @@ -71,9 +73,7 @@ public class ClusterCapacity { Double.compare(that.vcpu, vcpu) == 0 && Double.compare(that.memoryGb, memoryGb) == 0 && Double.compare(that.diskGb, diskGb) == 0 && - ((bandwidthGbps.isEmpty() && that.bandwidthGbps.isEmpty()) || - ((bandwidthGbps.isPresent() && that.bandwidthGbps.isPresent() && - Double.compare(that.bandwidthGbps.get(), bandwidthGbps.get()) == 0))); + bandwidthGbps.equals(that.bandwidthGbps); } @Override |